watch-replication-lag-as-a-durability-gap
Use when reads or failover depend on a replica. Measures replication lag continuously and treats it as the real RPO, alerting before a failover loses acknowledged data.
- License 许可
- MIT
- 最近更新
- 2026-11-12
- Stars
- ★ 81
- Forks
- 17
01 前言 Front Matter
- name
- watch-replication-lag-as-a-durability-gap
- description
- Use when reads or failover depend on a replica. Measures replication lag continuously and treats it as the real RPO, alerting before a failover loses acknowledged data.
02 资源文件 3
- 许可证LICENSE1.0 KB
- 参考文档SOURCE.md367 B
- 参考文档TRUST.auto.yaml2.2 KB
03 SKILL.md 正文
Watch Replication Lag as a Durability Gap
The promise "we have a replica" means nothing until you know the lag. Lag in seconds is the data a failover can lose; unmonitored lag turns a failover into silent data loss. Track it as a first-class durability metric.
Procedure
- Measure lag from the replica's perspective, not the primary's — the primary often cannot see a replica that stopped applying.
- Postgres:
SELECT now() - pg_last_xact_replay_timestamp() AS lag;on the standby; usepg_last_wal_receive_lsn()vsreplay_lsnfor byte lag. - MySQL:
SHOW REPLICA STATUS\G→Seconds_Behind_Source(and checkReplica_IO_Running/SQL_Runningare bothYes). - Redis/Kafka: consumer-group lag
kafka-consumer-groups.sh --describe --group xorredis-cli info replicationmaster_link_down_since_seconds. - Export lag as a metric and alert on both bounds: warn at 5s, page at 60s, and page immediately on
nulllag (the standby lost connection). - Alert when lag is trending up over an hour even if the instant value is low — a slow replica catches up only after the write burst ends.
- Tie the alert to the failover runbook: if lag exceeds the RPO window at failover time, the runbook must say to check before promoting.
- Test the metric by pausing replication (
SELECT pg_wal_replay_pause();) and confirming the alert fires within the expected delay.
Pitfalls
- Measuring lag on the primary, which reports 0 when the replica has silently stopped — the classic blind spot.
- Alerting on
Seconds_Behind_Sourceonly; it can read 0 while the replica is stuck on a conflicting transaction and not applying. - Ignoring byte lag: a standby replaying a steady state can show 0 seconds yet be gigabytes behind after a bulk load.
- A single async replica as the only copy, then promoting it during a primary outage and losing the un-replicated tail.
- Cascading lag: a replica-of-a-replica inherits the parent's lag and hides it from the primary's monitoring.
- Not accounting for lag during failover time itself; promotion freezes writes and widening the loss window further.
- Muting the lag alert during a known batch job and forgetting to unmute, so the next real stall goes unnoticed.
Verification
psql -h standby -c "SELECT now() - pg_last_xact_replay_timestamp() AS lag;"
# alert test
psql -h primary -c "SELECT pg_wal_replay_pause();" # on standby; lag should climb and page
Lag is exported, an induced stall raises the alert within the configured delay, and the failover runbook checks lag against the RPO before promoting.
Report: "Replication lag metric on <N> replicas (warn 5s/page 60s); induced stall alerted in <x>s; current max lag <y>s vs RPO <z>s."
04 同仓库更多 Skills
recipe-performance
Diagnose a specific MetaMask user flow's real-app performance and Sentry critical-user-flow telemetry with deterministic mm-harness recipes. Use for CUF boundaries, cold/warm/background-resume behavior, latency regressions, lifecycle tags, duplicate or blocking network requests, long tasks, layout/paint cost, screen redraws, React rerenders, or browser trace analysis where tests alone cannot prove the real app.
mexc-spot-websocket
MEXC Spot WebSocket workflows for public streams, protobuf handling, depth maintenance, listen keys, and private streams without exposing API keys.
mexc-spot-rest
MEXC Spot REST workflows for public data, signed account requests, orders, wallet/admin actions, and secure signing without exposing API keys.
mexc-futures-websocket
MEXC Futures WebSocket workflows for public streams, private account/order/position streams, ping/pong, subscriptions, and depth maintenance.
0xklen-version-and-refresh-sanctions-lists
暂无简介
verify-tests-cover-changed-lines
Use when a PR adds code that the existing suite may not exercise. Measures patch coverage — the share of newly changed lines hit by tests — before approving.