Skip to the page

PostgreSQL and MySQL · Scenario

Saved address shows the old value

The interviewer asks

Users update their delivery address, the app says 'Saved', but the next page still shows the old address. A few seconds later it's fine. Reads go to a replica. What's happening, and what do you do?

Then

Follow-ups the interviewer asks next

  1. Why does this happen with replicas?
  2. How do you measure lag on PostgreSQL and on MySQL?
  3. What's the quickest safe fix for this page?
  4. Lag jumps to 5 minutes every night around 1 am. What do you look for?
  5. Would synchronous replication solve it? What does it cost?
  6. What is 'read your own writes', and how do you build it properly?
  7. Have you hit a replica-lag bug?

The answer

What a strong answer covers

  • Replication is asynchronous: the write commits on the primary, and the replica applies it a little later. A read right after the write can hit the replica before it catches up.
  • Measures lag: pg_stat_replication.replay_lag on the primary or now() - pg_last_xact_replay_timestamp() on the replica; SHOW REPLICA STATUS in MySQL.
  • Quick fix: read the user's own data from the primary for a few seconds after they write (a flag in the session), or return the saved data in the write response.
  • Proper fix: route by consistency need in the data-access layer; or wait on the replica until it has applied the write's position (PostgreSQL 19's WAIT FOR LSN, MySQL's WAIT_FOR_EXECUTED_GTID_SET). Balances and payments always read from the primary.
  • Nightly lag: one huge DELETE in a single transaction; delete in small batches with pauses. MySQL: parallel replication workers help the replica keep up.
  • Synchronous replication (synchronous_commit = remote_apply) makes the write visible on the replica before commit returns, but every commit waits for the replica, and a slow replica slows or stops writes.
  • Prevents it: lag alerts, routing rules in one place, a test for "write then read".

The red pen

Common traps

Avoid:"add a sleep"; sending every read to the primary; synchronous replication without counting its cost.

Practise this out loud

Say your answer out loud to an AI interviewer that follows up, and get a score for it.

Practise by voice

Practise questions like this out loud

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview