liveBook · Manning

Read replica

As explained in PostgreSQL Mistakes and How to Avoid Them

A read replica is a database server that receives replicated data and serves read operations rather than accepting the authoritative writes.

A read replica is a PostgreSQL standby that receives replicated data and serves reads while the primary accepts writes. It can scale read traffic, but replication lag makes its view of the database temporarily stale. section 5.6

The stale-balance mistake

Suppose alpha is the primary and beta is a read replica configured with a 60-second apply delay. Beta reports an account balance of 100; alpha then changes it to 90. A later read from beta still returns 100, so application logic applies a +50 bonus and writes 150 to alpha. The result is an incorrect business decision, not a PostgreSQL ACID violation: the application attempted atomic work across two database nodes. section 5.6

How PostgreSQL Mistakes and How to Avoid Them covers it

How deep it goes
Explains replication lag, stale reads, recovery conflicts, and distributed transaction consequences without detailing replication internals.
Examples
Demonstrates account-balance reads and writes across a delayed standby and primary, plus a query canceled by recovery.
What it assumes
Assumes PostgreSQL replication, read-only standbys, SQL updates, and ACID transactions.
What you can do after
Diagnose stale-read failures and recognize when application logic requires coordinated transactions across database nodes.
How it connects
Connects read replicas with streaming replication, replication lag, ACID consistency, distributed transactions, and two-phase commit.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of PostgreSQL Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.