Cache Sizing Server Counts and Failure Headroom

Back of the Envelope Estimation · 40 min

System Design · Module 4 · Lesson 4 of 4 · 40 min

Cache Sizing Server Counts and Failure Headroom

Size a hot working set, translate hits into database demand, and reserve enough measured capacity for an instance failure.

Capacity must cover the workload during the failure you promise to tolerate, not only the warm steady state.

01 The idea

The problem this lesson solves

730,000 hot entries at 200 modeled bytes each need 146 MB before overhead.

Prerequisite: earlier lessons introduce the vocabulary and shared examples used here. Follow the module order.

Working setThe portion of data actively needed during a chosen interval.
Hit fractionThe share of cache lookups served by cached entries.
HeadroomCapacity deliberately left available for bursts, recovery and failures.

02 Worked example

Follow one worked example

Cache Sizing Server Counts and Failure Headroom worked diagram01Working setEntries × bytes02Warm cacheOnly misses reach DB03Cold cacheAll reads reach DB04SurvivorsEnough for peakKeep the units and assumptions visible at each step.Cache Sizing Server Counts and Failure Headroom compact diagram01Working setEntries × bytes02Warm cacheOnly misses reach DB03Cold cacheAll reads reach DB04SurvivorsEnough for peak
Working set: Entries × bytes • Warm cache: Only misses reach DB • Cold cache: All reads reach DB • Survivors: Enough for peak.

Trace the example in order. Follow the same identities, units and state transitions through the diagram and the events below.

1
Find the working set730,000 hot entries at 200 modeled bytes each need 146 MB before overhead.
2
Calculate misses2,000 QPS at 95% hits sends 100 read QPS to the origin.
3
Model recoveryAt zero hits, the origin sees 2,000 read QPS.
4
Reserve a survivor450 QPS at 100 budgeted QPS/instance needs five surviving instances, so six for one failure.

Capacity must cover the workload during the failure you promise to tolerate, not only the warm steady state.

03 The method

Mechanisms decisions and a guided tutorial

Work through the explanation in order, then apply it in the tutorial. Each comparison names a cost as well as a benefit.

Choice or conceptPurposeBoundary or cost
Hot-set sizingEntry count × actual entry costNot equal to a hit-rate percentage
Warm origin loadPeak reads × miss fractionInclude refresh and write work
Cold origin loadAll uncached readsRecovery needs bounds
Failure headroomSurviving tested capacityUse the promised failure domain

Estimate the hot set, not the whole database

Suppose 20 percent of the year's 3.65 million links should stay cached and each in-memory entry takes 200 bytes including its modeled key and metadata. That is 730,000 entries × 200 = 146 MB before allocator overhead and replication. These values must be measured for the chosen data structure. A hot-set percentage is about which items receive requests; it is not automatically the cache hit rate, which depends on the distribution of requests.

A hit rate changes the backing-store budget

With a 90 percent cache hit rate, database reads are 57.87 × (1 − 0.9) ≈ 5.79 QPS, excluding refreshes and writes. A cold cache drops the hit rate to zero and sends about 57.87 read QPS to the database. That is ten times the warm-cache read demand. The cache does not eliminate the need for overload protection or a recovery plan. Test both steady state and warm-up.

Convert a measured service rate into a starting count

Assume a load test finds one app instance can sustain 100 requests/s at the required latency for this workload. At 60 percent target utilization, budget 60 requests/s per instance. ceil(57.87 ÷ 60) = 1 serves the modeled read peak. Two instances can be a starting point for surviving one instance loss at that load, but this does not establish database, load-balancer or zone resilience. Capacity tests must include writes and realistic connection behavior.

Translate the result into a decision

Our small modeled workload does not justify sharding. A relational database, a modest stateless application pool, and a measured caching plan are reasonable candidates to test. If retention or traffic increases by 1,000×, rerun the arithmetic and locate the first limit. Use estimates to choose what to benchmark and where to investigate; a spreadsheet cannot prove tail latency, replication behavior or failure recovery.

Hot objects and popular requests are different

Caching twenty percent of the records does not imply twenty percent hits. Request popularity may concentrate heavily on a small set, or it may be almost uniform. Measure the access distribution and choose the working-set interval before selecting a cache size.

The yearly model contains 3.65 million links. Twenty percent is 730,000 entries. At an assumed 200 bytes per in-memory entry, that is 146 MB before allocator and replication overhead. Measure actual key, value and metadata costs in the chosen cache; a database row’s byte count is not automatically its in-memory footprint.

Model both the warm and cold paths

At 2,000 read QPS with 95 percent hits, the database receives about 100 read QPS before other work. At zero hits it receives all 2,000. A cache restart therefore creates a twenty-times increase in modeled read demand even though incoming client traffic stays constant.

A recovery plan can combine gradual warming, coalescing, concurrency limits and bounded stale responses where allowed. The cache lesson develops those controls; the sizing lesson makes their need visible in the worksheet. Do not assume unlimited fallback capacity merely because steady-state database charts look quiet.

Reserve the promised surviving capacity

