Interview Prep Zoneby CuriouserLabs

Question 5 of 5 · architect level

How does a request find the right shard, and how do you rebalance without downtime?

🎤 Say this first

Routing has three standard shapes: a routing tier / proxy that knows the map (Vitess, mongos, Envoy); a cluster-aware client that fetches the map and connects directly (Cassandra, Redis Cluster, Kafka); or any-node forwarding, where a node receiving a misrouted request proxies it. All three depend on a shared, versioned partition map, usually kept in a consensus store (etcd/ZooKeeper) — the map itself is exactly the small critical state consensus is for. For rebalancing, the rule that matters is: never rebalance by re-hashing on cluster size. Use a fixed large number of partitions moved wholesale between nodes, or consistent hashing with vnodes, or explicit range splits. Move data by copying while both copies serve, then cutting over atomically, throttled so the migration doesn't starve production traffic — and keep the switch reversible.

The full picture

Routing modelHow the client finds dataTrade-off
Proxy tierclient → proxy → shardone extra hop; easy central control (Vitess, mongos)
Cluster-aware clientclient caches the map, connects directlyfastest; map staleness must be handled
Any-node forwardingany node proxies to the ownersimplest client; internal traffic amplification
Redirect (MOVED/ASK)node replies 'go there instead'self-healing client caches — Redis Cluster's model
  • Stale maps are the normal case, so design for them: clients will hold an old map during a move. Systems handle this with redirects (Redis MOVED/ASK), with retries on a versioned map epoch, or with the source node forwarding during migration. 'How does a client with a stale map behave?' is the question that separates a design from a sketch.
  • Fixed partitions are the operationally boring choice, which is the point: pick 1024 partitions on day one for a 4-node cluster, and each node owns 256. Grow to 16 nodes and each owns 64 — partitions never split, they only move. The constraint is that the partition count caps your maximum node count and is painful to change (Kafka partitions, Elasticsearch shards).
  • Automatic rebalancing plus an automatic failure detector is a dangerous combination: a node is slow, the detector marks it dead, rebalancing kicks off, the resulting data movement makes the cluster slower, more nodes look dead — a cascade. Many mature systems deliberately keep rebalancing manual or approval-gated for exactly this reason, and knowing why is a strong architect-level point.
  • The safe migration sequence is the same everywhere: dual-write (or replicate) to the new owner → backfill historical data → verify by comparison → shift reads gradually → cut over writes → keep the old copy readable until you're confident → delete. Every step is reversible except the last, and the verification step is the one teams skip and regret.
  • Throttle and observe: rebalancing competes with production for disk, network and page cache. Rate-limit the transfer, run it off-peak, and watch p99 latency rather than just transfer progress. A rebalance that finishes in one hour and breaks your SLO is worse than one that takes a day.

🔄 Likely follow-up questions

  • What does a Redis Cluster client do when it gets a MOVED response mid-migration?
  • Why do mature systems often make rebalancing manual rather than automatic?
  • How do you verify a shard migration copied everything before cutting over?