Question presented to candidate:
"Our main Postgres database is running out of room and write capacity, even with read replicas. Someone suggested sharding. What is sharding, how would you choose how to split the data, and what gets harder once you do it?"
What a strong answer should cover:
Sharding is horizontal partitioning across machines: each shard holds a subset of rows and is the only writer for them, so it scales writes and storage, which read replicas do not
The shard key decides everything: high cardinality, even spread, and aligned with the main query so most requests touch one shard
The strategies and their failure modes: range (good scans, hot tail on monotonic keys), hash (even spread, scatter-gather for ranges), directory / lookup (flexible, but the map is a dependency)
What gets harder: cross-shard queries, joins and transactions, global unique constraints and IDs, hot keys that no key choice fixes
Resharding: hash % N moves most rows when N changes; fixed logical shards (or consistent hashing) move only the data that must move
When not to shard yet: vertical scaling, replicas, caching and archiving come first
Clarifying questions expected:
What is the dominant access pattern: by user, by tenant, by time?
Is the pressure on storage, write throughput, or both, and how fast is it growing?
Which queries must stay transactional across entities?
Code / implementation expected: Optional โ the choice of shard key with its trade-offs matters most; the example measures range vs hash on one workload and the cost of resharding.
sharding
partitioning
2
Try it yourself
Sketch your approach before you read the solution. That is what the interview tests.
Stuck? Get a hint.
A short nudge toward the approach. It will not give the answer away.
3
Solution
Target Audience: Beginners to system design who know what a database table is; no distributed-systems background assumed.
Difficulty: Medium
Verified with: Node 22.22 and Python 3.12 (both print identical output). Notion figures are cited from the Notion engineering blog; DynamoDB limits from the AWS DynamoDB developer guide.
How to read this doc: Every idea is explained in plain language first, then tagged with ๐ Interview term: so you also learn the words an interviewer expects. Numbers come from running the example; the Verified section quotes its full output.
1. Why This Even Matters โ A Story First
A town library keeps every member card in one filing cabinet. The town grows; the cabinet fills, and the queue at the single clerk gets long. Buying a bigger cabinet works for a while (vertical scaling), and hiring helpers who only read cards from phot
The solution is hidden so you can try first
15 min read ยท 14 sections
4
Read the code
Range vs hash sharding on one workload: hot shard, celebrity key, scatter-gather, resharding cost, capacity