Telemetry
Infrastructure SQL recipe

Find Cache Misses and Stampede Risk

Compare hit rate, backend cost, and concurrent misses by bounded cache-key pattern.

Intermediatecache_request_eventsReviewed 2026-07-28Tested with Apache DataFusion 45.2.0

Reviewed by the Telemetry product team on . SQL compatibility, event contract, synthetic output, and operational caveats. Editorial ownership

Question answered

Which cache-key patterns combine a poor hit rate with concurrent backend work?

Hit rate alone can hide a damaging burst. This query keeps concurrent misses and backend duration beside miss rate so teams can distinguish normal cache churn from stampede risk.

Event contract

Fields the query expects

FieldTypeWhy it exists
timestamp_utcTimestampCache lookup completion time in UTC.
cache_key_patternUtf8Bounded pattern such as product:{id}, never a raw key.
cache_hitBooleanWhether the lookup returned a cached value.
concurrent_missesInt64Observed in-flight fills for the same pattern.
backend_duration_msFloat64Fallback duration; zero for a hit.
environmentUtf8Deployment environment.
DataFusion SQL

Copy the query

sql
SELECT
  cache_key_pattern,
  COUNT(*) AS requests,
  SUM(CASE WHEN cache_hit THEN 1 ELSE 0 END) AS hits,
  SUM(CASE WHEN cache_hit THEN 0 ELSE 1 END) AS misses,
  100.0 * SUM(CASE WHEN cache_hit THEN 0 ELSE 1 END)
    / NULLIF(COUNT(*), 0) AS miss_rate_pct,
  MAX(concurrent_misses) AS maximum_concurrent_misses,
  AVG(CASE WHEN cache_hit THEN NULL ELSE backend_duration_ms END)
    AS average_backend_duration_ms
FROM cache_request_events
WHERE timestamp_utc >= now() - INTERVAL '24 hours'
  AND environment = 'production'
GROUP BY cache_key_pattern
ORDER BY maximum_concurrent_misses DESC, cache_key_pattern;

This read-only query is planned and executed against an empty typed table with Apache DataFusion 45.2.0. The deterministic sample output is synthetic and reviewed separately; validate field types, thresholds, and business definitions against your own data. Read the testing methodology.

Query result

Cache miss and stampede indicators

Product lookups combine a 50% miss rate with 31 concurrent fills and the higher backend cost.

cache_key_patternrequestshitsmissesmiss_rate_pctmaximum_concurrent_missesaverage_backend_duration_ms
product:{id}10555031232
feature-flags:{account}87112.5775

Synthetic example output. Run the query against your own event schema and thresholds before using it for operational decisions.

Cache miss and stampede indicators: static chart of synthetic miss_rate_pct values from the Find Cache Misses and Stampede Risk example result
Indexable SVG of the deterministic example output. Download it for an article, runbook, or design review with attribution.

Reproduce the example

Download the public fixture

The JSON bundle includes the typed event contract, reproducible input rows, exact SQL, expected output, review notes, and engine version. The CSV contains the displayed result.

How the SQL works

  1. 1The grouping key is a bounded application-defined pattern rather than a high-cardinality raw cache key.
  2. 2Miss rate captures efficiency while maximum concurrent misses exposes burst behavior.
  3. 3Backend duration is averaged only for misses because hits do not execute the fallback.

Edge cases to decide

  • Define concurrent_misses consistently at lookup time or fill start.
  • Split cold-start deployments from steady-state traffic when cache warming is expected.
  • Use percentiles rather than averages when backend duration has a heavy tail.

Recommended dashboard

  • Scatter plot: miss_rate_pct versus maximum_concurrent_misses
  • Trend: misses and backend duration by cache-key pattern
  • Table: top bounded patterns by backend work

Alert guidance

Alert when concurrent misses and backend duration rise together for a material request volume.

Read alert setup

Put the recipe to work

Related instrumentation and guides

Continue the analysis

Run it on real events

Create a table, adapt the fields, and save the result

Start free, send structured events, and use the query result as a chart, shared dashboard widget, or alert input.

Get an API key