Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

GitHub Engineering 9 min read Case study mediumAdept

Partitioning GitHub’s relational databases to handle scale

GitHub split its monolithic `mysql1` MySQL cluster by first virtually partitioning tables into schema domains (declared in YAML) and enforcing boundaries with query and transaction linters, then physically moving domains to new clusters via Vitess vertical sharding or a custom ProxySQL/GTID-based write-cutover script. Cross-domain joins were eliminated with techniques like preload, Rails' new `disable_joins` option and application-side joins, validated with Scientist experiments. The write-cutover moved 130 of the busiest tables in tens of milliseconds with only a handful of failed writes. Query volume grew from 950k to 1.2M queries/s while average per-host load halved, reducing database-related incidents.

Related posts

  • Horizontally scaling the Rails backend of Shop app with Vitess

    Shopify Engineering mediumAdept

    Shop app outgrew a single MySQL database despite federating tables across databases, so the team moved its Rails backend to Vitess, sharding user-owned tables by user_id into a "users" keyspace and keeping the rest in an unsharded "global" keyspace. The key enabler was a set of application-layer query verifiers that flagged missing sharding keys, cross-database and cross-shard transactions, cross-shard writes and cross-keyspace joins. They were rolled out first in dev/CI, then in log-only mode in production. Getting there also meant backfilling user_id onto billion-row tables, rewriting shard-key updates as insert-then-delete, and patching ActiveRecord associations so the sharding key reaches every query. Two takeaways: fix the data model early, and avoid cross-shard transactions because Vitess does not roll back partial commits by default.

  • Breaking up a monolith: How we’re unwinding a shared database at scale

    Datadog Engineering mediumAdept

    Datadog is splitting its large shared Postgres database into independently owned instances through a three-phase plan: logical separation into per-domain private schemas with explicit ACLs, access reduction so only owning teams query their tables directly, and physical separation onto managed OrgStore instances. Domain boundaries came from clustering Database Monitoring query samples and validating them with 30+ teams. Inter-domain foreign keys were replaced with CDC or Postgres replication. A homegrown PG Proxy lets teams migrate at their own pace and makes cutover a dynamic config change, with write downtime under five seconds and reverse replication kept for rollback. The platform investments that made this feasible, the Rapid service framework, OrgStore and PG Proxy, are presented as prerequisites, and each phase has concrete progress metrics.

  • Upgrading GitHub.com to MySQL 8.0

    GitHub Engineering mediumAdept

    GitHub upgraded 1200+ MySQL hosts (300+ TB, 5.5M QPS, 50+ clusters, including Vitess) from 5.7 to 8.0 over more than a year without breaking SLOs. The rollout went in stages: rolling replica upgrades per data center, then a replication topology with parallel 5.7 and 8.0 chains, then an Orchestrator graceful failover to an 8.0 primary, and finally cleanup after a 24-hour validation. Keeping rollback possible required backward replication from 8.0 to 5.7, which meant pinning utf8/utf8_unicode_ci collation and working around 8.0 role statements. Other problems included a commit-order replication hang fixed in 8.0.28, Vitess VTgate version advertising, and large WHERE IN queries that crashed MySQL in production despite passing CI.

  • Migrating Etsy’s database sharding to Vitess

    Etsy Code as Craft mediumAdept

    Etsy moved shard routing for its ~1,000-table, ~1,000-shard, 425 TB MySQL cluster (1.7M requests/sec) from an ORM that looked up random shard mappings in a single index database to Vitess vindexes, without moving any data. The ORM's shard assignment was switched to match Vitess's hash vindex, and legacy mappings were frozen into a read-only SQLite file copied onto each Vitess server. A custom hybrid vindex picks SQLite lookup or hash based on an id threshold. Tables were ramped incrementally through the experimentation framework with instant rollback, though 27 transaction-coupled models carrying a third of traffic had to move together to preserve per-connection atomicity. The five-year effort removed a single point of failure, cut re-sharding from months to days, and enabled opt-in scatter queries; one query dropped from ~2 s to ~20 ms, and bulk primary-key lookups needed far fewer queries.

  • The growing pains of database architecture

    Figma mediumAdept

    Facing ~3x annual database traffic growth and 65% peak CPU on a single Amazon RDS Postgres instance, Figma chose vertical partitioning (moving groups of tables to their own databases) over horizontal sharding, NewSQL, or self-hosting. Candidate tables were picked by measuring average active sessions from pg_stat_activity sampling and by tracing ActiveRecord queries into Snowflake to find isolated table groups. Migration used logical replication, with destination indexes dropped and rebuilt to cut initial copy from weeks to hours. Cutover went through a two-phase PgBouncer split, a brief pause with query cancellation, LSN-based sync checks, and reverse replication for rollback, keeping availability impact under a minute.

The quest for software engineering knowledge.

Look:
Layout: