Problem Statement
Describe the responsibilities of a shard routing layer and how you would deploy it safely.
Explanation
A router computes the shard from the partition key, manages shard maps, and provides health-aware failover. It shields clients from topology changes and exposes metrics on hit rates, latency, and errors.
Deploy it stateless behind a load balancer with config in a durable store. Roll out changes with feature flags and canaries. Keep a fast local cache of the shard map and a background refresher to avoid cold lookups.
Code Solution
SolutionRead Only
route(key){ sid=hash(key)%N; return pool[sid].pickHealthyReplica(); }