Our single database can no longer hold the write volume, so we're going to shard it. How do you pick a shard key, and what goes wrong if you pick a bad one?

system-design · Mid level · software-engineering

What the interviewer is really asking

Assesses whether the candidate can reason about shard-key selection against load distribution and the dominant access pattern, the hotspot/skew failure modes of a bad key, and why resharding is expensive — core sharding judgment, not just 'split the data.'

What to say

What to avoid

Example answers

Strong: I'd pick the shard key from the main access pattern and aim for even spread. For a multi-tenant app that's usually tenant_id — high cardinality, keeps one tenant's data co-located so common queries hit one shard, and spreads load. I'd avoid monotonic keys like a timestamp or auto-increment id, because they funnel every new write onto the newest shard — an instant hotspot. For mapping I'd use consistent hashing so adding a shard only moves a fraction of keys, not almost all of them. And I'd go in knowing cross-shard joins and transactions get hard, so I treat the key choice as nearly irreversible and decide it carefully.

Weak: I'd shard by user id using a hash so the data spreads out across the shards evenly. Then each shard handles its share of the load.

Want questions matched to your role? Paste a job title, job description, or CV and get a personalized set, or go Pro to unlock the full bank.