Preparing your design workspace

Loading the problem and your latest saved attempt…

Design Capacity-Weighted Cache Routing

Design a distributed cache-routing layer that assigns keys according to heterogeneous node capacity, minimizes movement during topology changes, and safely manages leader/follower replicas.

Problem statement

For this exercise, assume application clients use a distributed in-memory cache through a routing layer. Clients issue GET, PUT with a TTL and stable request ID, and DELETE for opaque keys.

Cache misses are valid because an external system remains authoritative; the cache service owns only routing, cached-entry lifecycle, replication, and availability.

The fleet spans three availability zones and contains one-unit standard nodes and four-unit large nodes. Key ownership should be proportional to advertised healthy capacity rather than equal per node. Adding, removing, reweighting, or draining a node should move only the affected share of keys.

Each key has one leader and two followers in different zones. A write is acknowledged after the leader and at least one follower accept the same version in the current topology epoch. There must never be two writable leaders for one key and epoch.

Design client routing, weighted placement, topology distribution, reads and writes, leader/follower replication, failover, rebalancing, overload protection, and observability. Discuss skew and hot keys.

Exclude the authoritative backing database, cache-value computation, detailed eviction-policy implementation, and cross-region active-active replication.

What to build

  1. Clients can get, put with a TTL and stable request ID, and delete opaque keys through a deterministic routing contract; misses and expired or evicted values are explicit outcomes.
  2. Healthy key ownership is distributed approximately in proportion to each node's configured capacity, and topology or weight changes use versioned placement with bounded key movement and controlled draining.
  3. Every key has one writable leader and two cross-zone followers; acknowledged writes follow the stated replica rule, and the system safely replaces a failed or fenced leader.
  4. Operators can observe ownership skew, hot keys, replica health, topology rollout, movement, latency, and saturation, and can apply backpressure or mitigation without silently weakening correctness.

At scale

  • Assume 50 million active keys, values up to 64 KiB, two million GET requests per second, and 100,000 PUT or DELETE requests per second at peak.
  • Target a p95 routing-decision latency below 2 ms inside a healthy gateway and a p95 cache GET latency below 20 ms.
  • Across a representative key sample, assigned primary load should stay within 10% of each healthy node's advertised capacity share; a membership change should move only the newly gained, lost, or reweighted share.
  • Topology metadata should converge to healthy gateways and nodes within 10 seconds, and one node or one availability-zone failure must not lose an unexpired acknowledged entry unless normal capacity eviction occurs.