← Lessons

quiz vs the machine

Platinum1820

Databases

Replication Stream Internals

How replicas stay current by shipping and replaying the log.

5 min read · advanced · beat Platinum to climb

Replaying the Log Elsewhere

A replica keeps a copy of the primary by consuming its write ahead log stream. The same records that protect the primary against crashes are shipped to replicas, which replay them to reproduce every change in order.

Physical Versus Logical

  • Physical replication ships raw page level WAL records, producing an exact byte copy. It is efficient but the replica must match the primary version and layout.
  • Logical replication decodes the log into row level change events, which can target a different schema or version and feed selective tables.

Lag and Synchronous Modes

Replays trail the primary by some replication lag. In asynchronous mode the primary commits without waiting, risking a small window of loss on failover. In synchronous mode the primary waits for a replica to confirm the log record is durable before acknowledging commit, trading latency for stronger guarantees.

Key idea

Replicas consume the primary WAL stream and replay it, with physical replication copying pages and logical replication decoding row events, while synchronous mode waits for replica confirmation to reduce data loss.

Check yourself

Answer to earn rating on the learn ladder.

1. What does a replica consume to stay current?

2. How does logical replication differ from physical?

3. What does synchronous replication trade for stronger durability?