Course contentsShow
← System Design
Lesson 1358 of 1,91934. Data Replication StrategiesFree lesson

Replication Lag in Async Systems

Understanding the delay between primary writes and replica updates, and its impact on read consistency.

Replication Lag in Async Systems

What You'll Learn

You'll understand what replication lag is in asynchronous systems, why it occurs, and how it can break read consistency expectations.

The Core Concept

In asynchronous replication, the primary database accepts writes and immediately returns success to the client before those changes reach the replicas. The replicas eventually catch up, but there's always a delay—this delay is called replication lag.

Why It Happens

Replication lag occurs because:

  • Network latency between primary and replicas
  • Replica processing time (applying changes takes CPU cycles)
  • Volume of writes overwhelming replica throughput
  • Geographic distance in multi-region setups

The Read Consistency Problem

Imagine you post a comment on a social media site. The write goes to the primary database, which immediately confirms "Saved!" But when the page refreshes, your comment is missing. Why? Your read request was routed to a replica that hasn't received the update yet—it's "lagging behind."

This creates several consistency anomalies:

  • Read-your-writes violation: You can't see your own changes
  • Moving backwards in time: Refreshing shows older data
  • Monotonic read violations: Reading from different replicas shows inconsistent timelines

Measuring Lag

Replication lag is typically measured in:

  • Time: Seconds or milliseconds behind
  • Transaction count: Number of operations queued

A replica lagging by 5 seconds means data you read could be 5 seconds stale.

Real-World Impact

For analytics queries, 5-minute lag might be acceptable. For user-facing features like inventory counts or account balances, even 1-second lag can cause serious problems—double-booking tickets, overselling products, or confusing users.

Key Takeaway: Replication lag is the inevitable delay between primary writes and replica synchronization in async systems, creating a trade-off between write performance and read consistency that must be carefully managed based on application requirements.