Interview: “I changed my name, refresh shows the old one”

Reads hit a lagging replica. Binlog, relay log and applier, why redo and binlog both exist, what semi-sync really promises, and read-your-writes with GTIDs.

More on Ticket interviews

Keep learning

Overview

Always read the replica Primary for 5 s after a write Wait for the write’s GTID Read routing Primary and replica timelines COMMIT name=“Asha” → binlog Lag is shorter than the refresh, so it looks fine. Raise the lag and it breaks. The GTID is already applied. No wait.

“I changed my name, refresh shows the old one”

replica lag After saving, a refresh shows the old name. The read hits a replica that has not applied the write. Route the writer's next reads so they see their own write.

Profile changes “don’t save”

Users save a new name. The reload shows the old one. A few seconds later, the new name appears. Worse at 9 am, when the nightly report runs on the replica. reads to replicas replica lag p99 Restated: the save works, but the next read hits a replica that has not caught up.

Where do reads and writes go?

SHOW REPLICA STATUS The replica has received 733 transactions it has not applied yet. transactions received transactions applied waiting to apply The network is fine. The applier is behind.

From symptom to mechanism

Did the write fail? query the primary No. The primary has the new name at once. Where does the follow-up read go? read db.ts To the replica. Even the read right after a write. How far behind is the replica? SHOW REPLICA STATUS 733 transactions received but not applied. The applier is the bottleneck. Why worse at 9 am? check jobs on the replica The nightly report steals CPU and I/O from the applier.

Read-your-writes, scoped

Fixes staleness only where users notice: their own writes. Bounded: waits at most 200 ms, then falls back to the primary. Measures lag with GTIDs, not the unreliable Seconds_Behind_Source. on primary Keep GTID in session, 10 s Replica waits ≤ 200 ms for GTID Fresh read replica, or primary on timeout

No AI from here

What exactly travels from the primary to a replica? The binlog (binary log): an ordered log of committed changes. In row format it carries before/after row images, not SQL text. A receiver thread copies it into the relay log. Applier threads replay it. Lag usually comes from the applier: big transactions, DDL, or a busy replica. binlog vs relay log receiver vs applier relay log replica receiver usual bottleneck The primary has a redo log and a binlog. Why both? Redo holds physical page changes in a circular file. Binlog holds logical transactions, also used for point-in-time recovery. An internal two-phase commit keeps them in sync. No binlog entry means not committed. two logs, two purposes internal 2PC redo log MySQL server page changes Crash recovery Would semi-synchronous replication fix this ticket? No. Semi-sync waits until a replica received the write, not applied it. So reads can still be stale. It helps failover: a commit exists on a second machine. Cost: every commit pays one network round trip. received ≠ applied durability vs freshness waits for ack write relay log ack sent OK to client apply… later reads still stale The primary dies. What can you lose with async replication? Anything committed on the primary but not yet received by the new primary. Users were told “saved”, and it is gone. That window is the RPO (how much data you may lose). Semi-sync shrinks it. GTIDs show exactly which transactions each replica has. Why is Seconds_Behind_Source misleading? It compares event timestamps, so it can say 0 while far behind. One 10-minute transaction shows 0, then jumps to 600. Better: compare GTID sets, or read a heartbeat row written every second. heartbeat table GTID comparison Timestamp guess. Reads 0, then jumps. Heartbeat / GTID Direct measure of what is applied.

Product asks: “make every read fresh”

How do you respond? Send all reads to the primary Fresh everywhere, but the primary carries every read. You lose read scale when it matters most. Primary load Read-your-writes with GTID wait Users always see their own changes. Others’ changes may be a moment late, which nobody notices. Switch to semi-sync replication Safer failover, but reads stay stale. Every commit gets one round trip slower. Return the saved object from the write path Cheapest fix for this page. The next page load may still read a stale replica.

Have one ready

Tell me about a consistency bug caused by replication. What users saw, how often. Read-your-writes, routing, or GTID wait. Lag alert plus a read-after-write test.

Did you show these?

Confirmed the write succeeded Found the read routed to a replica Explained binlog → relay log → applier Knew why redo log and binlog both exist Scoped the fix to read-your-writes Named the failover loss window (RPO)

More courses

  • Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
  • Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
  • React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
  • System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
  • NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
  • Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
  • Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
  • AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
  • Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
  • TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
  • CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
  • Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
  • Docker — What an image is, why layers cache, and how containers find each other on a network.
  • Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
  • Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
  • AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
  • Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.