Observe cache value and test safe bypass
Connect useful reuse, freshness, and origin headroom instead of treating hit ratio as the cache's complete health signal.
On this page
The question for today
What you’ll understand
- Separate positive hits, stale hits, negative hits, and suppressed errors.
- Calculate the origin-load increase caused by a bounded bypass fraction.
- Design a bypass and recovery test that respects origin capacity.
A cache can report excellent hit ratio while serving stale data, negative results from an outage, or cheap objects that save little origin work. Observability should explain useful reuse and the cost of losing it. Bypass testing asks what happens when selected requests reach the origin directly, but an uncontrolled test can create the failure it tries to measure. Budget origin headroom, preserve authorization and correctness, and distinguish a small experiment from a full cache-loss rehearsal.
Count outcomes that mean different things
Record positive fresh hits, permitted stale hits, authoritative negatives, transient-error reuse, misses, revalidations, and coalesced waits separately. A hit may still involve network and decoding cost, and a coalesced follower may wait nearly as long as a miss while avoiding extra origin work. Track end-to-end latency, age, source version where available, and origin cost. A global average can hide one tenant or key family with poor correctness or a hot-key bottleneck.
Use compatible denominators and intervals. Request hit rate, byte hit rate, and avoided origin CPU can diverge sharply. A cache server's lookup miss count may include retries or internal probes absent from the application's request count. A fill rejected by admission or a version guard is not necessarily a malfunction; its reason matters. Avoid raw-key labels that expose private data or create unbounded metric cardinality. Aggregate by deliberate nonsecret cohorts and retain sampled diagnostic traces under appropriate access controls.
Bypass changes the origin's workload
If a fraction of requests bypasses a cache independently, those requests go to the origin even when they would have hit. The remaining requests retain their original miss fraction only as a planning assumption. A true cache outage can also trigger retry waves, lost coalescing, cold dependent caches, and a different request mix. Start with a controlled fraction and a stop condition based on origin saturation, error rate, and latency rather than jumping directly to complete bypass.
Shadow reads can compare cached and origin versions, but still consume origin capacity and need correct authorization, deadlines, and nonmutating semantics. Do not replay an unsafe operation merely because it is labeled a cache check. Stale comparisons need a common source-version or age interpretation; reading a lagging replica can make a newer cache look wrong. Sample discrepancies and classify their cause before automatically replacing values or broadening invalidation.
Include recovery and cold warming
A cache-loss test is incomplete without recovery. Warming many entries simultaneously can recreate a stampede even after the origin has survived the outage. Pace fills, preserve version guards, and prioritize actually requested valuable keys rather than loading every historical key blindly. Observe eviction churn and memory pressure as the cache returns. Compare restored freshness and useful latency with the baseline, not merely whether connections reconnect and the hit counter begins increasing.
The queue lab makes the capacity assumption visible. Reset and set both λ=2, μ=3, predict declining backlog from four, then Step. For a separate higher-origin-load scenario Reset and re-set λ=4, μ=3, predict growth and Step. Rates are abstract jobs, not this lesson's measured QPS; the model has no hit ratio, bypass switch, retries, or saturation feedback. Use it to explain why a rate increase crossing service capacity needs a stop condition, then map actual measured rates to a justified admission budget.
Work it through
A small bypass can nearly double origin load
A fixed workload sends 10,000 requests/s with 90% reusable hits. Plan an independent 10% bypass while assuming the remaining requests keep the same hit rate and there are no retries or refresh changes.
Baseline origin load is 10,000×0.1=1,000 requests/s. The bypassed group sends 1,000 requests/s directly to the origin.
The other 9,000 requests/s retain a 10% miss fraction, adding 900 origin requests/s. Total planned origin load is 1,900 requests/s, a 90% increase over baseline.
Complete bypass would send 10,000 requests/s, ten times baseline under this simplified model. Verify origin headroom before raising the bypass fraction; real failure behavior can add retry or warming load beyond this estimate.
A modest bypass percentage can cause a large relative increase in origin work when the baseline cache is effective.
The living notebook
Explore the model
Interactive lab · queue
Bypass must fit an origin budget
Reset, set λ=2, μ=3, predict decline, then Step. Reset and re-set λ=4, μ=3, predict growth, then Step. This fluid aggregate queue does not calculate hit ratios, bypass fractions, retries, or real origin capacity.
- Fluid backlog
- 4
- Net rate · λ − μ
- −1 /s
- M/M/1 mean residence
- 1 s
Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forA cache experiment must stop or shed work before additional origin demand exceeds its verified capacity.
Pause & reason
Check your understanding
Your turn
Try it yourself
A service handles 2,000 requests/s with 75% hits. Under the simple independent-bypass model, estimate origin QPS with 20% bypass and compare it with the baseline. Name one reason a full outage could exceed the model.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Bypassed requests always reach origin; nonbypassed requests retain the stated miss fraction only by assumption.
Compare with the solution
Baseline origin load is 2,000×0.25=500 QPS. With bypass it is 2,000×[0.2+0.8×0.25]=800 QPS, a 60% increase. An outage may add retries, remove coalescing, or trigger dependent cache misses, producing more work than this fixed-workload estimate. Use measured stop conditions and capacity-aware admission rather than treating the arithmetic as a safe maximum.
Keep the idea
Take it with you
- Typed useful outcomes and freshness matter alongside hit ratio.
- Bypass load must be estimated relative to the origin's existing miss workload.
- Test cold recovery, correctness, and capacity stop conditions together.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.