Skip to content
Prompt Words
History

Read replica

Also called: replica, read-only replica, secondary, follower.

A read-only copy of a database that the primary keeps updated, usually asynchronously. You send heavy reads such as listings and reports to it, so the primary has room for writes. Because copying takes time, a replica can be a little behind the primary (replica lag).

Writes go to the primary; the replicas copy each change 2 s later (slow on purpose). A read in that gap gets old data.

Writes: 0 · Reads: 0 (0 stale) · Replicas are up to date

The primary and both replicas have price $10.

    Writes 0 reads 0 stale 0

    Say it in a prompt

    Add a Postgres read replica and route read-only queries (search, product listings, admin reports) to it through a second connection pool. Keep all writes on the primary. For read-your-writes, send a user's reads to the primary for 10 seconds after they write, so the page that loads right after saving shows the change. Alert when replica lag goes over 5 seconds.

    Vague vs precise prompt

    Vague prompt

    the database is slow, make it handle more traffic

    Typical resultSuggests a bigger database server or adds indexes here and there. Reads and writes still compete on one machine.

    Precise prompt

    Add a Postgres read replica. Send read-only queries (search, listings, admin reports) to it through a separate pool. Keep writes on the primary, and for 10s after a user writes, send that user's reads to the primary too (read-your-writes). Alert if replica lag passes 5s.

    Typical resultReports and listings move off the primary, writes get its full capacity, and a user who just saved still sees their change because that read goes to the primary.

    Seen on

    • Amazon RDS: A read replica is a read-only copy of a DB instance. RDS copies the primary's updates to it asynchronously, and you route read queries to it to take load off the primary.
    • A reporting dashboard runs its slow queries against a replica, so checkout writes on the primary stay fast.

    You might describe it as

    • a second copy of the database just for reading
    • send the heavy report queries somewhere else
    • database that follows the main one

    Not to be confused with

    • Sharding

      A read replica is a full copy of the data that only serves reads; sharding splits the data so each database holds a different part, which spreads writes too.

    • Database index

      A read replica adds a copy of the database so more reads can run at once; an index helps one database find rows faster.