Telemetry
Database reliability SQL recipe

Measure Database Replica Staleness by Region

Compare application-observed replica replay lag, stale reads, and failover outcomes by region.

Advanceddatabase_replica_read_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 replica regions are serving stale or failed reads?

Infrastructure replication lag does not always equal application-visible staleness. Read events can preserve the selected replica role, replay lag, and consistency outcome.

Event contract

Fields the query expects

FieldTypeWhy it exists
timestamp_utcTimestampReplica read completion time.
regionUtf8Application region.
replica_roleUtf8primary, replica, or failover target.
replay_lag_msFloat64Observed or reported replay lag.
consistency_outcomeUtf8fresh, stale, failed, or unknown.
operation_nameUtf8Controlled application read operation.
DataFusion SQL

Copy the query

sql
SELECT
  region,
  replica_role,
  operation_name,
  COUNT(*) AS reads,
  approx_percentile_cont(replay_lag_ms, 0.95) AS p95_replay_lag_ms,
  SUM(CASE WHEN consistency_outcome = 'stale' THEN 1 ELSE 0 END)
    AS stale_reads,
  SUM(CASE WHEN consistency_outcome = 'failed' THEN 1 ELSE 0 END)
    AS failed_reads
FROM database_replica_read_events
WHERE timestamp_utc >= now() - INTERVAL '24 hours'
GROUP BY region, replica_role, operation_name
ORDER BY stale_reads DESC, p95_replay_lag_ms DESC;

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

Stale reads by replica region

The ap-southeast subscription read has the highest observed staleness and replay-lag tail.

regionreplica_roleoperation_namereadsp95_replay_lag_msstale_readsfailed_reads
ap-southeastreplicasubscription-status18,4004,82021418
eu-westreplicaproject-list42,100740312

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

Stale reads by replica region: static chart of synthetic stale_reads values from the Measure Database Replica Staleness by Region 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, illustrative input rows, exact SQL, expected output, review notes, and engine version. The CSV contains the displayed result.

How the SQL works

  1. 1Replica role and region identify the read path.
  2. 2Application consistency outcome records user-visible staleness separately from reported lag.
  3. 3Operation name shows which workflows require stronger read-after-write behavior.

Edge cases to decide

  • Consistency outcome requires a defensible application check.
  • Replay lag units vary by database and collector.
  • Database-native replication and failover tooling remains the source for server diagnosis.

Recommended dashboard

  • Bars: stale_reads by region
  • Trend: p95_replay_lag_ms by role
  • Table: failed reads by operation

Alert guidance

Alert when a critical operation serves stale or failed reads beyond its reviewed consistency objective.

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