Suppose load testing establishes a budget of 100 QPS per app instance at the required latency, and the target load is 450 QPS. Five instances serve it normally. To keep five after losing one, provision at least six under this simplified one-instance model.

A zone failure can remove several instances and a shared dependency, so the same arithmetic must match the actual failure domain. Capacity measurements should include the expected mix of reads and writes, connection reuse and realistic dependency latency. The worksheet identifies what to test; it does not replace the test.

Guided tutorial

1. Separate two percentages

Write object coverage and request hit fraction in different columns.

2. Size entries

Include modeled keys, values, metadata and copy count.

3. Add a cold row

Compute database demand when every read misses.

4. Remove capacity

Cross out one instance or one zone and recompute whether the remaining budget meets demand.

cache_bytes = hot_entry_count * measured_bytes_per_entry
db_reads = peak_reads * (1 - hit_fraction)
serving_instances = ceil(peak_qps / budgeted_instance_qps)
# For one-instance loss under this simple model:
provisioned_instances = serving_instances + 1

04 Cheat sheet

Review the decisions

Use this table to explain the mechanism and its limit without memorizing a product name.

Choice or conceptRememberCheck
Hot-set sizingEntry count × actual entry costNot equal to a hit-rate percentage
Warm origin loadPeak reads × miss fractionInclude refresh and write work
Cold origin loadAll uncached readsRecovery needs bounds
Failure headroomSurviving tested capacityUse the promised failure domain
Working setThe portion of data actively needed during a chosen interval.
Hit fractionThe share of cache lookups served by cached entries.
HeadroomCapacity deliberately left available for bursts, recovery and failures.

05 Where & why

Check the primary references

Use official references for protocol and implementation details. The questions here are teaching prompts.

Primary reference
Google SRE overload handling

Read Google SRE overload handling

Primary reference
Google SRE service-level objectives

Read Google SRE service-level objectives

State the implementation version and the workload assumptions when defending your own design.

06 Interview questions

Explain the reasoning out loud

Answer before opening the explanation. The questions progress from vocabulary to decisions and failure behavior.

What does Working set mean?
The portion of data actively needed during a chosen interval.
What does Hit fraction mean?
The share of cache lookups served by cached entries.
What does Headroom mean?
Capacity deliberately left available for bursts, recovery and failures.
Why can a tiny cache have a high hit rate?
A small set of popular keys can account for most requests. Hit rate follows request frequency, not merely the fraction of objects stored.
Why not size cache entries from payload alone?
Keys, metadata, allocator behavior and copies also consume memory. Measure representative entries in the chosen implementation.
What changes when the cache is cold?
The miss fraction rises, increasing backing-store work and potentially queueing. Recovery capacity must be assessed separately from the warm case.
Does N+1 prove zone resilience?
No. Losing a zone may remove several instances or dependencies. Match the spare-capacity model to the actual promised failure.
Why use a budget below measured maximum throughput?
The maximum may have poor latency and no tolerance for bursts. Choose and test a target utilization under the real workload.

07 Practice problems

Practice a new case

Solve the new cases before revealing hints. Complete worked solutions follow the set.

Daily requests

Easy
Convert 8.64 million reads per day into average QPS.
Follow-up
Use a full 24-hour day.
Show the hint
There are 86,400 seconds per day.

Entry sizing

Easy
Size 5,000 hot entries at 300 bytes each.
Follow-up
State the assumption or edge case that makes the answer correct.
Show the hint
Multiply count by actual entry cost.

Cold-cache factor

Medium
Compute warm and cold database read QPS for a 2,000 read-QPS service at 95 percent hits.
Follow-up
Do not confuse the hit fraction with the miss fraction.
Show the hint
The database sees misses.

One failure

Medium
Find the minimum number of instances that can serve 450 QPS after losing one, if each is budgeted for 100 QPS.
Follow-up
Round up before reserving the failure allowance.
Show the hint
The surviving instances must cover all demand.

Two-instance loss

Medium
Find the minimum instances for 320 QPS after losing two when each is budgeted at 80 QPS.
Follow-up
State the assumption or edge case that makes the answer correct.
Show the hint
Count required survivors first.

Capacity defense

Hard
Write a capacity check for a read-heavy service that must survive cache restart and one app loss together.
Follow-up
State the assumption or edge case that makes the answer correct.
Show the hint
The failure scenarios can overlap.

Worked solutions

1. Daily requests

8,640,000 / 86,400 = 100 read QPS.

2. Entry sizing

1,500,000 bytes, or 1.5 decimal MB, before any unmodeled overhead or copies.

3. Cold-cache factor

Warm database reads are 2,000 × 0.05 = 100 QPS. Cold reads are 2,000 QPS, a 20× increase.

4. One failure

Five surviving instances are required because ceil(450/100) = 5. Provision at least six under this simplified one-instance-failure model.

5. Two-instance loss

Four survivors are needed, so at least six instances under this simplified independent-instance model.

6. Capacity defense

Estimate incoming peak and cold-cache origin work, then test surviving app and database capacity with bounded concurrency. State admission or degradation when the combined demand exceeds the tested budget.