Quick revision
The short answer
I would route with consistent hashing on the user id at the layer 7 proxy, using a ring hash with many virtual points per pod or Maglev, so each user maps to one pod, load spreads evenly, and adding or removing a pod moves only about 1/40 of users. For hot users and bots, I would use consistent hashing with bounded loads, which passes keys from a pod above about 1.25 times the average load to the next pod, plus rate limits or separate routing for bots. Routing stays an optimisation: any pod can serve any user from the shared store.
What to remember
In this answer, we saw how to route users to the same pod for cache affinity with consistent hashing on the user id at the proxy, using many virtual points or Maglev for even spread and moving only about 1/N of users when pods change. Bounded loads handle hot users by spilling excess to the next pod, bots get rate limits or their own pool, and any pod can serve any user from the shared store, so routing changes only ever cost cache misses.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would route with consistent hashing on the user id at the layer 7 proxy, using a ring hash with many virtual points per pod or Maglev, so each user maps to one pod, load spreads evenly, and adding or removing a pod moves only about 1/40 of users. For hot users and bots, I would use consistent hashing with bounded loads, which passes keys from a pod above about 1.25 times the average load to the next pod, plus rate limits or separate routing for bots. Routing stays an optimisation: any pod can serve any user from the shared store.
Why this question is asked
Cache affinity is a classic way to multiply a local cache's hit ratio: if each user always reaches the same pod, that pod's cache holds the user's features after the first request. The difficulty is everything around the happy path: pods are added and removed, deploys restart them, and a few users or bots generate far more traffic than everyone else. Interviewers ask this design to see whether we know consistent hashing well enough to handle those cases. In this answer, we will cover the requirements, the high-level design, how consistent hashing spreads users and handles pod changes, how bounded loads deal with hot users, the fallback that keeps routing an optimisation, and the metrics that tell us it works.
1Requirements and Rough Numbers
We have 40 pods, each with a local cache of per-user model features. We want requests for the same user to reach the same pod to raise the hit ratio, without letting any pod be overloaded, and with graceful behaviour when pods scale or restart. A few users and bots generate thousands of requests per second each, while a typical user sends a few per minute.
If the fleet handles, say, 40,000 requests per second, each pod's fair share is about 1,000. A single bot at 3,000 requests per second would, under pure hashing, put its pod at four times the average on its own. That is the case the design must handle.
2The High-Level Design
Requests reach a layer 7 proxy fleet, such as Envoy, which extracts the user id from a header or token and hashes it to choose a pod. Each pod serves the request from its local cache, such as Caffeine, and on a miss loads the features from the shared feature store, for example Redis or a database, which every pod can read.
- Clients and botsrequests carry a user id
- Layer 7 proxy (Envoy)hash on user id, ring hash or Maglev, bounded loads, bot limits
- 40 recommendation podslocal feature cache per pod
- Shared feature storeRedis or a database, the source of truth for every pod
4 layers, from the top down. Step through them one at a time.
3Consistent Hashing and Pod Changes
With a plain hash modulo 40, adding a 41st pod changes the target of almost every user, and every cache goes cold together. Consistent hashing avoids that. In a ring hash, each pod is placed at many points on a circle of hash values, and a user goes to the first pod point clockwise from the user's hash. Adding a pod takes over only the arcs just before its points, about 1/41 of users; removing one hands its users to the neighbours. Maglev achieves the same with a lookup table built from each pod's preference order, which gives very even spread and fast lookups.
Even spread needs care. With one point per pod, the random positions make some arcs much longer than others, and some pods would get two or three times the average users. With 100 or more virtual points per pod, or Maglev's table, the spread evens out to within a few percent. In Envoy this is a ring_hash or maglev load balancing policy with a hash policy on the user id header.
| Routing | Users that move from 40 to 41 pods | Effect on caches |
|---|---|---|
hash(user) mod N | about 40 in 41, almost all | every cache cold at once |
| Ring hash, many points per pod | about 1 in 41 | only the new pod's users miss |
| Maglev table | about 1 in 41 | only the new pod's users miss |
4Hot Users and Bounded Loads
Pure hashing sends every request of a hot user to one pod, whatever that pod's load. Consistent hashing with bounded loads fixes this: each pod has a cap, such as 1.25 times the current average load, and when a key's pod is at the cap, the request goes to the next pod on the ring that is below it. Most users stay on their home pod, and the excess from a hot user spills over to a neighbour, which then also caches that user's features. The capacity factor trades hit ratio against balance: a lower cap balances better but moves more requests away from home.
Not every proxy supports bounded loads directly, so we should check ours. HAProxy has a hash-balance-factor option for this; for Envoy, check your version, and if it is missing we can approximate it at the application side, by having an overloaded pod redirect or proxy a share of a hot user's requests.
- Hash the user id onto the ringhome pod is pod 17
- Is pod 17 below 1.25 times the average load?YesSend to pod 17NoTry the next pod on the ring
- Is the next pod below the cap?YesSend there; it caches the user tooNoKeep walking the ring
3 steps in order. Play them, or step through them one at a time.
5Bots and the Fallback Rule
Bots deserve their own treatment rather than special cases in hashing. We identify them by API key, user agent or behaviour, apply rate limits at the proxy, and route heavy automated clients to a separate pool, so they cannot hurt real users' latency or skew the main pool.
Most importantly, routing must be an optimisation, not a guarantee. Any pod must be able to serve any user by loading features from the shared store. Then a pod failure, a rolling deploy, a spill-over under bounded loads, or a request that reaches the wrong pod only costs a cache miss and some latency, never an error. That is what makes the design safe to change.
6Measuring It
After each scale event and deploy, we watch the hit ratio per pod and overall, the per-pod request rate and CPU with its spread across pods, the load on the shared feature store, and latency. A good design shows the hit ratio dipping briefly after a change and recovering within minutes, and no pod rising far above the bound. Requests from bots and hot users should be visible as their own series, so a new heavy client is noticed early.
7Follow-up questions
What happens to the hit ratio during a rolling deploy, and how would you soften it?
Each restarted pod comes back with an empty cache, and its users miss until it warms, while the shared store sees extra load; with pods replaced one at a time, the overall hit ratio dips by roughly the restarted pod's share each time. To soften it, roll slowly with a pause between pods, warm the new pod from the shared store for its hash range before marking it ready, keep pod identities stable so the hash ring does not change during the deploy, and make sure the feature store has headroom for the extra misses.
Why hash on the user id rather than the client IP?
Many users share an IP behind NAT or mobile carriers, and one user's IP changes between networks, so IP hashing would both merge different users and split one user across pods. The user id is exactly the key the cache is organised by.
What if the proxy fleet has many instances; do they agree on the mapping?
Yes, as long as they all see the same list of pods: ring hash and Maglev are deterministic, so every proxy computes the same home pod. Bounded loads use each proxy's own view of load, so spill-over decisions can differ slightly between proxies, which is acceptable because routing is only an optimisation.
8Conclusion
In this answer, we saw how to route users to the same pod for cache affinity with consistent hashing on the user id at the proxy, using many virtual points or Maglev for even spread and moving only about 1/N of users when pods change. Bounded loads handle hot users by spilling excess to the next pod, bots get rate limits or their own pool, and any pod can serve any user from the shared store, so routing changes only ever cost cache misses.
Open with
I would hash on the user id at the layer 7 proxy using consistent hashing, a ring hash with many virtual points per pod or Maglev, so each user maps to one home pod, the spread across 40 pods is even, and adding or removing a pod moves only about one fortieth of users instead of reshuffling everyone like modulo hashing would.
Then, if they want more
The problem is hot users and bots, because pure hashing sends all of a bot's thousands of requests per second to one pod.
So I would use consistent hashing with bounded loads: each pod has a cap, around 1.25 times the average load, and when the home pod is above it, the request goes to the next pod on the ring, which then caches that user too.
I would check whether our proxy supports it, HAProxy has a hash balance factor, or approximate it. Bots I would rate-limit at the proxy or route to their own pool.
And I would treat routing as an optimisation, not a guarantee: any pod can serve any user by loading features from the shared store, so failures, deploys and spill-over only cost cache misses. After each scale event I would watch hit ratio, per-pod load and feature-store load.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Design the routing, and explain how it handles pod changes and hot users.": https://scrivio-interview-library.netlify.app/architecture/load-balancing-networking/a66a8db698/