A user updates their profile, refreshes, and sees the old data. Reads go to async read replicas. What is happening?
Options
- A cache stampede that happens on the key of the profile
- Replication lag; send that user's reads to the primary for a while (Correct option)
- A deadlock between two updates of the profile of the user
- Corruption in the index of the table that stores the users
Answer
Replication lag; fix with read-your-writes (route the user's reads to the primary briefly)
Why
With asynchronous replication, the primary database confirms the write immediately and sends it to the replicas a moment later.
If the next read hits a replica that has not received the change yet, the user sees old data. This delay is replication lag (eventual consistency).
Fix: after a user writes, send that user's reads to the primary for a short time.
Remember
Async replicas can be slightly behind the primary.