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.
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_indexand as wall-clocknow() - 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|sessionand 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
minCommitIndexin 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.