Users see stale data right after saving because reads go to a replica with lag. How do you handle it?
IntermediateScenarioData and databases
Answer
Situation read → Asynchronous replicas are always slightly behind. The fix is choosing which reads need to be fresh, and making sure lag stays low.
What I'd do →
- Measure lag:
ReplicaLagin CloudWatch (RDS) orAuroraReplicaLag, and alert on it. - Find why it's high: big batch writes, long queries on the replica blocking replay, or an undersized replica.
- Route "read-your-own-writes" reads to the primary: for example, for a few seconds after a user writes, or for the specific pages that show what was just saved.
- Keep the replica for reporting, search and lists where a few seconds of staleness is fine.
- On Aurora, replicas share storage, so lag is usually milliseconds, which may remove the problem.
Why → Not every read needs to be consistent; send only the ones that do to the primary.
Interview tip → Use the phrase "read-your-own-writes"; it names the exact consistency issue.
More on Data and databases
A release needs to rename a column that the running app reads and writes. How do you do it with zero downtime?IntermediateHow do you prove your database backups actually work?IntermediateDesign backups for an RDS PostgreSQL database with RPO of 5 minutes and RTO of 1 hour, including a region failure.AdvancedYour migrations run in an init container and two pods ran them at the same time during a deploy, leaving the schema half-applied. How do you fix the approach?IntermediateUpgrade RDS PostgreSQL from 13 to 17 with minimal downtime. How?AdvancedYou need to add an index and a column to a 500-million-row table that's written to constantly. How do you avoid locking it?Advanced