Replication
Your write landed. Why is the read old?
A successful write and an up-to-date replica are two different things.
Ben Osborn
With asynchronous replication, a primary can confirm a write before a replica has applied it. If the next read goes to that replica, it may return the previous value.
The write succeeded. The copy has not caught up yet.
Follow one update
Imagine changing a display name from Alex to Sam:
- The application writes
Samto the primary. - The primary confirms the write.
- A read reaches a replica before it applies that change.
- The replica still returns
Alex.
What the model tells you
Sending reads to replicas can spread read work across machines. It also makes the timing of replication part of the application's behavior.
For a screen that must show the user's latest change, reading from the primary is one possible approach. Other designs track replication progress before allowing a read. The right choice depends on the database and the application.
What to test
- Write a value, then immediately read it through the application's normal route.
- Repeat under load and measure how long old values remain visible.
- Check which screens actually need to see the latest write immediately.
See PostgreSQL's streaming replication documentation for one implementation of asynchronous replication.