The interview problem
A service caches expensive parsed documents in worker memory. Route repeated document requests to the same worker while adding capacity and handling a hot document.
Original practice, not a reported company interview. All scenarios and worked numbers are illustrative. Interview date: not applicable. Sources retrieved September 30, 2026.
1. Scope and assumptions
Assume cache loss is harmless and durable documents live elsewhere. Hash affinity is a performance policy, not ownership or authorization. Distinct from implementing a distributed cache's storage protocol.
2. Worked approach
tenant/document key + membership version → affinity worker → coalesced origin fill → cache
Hash the tenant/document key against a versioned worker set using a consistent-hash scheme. Gateways receive membership snapshots and health updates. Virtual nodes or a suitable alternative distribute keys; verify distribution empirically rather than assuming equal key count means equal load.
On removal, reroute affected keys and warm them lazily with per-key request coalescing. Bound simultaneous cold fills. For a hot key, allow a small replica set and select within it using queue load; retain a canonical durable source. Do not persist mutations only at the affinity worker. Include tenant identity in cache keys and recheck access before returning cached content.
3. Calculate the example
Under an ideal balanced equal-weight scheme, expanding from 10 to 11 workers remaps about 1/11 = 9.09% of keys. With 11 million equally popular keys, approximately one million move. That estimate says nothing about byte volume: if one moved document generates 30% of traffic, the cold-start impact can be much larger. A worker capable of 1,000 requests/s cannot serve a single 3,000 requests/s key merely because average fleet load is low.
4. Failure cases and trade-offs
Gateways with different membership views temporarily disagree about affinity. Correctness survives because caches are disposable, but duplicate fills can overwhelm storage. An unstable health probe may repeatedly remap keys; use drain states and bounded convergence.
Strict affinity minimizes duplication but concentrates hot-key load. Replicating hot entries spends memory to lower tail latency. Random routing is simpler when cached objects are cheap or every request is unique.
5. Validate the result
Simulate additions, removals, skewed popularity and stale gateway views. Measure remapped bytes, origin fetches and queue age. Test that membership churn cannot bypass tenant isolation.
6. Interview follow-ups and self-review
How would unequal worker memory change weights? Can an in-flight request finish on a draining worker?
Reward separation of affinity from correctness, explicit churn behavior, a hot-key solution and a qualified remapping estimate.
Sources and related practice
Technical reference: www.envoyproxy.io — Official load-balancer choices including consistent hashing; workload calculations are illustrative.
Exact publication/update date not established in this review. Retrieved September 30, 2026. This reference supports the named technical concept; the proposed workflow and examples are original, not a documented vendor implementation or interview report.
Continue with Design a distributed cache; Route around failing service dependencies.
Continue your preparation
Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.