Course contentsShow
← System Design
Lesson 208 of 1,9196. Database Scaling: Read ReplicasFree lesson

Replication Lag: What It Is and Why It Happens

Understanding the delay between writes on primary and their appearance on replicas, and the fundamental causes.

Replication Lag: What It Is and Why It Happens

What you'll learn: You'll understand replication lag—the delay between a write on the primary database and when that change appears on replicas—and why it naturally occurs in distributed systems.

What Is Replication Lag?

Imagine you write something in your diary, then ask your assistant to copy it into backup notebooks. Replication lag is the time between when you finish writing and when your assistant catches up with all the copies.

In database terms, replication lag is the time delay between:

  1. A write operation completing on the primary database
  2. That same change becoming visible on one or more replicas

If you update a user's profile on the primary at 10:00:00, but the replica doesn't show that change until 10:00:02, you have 2 seconds of replication lag.

Why Does Replication Lag Happen?

Several fundamental factors cause lag:

Network delay: Changes must travel over the network from primary to replicas. Physical distance and network congestion add time.

Replication mode: Asynchronous replication inherently creates lag because the primary doesn't wait for replicas to confirm receipt before completing the write.

Replica processing time: Replicas must apply the changes they receive. If a replica is busy serving read queries or processing a large batch of updates, new changes queue up.

Volume of writes: Heavy write traffic creates a backlog. The replica processes changes sequentially, so high write rates increase lag.

Resource constraints: If a replica has slower CPU, less memory, or slower disks than the primary, it can't keep pace.

This lag is why you might update your profile picture and still see the old one when the page loads from a replica milliseconds later.

Key Takeaway: Replication lag is the inevitable delay between primary writes and replica updates, caused by network transit time, processing overhead, and the asynchronous nature of most replication strategies.