Interview: EU users wait on the ocean for every write, can both regions take writes?

Single leader vs multi-leader vs leaderless across regions. Link cut and heal, last write wins and clock skew, version vectors, CRDT merges, and why hard…

More on Ticket interviews

Keep learning

Overview

Single leader Home region per user pick for Money, stock, usernames. Writes mostly from one region. Mergeable data: profiles, notes, offline-first apps. Always-on key-value data, like carts and sessions. Each user edits only their own data. What is a write conflict, and why can a single leader never have one? explain simply Two writes to one record where neither writer knew about the other. One leader puts every write in one order. The later write sees the earlier one. Two leaders each accept a write and tell the other later. Both think they were first. “Concurrent” means unaware of each other, not same moment. Hours apart offline still counts. one order vs no order async replication is the cause EU leader US leader accepted locally receives 'B' neither saw the other receives 'A' We resolve conflicts with last write wins, using the server clock. What breaks? what breaks if Writes vanish silently. Last write wins keeps the biggest timestamp and drops the rest. Clocks differ between machines. A truly later write can get a smaller stamp and lose. Example: 42.003 loses to 42.004 with under 3 ms of clock skew (drift). Safe only for insert-only unique keys. For updates, use version vectors or a merge. silent data loss clock skew reorders cause and effect A checkout does 3 writes in a row. What does a far region really pay? About 450 ms with one far leader, versus about 15 ms locally. Cheaper first: run checkout near the leader, or send all 3 writes in one call. Multi-leader hides the delay, but you pay in conflicts and weaker checks. counts round trips tries cheaper fixes first 3 writes × far trip 3 writes batched, 1 trip 3 local writes Usernames must be unique and balances must not go negative. How, with two leaders? what would you do instead You cannot promise it. Each leader accepts a write that only breaks the rule combined. Option 1: send those rare writes to one region. The trip is fine for signups. Option 2: loosen the rule and repair later, like rebooking an overbooked passenger. Option 3: a store that agrees across regions on every write, and pays the delay. hard rules need one decider splits data by need knows compensation exists Route to one leader Rare writes pay the trip. Repair afterwards Allow it, then compensate. Consensus store Always correct, always slow. How does the database know two writes were concurrent, not one after the other? A version vector: one counter per replica, carried with each write. If every number in A ≤ the same number in B, B knew A. B replaces A. If each is higher somewhere, they are concurrent. Keep both as siblings and merge. A bare timestamp cannot tell these cases apart. one counter per replica overwrite vs siblings timestamps are not enough Staff: which data can merge by itself, and which can never be fixed by a merge? Counters: each replica adds to its own slot. Take the max per slot, then sum. Carts and lists must track deletes. Text needs a CRDT (merge-safe data type) or OT. Rules across records, like “no overlapping bookings,” can break even after correct merges. picks a merge per data type delete tracking rules need one decider Why it is slow Every EU write crosses to the one US leader. Cheap fixes first Move code near the leader, batch writes, add EU read replicas. Price of two leaders Split by data Profiles and carts: home region. Payments: one leader. Prove it Cut the link in a test, edit both sides, check after healing. Multi-leader only for speed Try a closer app, batching or read replicas first. Last write wins as default Forgetting quiet features Auto-increment, triggers and constraints act oddly with many leaders. Assuming in-order arrival An update can arrive before its insert. Version vectors help. Multi-leader price: conflicts, no hard rules Last write wins loses data silently Home region per user, and its weak spot Node 1 writes x=1 with timestamp 42.004. Node 3 then increments x to 2 with timestamp 42.003, because its clock is slightly behind. Node 2 keeps x=1 and drops the increment. Node 1 clock Node 3 clock built on it The second write is later in cause and effect, but its stamp is smaller. EU sets the title to A EU edits again, after seeing W1 US edits, after seeing W1 but not W2 Every number on the left is at most the right. The right one knew about the left one, so it replaces it. Every number on the right is at most the left. The left one knew about the right one, so it replaces it. Each side is higher somewhere. Neither knew about the other. These are concurrent: keep both and merge. Version vector comparison Pick two writes the two writes and their version vectors EU adds 1 → [1, 0, 0] Asia adds 1 → [0, 0, 1] Each node only changes its own slot, so the merge never double-counts and never drops an add. One leader in the US A leader in each region EU write waits for the trip to the US, ≈ 150 ms (illustrative). EU cannot write or read fresh data. US carries on. Nothing to merge. There was only one order of writes. Unique names and balances can be enforced. EU writes locally, ≈ 5 ms. The copy to the US happens later. Both regions keep taking writes. Changes queue up. Not guaranteed. Two leaders can each accept a “fine” write. Fast if the quorum stays in the EU. A quorum across regions waits for the far replicas. A local quorum still works. Reads can be stale. Read repair and background sync copy values. Concurrent writes become siblings or last-write-wins. Not guaranteed. Even quorums are not single-copy behaviour. Two regions, one link. Pick a design, then cut the link. Replication design Inter-region link link up link cut EU REGION US REGION EU write cannot reach the leader every EU write crosses the ocean each write stays in its own region copies, sent later a write that stays local a write that crosses the ocean copying changes to the other region blocked by the cut EU write speed See the next box. While the link is cut After it heals Hard rules What to notice. Speed and “keeps working in a cut” go up when you add leaders. The price is on the right: conflicts, and no hard rules. The EU stamp is bigger, so the EU cart wins. The US customer removed DVD, and that was thrown away. No error was shown. The US stamp is bigger, so the US cart wins. The EU customer removed Book, and that was thrown away. No error was shown. Keeping every item from both carts brings both removed items back. This is the shopping-cart surprise: both removed items come back. The merge remembers that Book and DVD were deleted, so both removals survive. This is what a CRDT-style merge does. Cart is Book, DVD, Soap. At the same moment, EU removes Book and US removes DVD. How to settle the conflict last write wins keep both, then union merge that tracks deletes Whose clock is ahead EU clock ahead US clock ahead in cart ✕ removed here ✓ yes after both regions sync, the cart is after sync ✕ removed ⚠ came back ✓ in cart What to notice. The first two options are easy to build and both lose a customer action. The third needs a data type designed for merging. Left: one master notebook in the US head office, and the EU branch phones every time. Right: each branch has its own notebook and they swap notes at night. ONE MASTER NOTEBOOK EU branch US head phone call, every time slow, and dead if the line is down A NOTEBOOK IN EACH BRANCH EU notebook US notebook swap notes at night fast, but both may edit the same line

EU users wait on the ocean for every write. Can both regions take writes?

One US leader makes every EU write cross the ocean. Two leaders are faster, but can clash. single leader last write wins version vectors EU users wait about 150 ms on every write. The only leader is in the US.

Two branch offices, one notebook each

One notebook in the US office EU phones in A notebook per branch swap notes at night Same line edited twice who is right? Leaders are notebooks. Swapping notes is replication.

EU checkout writes feel slow. Let both regions accept writes.

Our only write leader is in the US. Every EU write travels there and back. Can the EU take writes too? Data: profiles, carts, payments. EU write US write

Four ways to take writes in more than one region

Fast local writes Works when link is cut No conflicts Hard rules hold Profiles, carts and payments. EU is slow. What do you do? Multi-leader for everything, last write wins Fast, but same-record edits erase each other silently. Balances cannot be protected. EU write speed No lost writes Keep one leader, add EU read replicas Home region per user for profile and cart (with merge rules). Payments stay on one leader. Owner writes are local and cannot collide. Only rare payments pay the trip.

Say these out loud first

Related chapters: replication log, quorum, split brain, version conflict.

A model answer

EU users find writes slow. Should we go multi-leader?

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.