Pattern · seen in 2 breakdowns across 2 companies

Shard-Key Colocation

Definition

When sharding, place every row that must be read or committed together on the same shard, by two coordinated choices: shard the full set of tables that reference each other (not just the big one), and partition them all by the same key — the entity whose boundary matches the application's transaction and query patterns. Transactionality guarantees stop at a single host; colocation is how a sharded system keeps the transactions it actually needs without distributed coordination.

The failure case the pattern prevents is quiet corruption at the seams: a parent row on one shard, its children on another, and a delete that succeeds on one side while the update on the other fails. The design work is choosing the colocation entity — the workspace, the guild, the user — such that real queries stay inside it and load spreads acceptably across instances of it.

When it applies

01Horizontally sharding a relational schema where foreign-key-related tables participate in shared transactions
02Choosing a partition key for a multi-tenant product, where the tenant boundary usually is the transaction boundary
03Any sharded system where cross-shard joins or two-phase commits would otherwise become the common path

Tradeoffs

The shards inherit the colocation entity's skew: uniform buckets by count are not uniform by weight when one tenant outweighs thousands
The partition key becomes architectural commitment — a product pivot away from the chosen entity turns colocation into impedance
Everything transitively related must shard together, dragging small tables into the scheme to protect the transactions of large ones

The same move, 2 ways

Every row is a production system that bet on this pattern — the note says how, in that system's own terms.

Figma
Figma Blog
2024
Figma's 'colos' are exactly this pattern: related tables grouped so they share one shard key and one physical layout. Inside a colo, cross-table joins and full transactions work, as long as they stay within a single value of the shard key. Most application code already queried that way, which is what made the abstraction cheap for product developers: the payoff is that the queries you were already running stay free. Read the breakdown →
Notion
Notion Blog
2021
Both halves of the pattern sit in one post. Shard every table reachable from block so that rows which must change together live on the same host (a single database is as far as a commit-together guarantee reaches), and partition all of it by workspace ID so that a given user's queries land on one shard. The example the post gives is the failure case stated plainly: a block deleted on one host while its comments, stranded on another, never get the update. Read the breakdown →

Often used together

Patterns sharing breakdowns with this one — derived from co-occurrence, threshold ≥2 shared.

Problems this pattern answers

The walls where its breakdowns live — each opens the cross-company comparison.