Fintech Lab
Lesson 83Engineering deeperAdvanced
Sharding strategies for ledger tables
100 million users, one Postgres won't hold them. Pick a shard key.

Your ledger grows past what a single Postgres can handle. Time to shard. The shard key choice determines what queries become CHEAP and what becomes EXPENSIVE. Shard by user_id: per-user queries (wallet balance, statement) are co-located in one shard, but cross-user queries (total revenue, top customers) fan out across all shards. Shard by date: time-window queries are local but per-user history fans out. Shard by account: per-account aggregates local but transactions touching multiple accounts hit multiple shards. The right answer depends on your QUERY PATTERN; lesson 41 (partitioning) is the time-shard adjacent. This lesson posts a user-sharded entry and discusses the trade-offs.

Fintech Lab is a free, interactive lab for fintech engineers. Real ledger, your own sandbox, engineering patterns from production. See all 85 lessons.

Search lessons

Type to find any of the 85 lessons. Press Enter to open.