Hit ratio — the headline and the diagnostic ladder

Hit ratio is the one number that tells you whether the CDN is earning its money — request hit ratio for users, byte hit ratio for the bandwidth bill — and when it's low the diagnostic ladder is Vary cardinality → TTL config → purge frequency → bypass rules → cookie cache key.

Previously

Every lever we've built — TTL, Vary, purge, shield, bypass — moves one number, origin RPS, and the headline that summarizes them all is hit ratio; this is the dashboard you read, and the ladder you walk when it's low.

Scene 11

Hit ratio — the headline and the diagnostic ladder

  1. Watch
  2. Try it
  3. Predict
  4. Capture
Request hit ratio92.0%Byte hit ratio88.0%Origin RPS38.0REQUEST FLOW · HIT vs MISSband thickness ∝ share of trafficincoming100%HIT · 92.0%served from edge cacheMISS · 8.0%Vary explosion20% of missno-store / no-cache header20% of missrecent purge20% of missbypass rule20% of misscookie in cache key20% of missDIAGNOSTIC LADDER5 steps11 — Inspect Varyscene 8Vary on cookies / UA fragment…22 — Read respons…scene 4no-store / no-cache forces re…33 — Check purge …scene 7Recent purge cleared the work…44 — Audit bypas…scene 10Cookie / query rule bypassing…55 — Examine cach…footgunCookie pinned into the cache …Healthy dashboard. Request hit ratio 92%, byte hit ratio 88%, origin RPS low. Miss bucket distribution is uniform — no single failure mode d…
What to watch for

How do you tell if your CDN is earning its money? The first number you check is what fraction of requests it serves from its own cache vs forwarding to origin — that fraction is the hit ratio, and it splits into two: request hit ratio (what users feel) and byte hit ratio (what the CFO pays for). Healthy dashboard shown: request hit ratio 92%, byte hit ratio 88%, origin RPS low; the Sankey is mostly green-HIT and the thin red MISS share is spread evenly across the five buckets — no single failure mode dominates.

Continue unlocks when the animation finishes.
Implementation

Highlighted lines are the ones running in the diagram right now.

Dashboard.computeHitRatio
the two headline numbers, computed from edge log lines
def computeHitRatio(edge_logs):
hits = count(l for l in edge_logs if l.cache == 'HIT')
misses = count(l for l in edge_logs if l.cache == 'MISS')
request_hit_ratio = hits / (hits + misses)
bytes_from_cache = sum(l.bytes for l in edge_logs
if l.cache == 'HIT')
total_bytes = sum(l.bytes for l in edge_logs)
byte_hit_ratio = bytes_from_cache / total_bytes
# diverges when one big-object class misses
return request_hit_ratio, byte_hit_ratio
Operator.diagnose
the 5-step ladder, ordered cheapest-investigation-first
def diagnose(metrics):
if metrics.vary_cardinality_per_url > 5:
return 'vary' # one curl, read Vary header
if metrics.ttl_avg < 60 or metrics.no_store_pct > 0.1:
return 'ttl' # curl asset, read Cache-Control
if metrics.purge_rate_per_hour > 10:
return 'purge' # check CI logs for zone-wide purges
if metrics.bypass_pct > 0.2:
return 'bypass' # audit /api/* style rules
if metrics.cookie_in_key:
return 'cookie' # strip cookies for asset paths
return 'investigate_origin'

Where this sits in Build a CDN

Scene 11 of 13, in the Operating act — Shield, bypass routes, and the hit-ratio dashboard.. Request hit ratio vs byte hit ratio, and the 5-step ladder when it crashes: Vary cardinality → TTL config → purge frequency → bypass rules → cookie key.

Up next. Now that you can read the dashboard and run the ladder, the capstone asks the inverse question: design the configuration that produces a healthy one for a stated workload.

All 13 scenes in Build a CDN · Every curriculum

Built with Arqly
Every scene in Build a CDN builds on the one before it.All 13 Build a CDN scenes