Etsy、1000シャード・425TBのMySQLシャーディングアーキテクチャをVitessに移行
Etsyのエンジニアリングチームは、1000シャード、425TB規模のMySQLシャーディングインフラを、データのリシャーディングや未シャード化テーブルのシャーディングを可能にするVitessへ移行したと報告した。
キーポイント
大規模インフラ移行の実施
Etsyは長年運用してきた大規模なMySQLシャーディングインフラ(1000シャード、425TB)を、オープンソースのデータベースクラスタリングシステムであるVitessへ移行した。
移行手法と技術的アプローチ
シャードルーティングを社内システムからVitessのvindexesを使用して移行し、これにより既存のデータ構造を維持しながら新たな機能を導入した。
移行による新機能の獲得
この移行により、データのリシャーディング(シャードの再配置)や、これまでシャーディングされていなかったテーブルのシャーディングが可能になった。
影響分析・編集コメントを表示
影響分析
この事例は、大規模ECプラットフォームにおけるデータベースインフラの近代化の実践例として、同様の課題を抱える企業にとって貴重な参考情報となる。特に、既存の大規模シャーディング環境を維持しながら新たな柔軟性を獲得する移行手法は、技術的負債の解消とシステム進化を両立させるモデルケースとして注目される。
編集コメント
大規模実稼働システムのデータベースインフラ刷新事例として、技術的負債との向き合い方と近代化への道筋を示す実践的な内容。特にシャーディング戦略の進化に関する知見は、スケールアウトを迫られる多くのサービスにとって参考になる。
Etsy のエンジニアリングチームは最近、同社が長年運用してきた MySQL シャーディングインフラを Vitess へ移行した方法を説明しました。この移行により、シャーディングルーティングは Etsy の内部システムから vindexes を使用して Vitess へと移され、データの再シャーディングや、それまで非シャーディングだったテーブルのシャーディングといった機能が実現可能になりました。
MySQL の水平スケーリングを目的としたオープンソースデータベースクラスタリングシステムである Vitess は、当初 ORM(オブジェクトリレーショナルマッピング)とデータベースの間にレイヤーとして導入され、クエリをそこ経由でルーティングする仕組みでした。同時に、ORM 側がターゲットとなるシャーディングを指定し続けるという状態も維持されていました。
Vitess において vindexes は、アプリケーションデータがデータベースのどのシャードにマッピングされるか、またクエリがどのようにそれら across ルートされるかを定義します。Etsy のシニアソフトウェアエンジニアである Ella Yarmo-Gray は、Etsy が直面した課題について次のように説明しています。
「この新しいインフラストラクチャを整えたことで、Vitess 内でシャーディング戦略を定義する vindexes の探索を開始する準備が整いました(...)。ORM のシャードマッピングはランダムでありアルゴリズム的ではないため、これらの標準的な vindexes のいずれかを使用するには、すべてのデータを再シャーディングする必要があり、これは手作業によるプロセスとなり、おそらく数年かかるでしょう。そこで私たちは、既存のシャーディングロジックを Vitess へ移植するカスタム vindexes を作成することを選びました。これにより、データの移動に伴う複雑さやリスクを回避しつつ、当社の環境で vindexes がどのように動作するかを検証することが可能になりました。」
Etsy は 2010 年頃より、生産データの大部分を保存するためにシャード化された MySQL アーキテクチャを採用しており、独自の実装によるシャーディングロジック、約 1,000 のシャード、425 TB に及ぶデータを保有し、毎秒 170 万リクエストを処理しています。
Etsy のエンジニアは、内部のオブジェクト・リレーショナル・マッピング(ORM)レイヤーを通じて MySQL にアクセスしており、各データベーステーブルには対応するモデルが存在します。シャード化されたテーブルにおいては、レコードがどのシャードに保存されるかを決定するために、モデル内に「シャーディファイア ID」と呼ばれる一意な ID フィールドが定義されています。多くのモデルでは shop_id や user_id がシャーディングキーとして使用されますが、全体としては 30 種類以上の異なる ID が利用されており、レコードとシャードのマッピング情報は、単一の(非シャード化された)「インデックス」データベースに格納されていました。このアプローチはスケーラビリティの向上と障害時の影響範囲をトラフィックの一部に限定する点で有効でしたが、スケーリング操作は低速かつ手動であり、インデックスデータベースが単一障害点(SPOF)となる一方で、開発者はシャーディング管理を自前で行う必要がありました。
数年前、同社はこれらの課題に対処しつつ MySQL 互換性を維持し、「インデックス」データベースの廃止、および開発者に対するシャードの複雑さの隠蔽を目的として Vitess への移行を決断しました。この移行には、より効果的なシャーディングをサポートするためのデータモデルの一部再設計、シャーディングキーの選定、そしてデータ整合性を検証しながら生産環境へのトラフィックを段階的に切り替える作業が含まれていました。Yarmo-Gray は以下のように結論付けています:
5 年、約 2,500 のプルリクエスト、そして 6,000 のクエリを経て、Etsy のシャード管理を Vitess vindexes(仮想インデックス)へ移行することに成功しました。移行プロセスの合理化に多大な労力を費やしましたが、Etsy のような規模と歴史を持つコードベースに対するデータベース基盤の置き換えは依然として大きな課題でした。
ここ数年、Etsy のエンジニアリングチームは「Vitess を用いた支払いのシャード化」と題する一連の記事を公開しており、その中で支払いプラットフォームの移行努力を記録し、データモデルの移行における課題や、重要な高トラフィックシステムのカットオーバー(切り替え)作業の詳細、そしてカットオーバーリスクの評価について記述しています。
著者について
Renato Losio
Renato はクラウドアーキテクト、技術リーダー、およびクラウドサービススペシャリストとして豊富な経験を持っています。現在、彼はベルリンに住み、リモートでシニアクラウドアーキテクトとして勤務しています。彼の主な関心領域はクラウドサービスとリレーショナルデータベースです。彼は InfoQ の編集者であり、認定された AWS Data Hero です。LinkedIn で彼に連絡することができます。
もっと見る 表示しない
原文を表示
The Etsy engineering team recently described how the company migrated its long-running MySQL sharding infrastructure to Vitess. The transition moved shard routing from Etsy’s internal systems to Vitess using vindexes, enabling capabilities such as resharding data and sharding previously unsharded tables.
An open source database clustering system for horizontally scaling MySQL, Vitess was initially introduced as a layer between the ORM (Object-Relational Mapping) and the database, routing queries through it. At the same time, the ORM continued to specify the target shard.
In Vitess, vindexes define how application data maps to database shards and how queries are routed across them. Ella Yarmo-Gray, senior software engineer at Etsy, explains the challenge Etsy faced:
With this new infrastructure in place, we were ready to start exploring vindexes, which define sharding strategies within Vitess (...) Since the ORM’s shard mappings are random and not algorithmic, using one of these out-of-the-box would require re-sharding all of our data – a process that would be manual and likely take years. Instead, we chose to write custom vindexes that ported our existing shard logic into Vitess so we could test how vindexes worked in our environment without the complexity and risk of moving data.
Etsy has used a sharded MySQL architecture since around 2010 to store most of its production data, with proprietary sharding logic, approximately 1000 shards, and 425 TB of data, serving 1.7 million requests per second.
Etsy engineers access MySQL through an internal object-relational mapping (ORM) layer, in which each database table has a corresponding model. For sharded tables, a unique ID field, called the shardifier ID, was defined in the model to determine which shard stores each record: while most models use shop_id or user_id as a sharding key, overall more than 30 different IDs were used, with record-to-shard mappings stored in a single (unsharded) "index" database. While the approach improved scalability and limited the impact of outages to a small portion of traffic, scaling operations were slow and manual, with the index database being a single point of failure and developers having to manage sharding themselves.
A few years ago, the company decided to migrate to Vitess to address those challenges while maintaining MySQL compatibility, removing the "index" database, and hiding shard complexity from developers. The migration involved redesigning parts of the data model to support better sharding, selecting a shard key, and gradually moving production traffic to the new environment while verifying data consistency. Yarmo-Gray concludes:
Five years, approximately 2,500 pull requests and 6,000 queries later, we have successfully migrated Etsy’s shard management to Vitess vindexes! Despite the work we put in to streamline the migration process, it was still a challenge to replace the database infrastructure for a codebase of Etsy’s scale and age.
In the last few years, the Etsy engineering team has published a series of articles titled "Sharding Payments with Vitess," documenting their migration effort for the payments platform, describing the challenges of migrating their data models, covering the cut-over effort of a crucial high-traffic system, and evaluating cutover risks.
About the Author
Renato Losio
Renato has extensive experience as a cloud architect, tech lead, and cloud services specialist. Currently, he lives in Berlin and works remotely as a principal cloud architect. His primary areas of interest include cloud services and relational databases. He is an editor at InfoQ and a recognized AWS Data Hero. You can connect with him on LinkedIn.
Show moreShow less
関連記事
Airbnbが大量メトリクスパイプラインをOpenTelemetryに移行
Airbnbの監視エンジニアリングチームが、StatsDと独自のVeneurベースの集計パイプラインから、OpenTelemetry CollectorとVictoriaMetricsのvmagentを基盤とするオープンソースメトリクススタックへの大規模移行を実施し、毎秒1億サンプル以上の処理を実現した。
Google CloudがPostgreSQLコア機能への継続的な取り組みを強調
Google Cloudは、PostgreSQLへの技術的貢献として、論理レプリケーション、アップグレードプロセス、システム安定性の向上を発表した。これはスケーラビリティや運用課題の解決を目指すコアエンジンの強化に焦点を当てている。
Kubernetes上でSlurmを使用した大規模GPUワークロードの実行
NVIDIAが、オープンソースのクラスタ管理システムSlurmをKubernetesと統合し、大規模GPUワークロードを効率的に管理・スケジューリングする方法を紹介している。SlurmはTOP500システムの65%以上で採用されている実績を持つ。