Senior LevelSoftware Engineering Principles
How do you rebalance database shards using Consistent Hashing without taking system downtime?
❓ Interview Prompt: Explain Shard Rebalancing, online resharding strategies, dual-writing during migration, Virtual Nodes, and live data backfilling.
When a database cluster running on $N$ shards reaches storage or CPU capacity, new shards must be added and keys rebalanced without taking production downtime:
Online Resharding Workflow:
1
Add New Shard Nodes: Register new physical shard nodes on the Consistent Hash Ring using Virtual Nodes.
2
Dual-Write Phase: Update routing proxy to dual-write new keys to both old and new target shards.
3
Background Backfill: Migrate historical keys belonging to new shard ranges in small, rate-limited batches.
4
Cutover & Cleanup: Verify key parity, switch read traffic to new shards, and drop old data ranges.
Code Implementation Example
json
{
"reshardingTask": "Add Shard 5 & 6 to Cluster",
"status": "Background Backfill",
"migratedKeysCount": 4500000,
"remainingKeysCount": 500000,
"dualWriteEnabled": true
}💡Online database shard rebalancing progress tracking payload.
🎯 Interview Key Takeaway
Execute live database shard rebalancing using dual-writing and background backfilling to scale storage without downtime.
#Sharding#Resharding#Database Scaling#Senior
Back to all Software Engineering Principles Questions→