DataUpdated 2026-11-20

Read replicas

Copies of the primary that serve reads: when they help, what replication lag does, and why a replica is not a backup.

Photocopies of the ledger, so many people can read it without queuing.

That is a read replica. The original ledger stays in the back room for writing. Copies sit at the front, and anyone who only needs to look can read a copy.

How it works

A read replica is a copy of the database that serves read traffic, so the primary can focus on writes.

Code
Writes → Primary
Reads  → Replica 1, Replica 2

The primary sends its changes to each replica. Replicas apply them and answer read queries.

Code
            Primary
               │
       ┌───────┴───────┐
    Replica 1       Replica 2

Consider a workload of 100,000 reads for every 10,000 writes. Without replicas, the primary does all of it. With replicas, the reads spread out and the primary load drops.

Replication lag

Replication is not instant. For a short time a replica can be behind.

Code
Primary:  username = Ahmed
Replica:  username = Zeeshan   (briefly stale)

This is a consistency trade-off. For most reads, such as a product list, a few seconds of staleness is harmless. For a user who just saved a change and reloads, it is not. The usual answer is read-your-writes: send those specific reads to the primary, and send the rest to a replica.

A replica is not a backup

If a bad delete reaches the primary, replication copies the delete to every replica. Both now hold the same bad state. Backups are the answer to that, not replicas.

What replicas are good for

  • Read-heavy workloads, which is most web apps.
  • A primary that is CPU or IO bound because of read queries.
  • Reports and analytics that should not compete with transactional traffic. A dedicated replica keeps those long queries away from the checkout path.
  • A start toward high availability, since a replica can be promoted if the primary fails, depending on the failover mechanism.

Measuring before adding one

The case for a replica is a measurement, not a feeling. Look at the ratio of reads to writes, at which queries use the most time, and whether the primary is limited by CPU or by disk. If a few slow queries dominate, an index may fix them. If the same expensive reads repeat, a cache may remove them. If the load is genuinely many different reads and the primary is saturated, a replica is the right tool. Having the numbers also tells you how many replicas you need, and how much lag the product can tolerate before users notice.

Monitoring lag

Lag should be a metric with an alert, not a surprise. Track how far behind each replica is, in seconds. If a replica falls too far behind, take it out of rotation until it catches up, and send its reads to the primary or to a healthier replica. A long report query running on a replica can also delay replication on some setups, so check how your database handles that conflict before pointing heavy queries at it.

Where I used it

I haven't shipped this in a public project yet.

IMS runs on one Postgres database by design, with contention to be measured. I have not added replicas, and I have no read-to-write numbers that justify them, so I will not pretend otherwise.

Trade-offs

  • Stale reads. Lag is real, and every read path has to decide whether it can tolerate it.
  • No help for writes. Replicas do nothing for write throughput. A write-heavy bottleneck needs a different answer.
  • More to operate. Each replica needs monitoring, and lag needs an alert.
  • Routing logic. The application, or a proxy, must decide which queries go where. Getting that wrong sends writes to a read-only copy or reads to a stale one.
  • Cost. Each replica is another full copy of the data.
  • A premature step. Indexes and caching are cheaper, so try those first.

A useful rule: add a replica when reads are the measured bottleneck and the staleness is acceptable. Until then, an index or a cache costs less.