Database Sharding: When and How

Sharding is operationally expensive. Pick when forced; never for premature optimization.

When to shard

Sharding is the largest reversibility tax in database operations. Reach for it last, not first; the simpler scaling levers usually have more headroom than teams assume.

Four sharding patterns

Migration cost

Sharding migrations measure in quarters, not weeks. Plan for the long path and stage the work so production stays usable throughout.

Application changes

Sharding moves complexity from the database into the application. Plan for the shape of that complexity before you commit.

Antipatterns

What to do this week

Three moves. (1) Apply this pattern to your most-loaded table. (2) Measure query latency / write throughput before/after. (3) Document the win and the constraint so the next refactor inherits the knowledge.