Quick revision
The short answer
I decide from the access distribution. Usually a small fraction of keys gets most reads, so a much smaller local cache keeps most of the hit ratio, which I check by replaying access logs against simulated cache sizes. The long tail goes into a shared cache such as Redis, stored once and with a hit ratio independent of pod count, while the local layer keeps what is read on almost every request and changes rarely, bounded by weight with short TTLs and invalidation. Smaller local caches also warm faster, and the decision is expressed in cost per pod times pods against shared-cache cost and the latency budget.
What to remember
In this answer, we saw that 200 pods with 2 GB local caches spend 400 GB of RAM on mostly duplicated data and take minutes to warm. We measure the access distribution by replaying logs against simulated cache sizes, which usually shows that a much smaller local cache keeps most of the hit ratio. The long tail moves to a shared Redis layer stored once and independent of pod count, the local layer keeps config, reference data and the hottest products bounded by weight with short TTLs and invalidation, readiness waits only for the critical set, and the decision is stated as RAM per pod times pods against shared-cache cost and latency budget.
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 decide from the access distribution. Usually a small fraction of keys gets most reads, so a much smaller local cache keeps most of the hit ratio, which I check by replaying access logs against simulated cache sizes. The long tail goes into a shared cache such as Redis, stored once and with a hit ratio independent of pod count, while the local layer keeps what is read on almost every request and changes rarely, bounded by weight with short TTLs and invalidation. Smaller local caches also warm faster, and the decision is expressed in cost per pod times pods against shared-cache cost and the latency budget.
Why this question is asked
Local caches feel free because they are just heap memory, but at 200 pods every gigabyte per pod becomes 200 gigabytes of RAM holding the same data. Interviewers ask this because it combines measurement, architecture and cost: the right answer is not a rule of thumb but a method. In this answer, we will look at what the current setup costs, measure how reads are distributed, decide what moves to the shared layer and what stays local, deal with warm-up, and express the decision in cost terms.
1What the Current Setup Costs
Each of the 200 pods holds a 2 GB local cache, 400 GB of RAM in total. Because any pod can serve any request, every pod caches roughly the same popular data, so most of those 400 GB are copies of the same few gigabytes. The second cost is time: after a deploy each pod starts with an empty cache, and filling 2 GB takes 4 minutes, during which the pod either misses heavily or is not ready, which slows every rollout and every scale-out.
So two questions decide the design: how much of the hit ratio would we lose with a smaller local cache, and what would serve the reads the local cache no longer holds?
2Measuring the Access Distribution
Catalogue reads are almost always skewed: a small fraction of products receives most of the traffic. If the top 1 percent of keys receives 60 percent of reads and the top 10 percent receives 90 percent, a local cache sized for the top few percent captures most of the hits that 2 GB captures today.
We do not have to guess. Take a day of access logs, the sequence of keys requested by one pod, and replay it through a simulated cache at several sizes, using the same eviction policy as production (Caffeine's W-TinyLFU; the Caffeine project includes a simulator, or a short program that feeds the keys into a real Caffeine instance works too). The output is a curve of hit ratio against cache size, and it usually shows a sharp knee.
| Local cache size | Simulated hit ratio | RAM over 200 pods |
|---|---|---|
| 2 GB (today) | 97 percent | 400 GB |
| 512 MB | 94 percent | 100 GB |
| 256 MB | 92 percent | 50 GB |
| 64 MB | 84 percent | 12.5 GB |
3Putting the Long Tail in a Shared Cache
The reads a smaller local cache no longer holds, the long tail, go to a shared cache such as Redis. There, each value is stored once, or once per replica, for all 200 pods: a 30 GB working set with one replica is 60 GB instead of hundreds. Its hit ratio does not depend on the number of pods, because a key loaded by any pod is a hit for all others, so autoscaling no longer degrades caching.
The price is latency: a Redis read in the same zone takes around a millisecond, against well under a microsecond locally. For the 5 to 8 percent of reads that fall through the local level, an extra millisecond is usually invisible in the response time, and the backing store is protected as well as before.
- Local Caffeine, about 256 MB per podConfig, reference data, hottest products; weight-bounded, short TTL
- Shared Redis, about 30 GB plus replicaThe long tail, stored once for all pods
- Catalogue databaseOnly misses on both levels
3 layers, from the top down. Step through them one at a time.
4What Stays Local
The local layer should hold what is read on almost every request and changes rarely: configuration, feature flags, reference data such as categories and currencies, and the hottest products. These are the reads where even a millisecond per lookup adds up, because a single request may use them dozens of times.
The local cache should be bounded by weight rather than entry count, since catalogue entries vary widely in size; Caffeine's maximumWeight with a weigher based on the serialized size gives a real memory budget. Entries get short TTLs plus invalidation messages, so 200 local copies do not drift from the shared truth for long.
5Faster Warm-Up
With a 256 MB local cache and a warm shared layer, a new pod fills its local cache from Redis in seconds rather than from the database in minutes. Readiness probes should wait only for the critical set: configuration and reference data that every request needs. Product entries can fill on demand, because a local miss is now a cheap Redis hit. A 4-minute warm-up typically shrinks to well under a minute, which makes deploys and scale-outs faster as a side effect.
6Expressing the Decision in Cost
Finally, put it in the terms the bill review uses. The local layer costs RAM per pod times the number of pods; the shared layer costs a Redis cluster with replicas; and the latency budget says how much of the response time we may spend on the extra hop. In the example, shrinking local caches from 2 GB to 256 MB frees about 350 GB of RAM across the fleet, which may allow smaller instances, while adding a cluster of about 64 GB. Unless the latency budget is extremely tight, that is an easy trade.
The decision is not permanent. The local share of cost grows linearly with pods, the shared share does not, so the balance should be revisited whenever the pod count changes a lot, for example doubling for a new market.
7Follow-up questions
What would make you keep the large local caches after all?
A very tight latency budget combined with many lookups per request, where even pipelined Redis reads would add too much; a request rate so high that the shared cache would need to serve millions of lookups per second; data that is small and almost never changes, so duplication costs little; or a resilience requirement to keep serving fully during a Redis outage. If the replay shows that the hit ratio falls steeply with size, because access is not skewed, large local caches may also simply be the right tool.
Why bound the local cache by weight rather than entry count?
Because entries differ in size. A limit of 50,000 entries could be 50 MB or 2 GB depending on which products are cached. maximumWeight with a weigher gives a real memory budget, which is what the bill and the pod's memory limit care about.
How do you keep 200 local copies consistent?
With short local TTLs as the bound, and an invalidation channel, Redis pub/sub or a Kafka topic, so a change drops the local entry on every pod within seconds. Data that cannot tolerate even that should not be cached locally.
8Conclusion
In this answer, we saw that 200 pods with 2 GB local caches spend 400 GB of RAM on mostly duplicated data and take minutes to warm. We measure the access distribution by replaying logs against simulated cache sizes, which usually shows that a much smaller local cache keeps most of the hit ratio. The long tail moves to a shared Redis layer stored once and independent of pod count, the local layer keeps config, reference data and the hottest products bounded by weight with short TTLs and invalidation, readiness waits only for the critical set, and the decision is stated as RAM per pod times pods against shared-cache cost and latency budget.
Open with
I would start by measuring rather than guessing. Catalogue access is usually very skewed, so I would replay a day of one pod's access log through a simulated Caffeine cache at several sizes and plot hit ratio against size.
Then, if they want more
Typically a few hundred megabytes keep most of the hit ratio of 2 gigabytes. Whatever the smaller local cache no longer holds, the long tail, goes into a shared cache like Redis.
There each value is stored once for all pods, so instead of 400 GB of copies we pay for maybe 30 GB plus a replica, and its hit ratio does not depend on the pod count. It costs about a millisecond on those reads, which is usually fine.
Locally I would keep what almost every request reads and what rarely changes: configuration, reference data and the hottest products, bounded by weight, with short TTLs and invalidation. That also fixes warm-up: a small local cache fills from a warm Redis in seconds, and readiness only waits for the critical set like configuration.
Then I would present it as cost: RAM per pod times pods against the Redis cluster and the latency budget, and revisit it whenever the pod count changes a lot. I would keep large local caches only if the latency budget or request rate makes the extra hop impossible.
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 "How do you decide what belongs in the local layer, what belongs in a shared layer, and...": https://scrivio-interview-library.netlify.app/architecture/caching-strategies/c99ae6437e/