Sub topic 14
Observability, replication lag and failure testing
This chapter assumes you know basic cloud monitoring, the replication ideas from earlier chapters, and how health checks drive failover. An active-active design only works if you can see its state and have practiced its failures. Here you will learn what to measure, how to treat replication lag, and how to test.
What to observe
Per-region dashboards hide most multi-region problems. You need signals that compare regions.
| Signal | Why it matters |
|---|---|
| Replication lag (seconds behind) | Sets your real RPO and the staleness users see |
| Error rate and latency per region | Shows a degraded region before health checks fail |
| Conflict count | A rising rate means write ownership or merge rules are wrong |
| Traffic share per region | Confirms routing matches your intent |
| Queue depth and age of oldest message | Shows cross-region event backlogs |
| Capacity utilization per region | Shows whether survivors can absorb a failure |
Alert on trends and on user-facing results, not only on host metrics. A region can pass its health check and still serve stale or failing responses.
Measuring replication lag
Replication lag is the delay between a write committed in one region and the same write being visible in another. Many databases report it, but the number can mislead. An idle system may report zero lag because nothing is waiting, and a stalled link may report no data at all.
A reliable method is a heartbeat. A writer in each region updates a row with the current time every few seconds. Other regions read that row and compute the age of the value.
import time
def lag_seconds(heartbeat_written_at, now=None):
"""Age of the newest heartbeat seen from a remote region."""
now = time.time() if now is None else now
return max(0.0, now - heartbeat_written_at)
def check_lag(heartbeats, threshold=5.0, now=None):
"""heartbeats maps region name to the last heartbeat timestamp seen."""
alerts = []
for region, written_at in heartbeats.items():
lag = lag_seconds(written_at, now)
if lag > threshold:
alerts.append((region, round(lag, 1)))
return alerts
print(check_lag({"eu-west-1": 1000.0, "us-east-1": 990.0}, now=1002.0))
# [('us-east-1', 12.0)]The check compares timestamps from different machines, so clock drift adds error. Keep the threshold well above your expected clock skew. Also alert when a heartbeat stops arriving, since a missing heartbeat is worse than a late one.
What to do when lag grows
Decide in advance how the system reacts. Common options are to route reads that need fresh data to the owning region, to show a staleness notice, to pause non-critical writes, or to stop sending traffic to a region whose data is too old. Each option trades availability for correctness, so tie the threshold to a business requirement.
Testing failures
A failover path that has never run should be assumed broken. Test in stages.
- Start in a staging environment that matches production topology.
- Inject a single fault: block traffic to one region, add network latency between regions, or stop replication.
- Check the expected result: traffic shifts, errors stay under budget, and no data is lost beyond your RPO.
- Restore the fault and confirm the region catches up and conflicts resolve.
- Move to production with a small blast radius, during working hours, with a stop condition.
Test partial failures as well as full outages. Slow links, a single failing dependency, and one-way network loss often cause more damage than a clean region loss, and they are where split brain appears.
Exercise
Your replication lag metric reads 0 seconds in the quiet hours, yet users report missing data after a link problem. What is a likely cause, and what would you add?
Show answer
The metric reports lag only when there are pending changes, so a stalled link with no new writes can look healthy. Add a heartbeat write in each region and alert on the age of the newest heartbeat seen remotely, including when it stops arriving.