Skip to main content
PreparationZone Logo
PrepZone

Read Replicas and Replication Lag

Serve reads from followers but know your staleness budget — ShardPay balance queries.

Pass checkpoint below

Read these first

Why this matters

  • Serving reads from followers without a lag budget causes user-visible bugs — "I paid but balance didn't change."
  • ShardPay routes balance checks to the primary after user actions; history and analytics hit replicas with documented staleness.
  • Monitoring replication lag is mandatory — it is the leading indicator before replica-induced incidents.
  • Interviewers ask how you expose staleness to clients and when you force leader reads.
Write
LeaderLatest data
Follower 1Lag 50ms
Follower 2Lag 200ms
Followers trail the leader — reads may return stale data until replication catches up.

Staleness budget

ShardPay's transaction history API tolerates 30 seconds of replication lag on read replicas. Live balance checks after a transfer hit the primary or a session-routed replica caught up within 200ms. Merchants see a "syncing" badge when replicationLagMs exceeds the SLO — transparency beats silent wrong data.

A staleness budget is a product decision encoded in infrastructure: not every replica is wrong for every query.

Key concepts

  • Replication lag — Time or byte offset between leader's latest commit and a follower's applied position. ShardPay measures lag as leader_commit_index - replica_applied_index and as wall-clock now() - last_replicated_at.
  • Read routing — Direct queries to primary, replica, or hybrid based on consistency needs. ShardPay's API gateway reads X-Read-Preference: primary|replica|session and routes accordingly.
  • Lag SLO — Maximum acceptable lag before alerting or degrading UX. ShardPay alerts at lag > 5s (warning) and > 30s (page on-call); history API shows syncing badge at > 10s.
  • GTID / log offset — Global transaction ID or commit index tracking replication position. ShardPay clients receive minCommitIndex in transfer responses for session-aware replica selection.
  • Catch-up reads — Replica promoted to serve session only after applying through minCommitIndex. Avoids leader load for every post-action poll while guaranteeing read-your-writes.

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 2 sections

  • Routing rules by endpoint
  • Operating replicas under load

Test yourself

Answer these before moving on — recall is what makes it stick.