Skip to content
Telemetry
Infrastructure SQL recipe

Find cache misses and stampede risk

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

Intermediatecache_request_eventsReviewed 2026-07-28Tested with Apache DataFusion 45.2.0

Reviewed by the Telemetry product team on . We checked the SQL syntax, required event fields, sample results, and limits on using the query. Who reviews this page

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 schema

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. We review the synthetic sample output separately. Check field types, thresholds, and counting rules 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
Download this SVG chart of the sample results for an article, runbook, or design review. Please credit Telemetry.

Reproduce the example

Download the sample data

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

How the SQL works

  1. 1Group by a fixed set of cache-key patterns your app defines. Raw cache keys would create too many groups.
  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 check

  • 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 of cache-key patterns with the most backend work

Alert guidance

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

Read alert setup

Set up the events this query needs

Related instrumentation and guides

Continue the analysis

Run it on your 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