What is Read-Replica Lag?
Read-replica lag is the delay between when a primary database processes a write and when that update is visible on its read replicas, sometimes causing replicas to serve stale data.
When to Use
Read replicas are used to handle read-heavy workloads, such as analytics dashboards, reporting tools, or news feeds, where slightly stale data is acceptable and improves scalability.
Example
If you add a comment on a post and instantly refresh a feed powered by a read replica, you might not see your comment right away due to lag.
Want to go deeper? Explore Grokking System Design Fundamentals, Grokking the System Design Interview, Grokking Database Fundamentals for Tech Interviews, or practice with Mock Interviews with ex-FAANG engineers.
Why Is It Important
Read-replica lag matters because it impacts data consistency. High lag can confuse users, as they may see outdated values after making changes.
Interview Tips
In interviews, define read-replica lag clearly, explain the consistency trade-off, and mention solutions like using the primary database for critical reads or monitoring lag metrics.
Trade-offs
You gain performance and scalability but lose immediate consistency. This trade-off is central to many system design discussions.
Pitfalls
Common mistakes include assuming replicas are always up to date or not setting up monitoring/alerts for lag, which can lead to bugs in production.
GET YOUR FREE
Coding Questions Catalog
$197

$78
$78