← All posts
Lessons from Sharding PostgreSQL
Sharding bought us headroom and a pile of new problems. Pick your shard key like your job depends on it — because it does.
We sharded when a single primary couldn't keep up with writes. It worked. It was also the hardest thing we did all year.
The shard key is everything
Choose a key that distributes evenly and keeps related rows together. We picked tenant_id — most queries are tenant-scoped, so they stay on one shard.
What got harder
- Cross-shard joins — avoid them; denormalize or fan out and merge.
- Unique constraints — only enforceable within a shard.
- Migrations — now N times the work and N times the blast radius.
Sharding is not an optimization. It's a new distributed system with your old data in it.
More to read