Key takeaways
- ✓A write to a primary in another region costs one round trip: 154 ms at 75 ms each way in the lab, against 0.2 ms for a write to a database in the same region, and the cost was 2 × the one-way delay plus a few milliseconds at every distance tested.
- ✓A transaction of three inserts from Europe to the US primary took 769 ms, because it waits for BEGIN, each insert and COMMIT in turn, which is five round trips of about 150 ms, so across regions one statement beats five.
- ✓Synchronous replication puts the round trip on every commit: a client sitting next to the US primary waited 154 ms per write, against 0.2 ms with asynchronous replication, which confirms first and copies later.
- ✓When the US region was cut off, asynchronous replication lost 10 to 13 bookings the US had already confirmed in each of three runs, and the Europe copy sold 14 to 18 seats a second time, because it did not know those lost bookings had already taken their seats.
- ✓Recovery took 5.4 seconds in the asynchronous runs: about 2.2 seconds to detect three failed health checks, 0.3 seconds to promote the European replica, and the rest waiting for clients to let go of a DNS answer cached for 5 seconds.
- ✓Synchronous replication lost 0 bookings and sold 0 seats twice in all three runs, but it confirmed only 126 to 135 bookings in the 15 seconds before the failure, about 9 a second across both regions, against about 193 a second with asynchronous replication, most likely because each booking held one shared counter row for the 80 ms round trip.
Writing across an ocean was 154 ms a write in the lab, and a three-write transaction took 769 ms. When the US region was switched off, asynchronous replication lost the bookings it had confirmed but not copied, and Europe sold 14 to 18 of the same seats again. This chapter counts the round trips a write pays across regions, then looks at what replication has to wait for, and what a region failure does to the seats.
The examples come from Lab 19 (Multi-Region and Geo-Distribution) of the system design labs: script 01_latency.py for the distance test, and script 02_region_failover.py for the region loss. Read the setup carefully before the numbers. Every region ran as containers on one laptop, an Apple M4 Max with Docker Desktop, 16 virtual CPUs, and Postgres 17. The "regions" are not in different places. The distance between them is a delay that a relay called Toxiproxy adds to each cross-region link, in both directions. The databases are real Postgres, so the writes, commits and failovers are real. The delay is simulated. Each configuration is a single recorded run of the distance test, and three runs of the failover test.
The regions are named by the lab. us is the US region, which holds the primary: the one database that takes writes. eu is Europe, with a replica (a copy that follows the primary). ap is Asia, also with a replica. Throughout this chapter, "Europe" means eu and "the US" means us.
What distance does to a write
Light in fibre covers about 200 km in a millisecond, and no software makes it faster. A write from Europe to a primary in the US has to travel there and come back before the client hears "saved". That is a round trip. The lab measured the cost at four distances, with 200 writes per path, one after another:
| Path | 0 ms | 20 ms | 40 ms | 75 ms |
|---|---|---|---|---|
| Client in Europe, to a database in Europe | 0.15 ms | 0.14 ms | 0.18 ms | 0.15 ms |
| Client in Europe, to the US primary (one write) | 0.29 ms | 43.8 ms | 83.5 ms | 154.1 ms |
Those are medians, the p50 of each run. The delays are the one-way values, so at 75 ms the round trip is 150 ms, and the measured 154 ms is that plus a few milliseconds of overhead. The rule the numbers show is simple: a remote write costs one round trip, and a write in the same region costs almost nothing. At 75 ms, the remote write was about a thousand times slower.
The distance widget below uses these same medians, on one scale, so the local writes are slivers next to the others.
75 ms each way (about New York to Singapore). Median (p50) write latency, 200 writes per path.
Bars share one scale, set by the 769 ms transaction. Toxiproxy adds the delay on one machine; real links add jitter and loss.
Think of a company ledger kept at head office in New York, with a copy at a branch in Frankfurt. A Frankfurt clerk who wants a line changed has to phone New York and wait for the answer, every time. The phone list the branches use to find head office is itself copied out every five seconds. That is the whole problem in one picture.
A transaction pays per statement
A transaction groups several writes so they all happen or none do. The client sends BEGIN, the statements, then COMMIT, and each one waits for its answer before the next is sent. The lab ran a transaction of three inserts from Europe to the US primary:
| Distance (each way) | One write | Transaction of 3 inserts |
|---|---|---|
| 20 ms | 43.8 ms | 217.9 ms |
| 40 ms | 83.5 ms | 419.0 ms |
| 75 ms | 154.1 ms | 768.8 ms |
Counting the messages: BEGIN, three inserts and COMMIT are five statements, so five round trips. At 75 ms each way, five round trips of about 150 ms come to about 750 ms, and the measured 769 ms includes the overhead. Across regions, the number of round trips matters more than how much work the database does. Packing the work into one statement, such as a single insert that also records the seat, or a stored procedure, takes one round trip instead of five.
Synchronous or asynchronous: who waits for the copy
Replication is how the replica gets the primary's writes. There are two ways to wire it, and they differ on when the primary says "yes" to the client.
- Synchronous: the primary does not confirm a write until the replica has it. If the replica is in another region, every write waits a round trip, even for a client sitting next to the primary.
- Asynchronous: the primary confirms first and sends the write to the replica afterwards. The client's wait is local, but anything confirmed and not yet copied exists only in the primary's region.
The lab measured a US client writing to the US primary, with the replica in Europe:
| Replication | At 75 ms each way |
|---|---|
| Synchronous, replica in Europe | 154.4 ms per write |
| Asynchronous | 0.20 ms per write |
The synchronous figure is the same round trip as before, now paid on every commit, even though nothing has failed. The asynchronous figure is the local cost. That gap is the reason people choose asynchronous replication, and the reason it can lose data, which is the next part.
Losing a region
The second test is the one that matters most. The primary is in the US, Europe is 40 ms away, and Asia has a replica too. Clients in the US and in Europe each make 100 bookings a second. Each booking is one statement that adds one to the event's seat counter and records the seat for that user, so the seat number is whatever the counter reaches.
Fifteen seconds into the run, the US region goes dark: every link to it is cut. Three things have to happen before traffic works again:
- Detection. A failover script running in Europe checks the US every 0.5 seconds. After three failed checks in a row, it decides the US is gone. That took about 2.2 seconds.
- Promotion. The script promotes Europe's replica to primary, so it accepts writes. That took about 0.3 seconds.
- Moving traffic. Clients find the primary through DNS, the name service that maps a name to an address. In the lab, DNS is a stand-in: a file that each client reads and caches for 5 seconds. Clients keep the old answer until it expires.
The recovery time, the RTO (recovery time objective: how long the service is down), was 5.4 seconds in every asynchronous run. Half of it was the DNS wait, as the caveats below explain.
What a region loss does to the seats
With asynchronous replication, the new primary in Europe is missing the bookings the US had confirmed but not yet sent across the 40 ms link. The lab counted them against the bookings the US had confirmed:
| Replication | Confirmed by the US, per run | Confirmed but missing in Europe | Seats sold twice |
|---|---|---|---|
| Asynchronous (3 runs) | 2,893 to 2,903 | 10 to 13 | 14 to 18 |
| Synchronous to Europe (3 runs) | 126 to 135 | 0 | 0 |
The loss is small, about 0.1 seconds of US bookings at 98 a second. The cost is larger than the loss. A confirmed booking that the new primary never received is a seat the new primary does not know is taken. Europe's counter hands the same seat number out again, to someone else. So a lost booking becomes a seat sold twice, and the lab saw more double sales than losses, because the old US primary was still alive in the dark region and may have saved a few bookings whose confirmation never got out. That part is the lab's most likely explanation, not something it tested directly.
The lesson is not that rows go missing. It is that two customers can end up holding the same seat.
With synchronous replication, the US primary waited for Europe before it confirmed each booking. Nothing confirmed was lost, and no seat was sold twice. The price came before the failure.
The workflow and the results
The failover test ran three times per replication mode. The table is the lab's recorded results:
| Run | Mode | US bookings/s before the cut | Confirmed by US | Lost | Sold twice | Detected | Promoted | RTO |
|---|---|---|---|---|---|---|---|---|
| 1 | Async | 97.7 | 2,893 | 11 | 18 | 2.2 s | 2.5 s | 5.4 s |
| 2 | Async | 97.9 | 2,903 | 10 | 14 | 2.2 s | 2.5 s | 5.4 s |
| 3 | Async | 97.8 | 2,898 | 13 | 17 | 2.2 s | 2.5 s | 5.4 s |
| 1 | Sync | 3.7 | 126 | 0 | 0 | 2.3 s | 2.6 s | 5.6 s |
| 2 | Sync | 2.7 | 135 | 0 | 0 | 2.3 s | 2.5 s | 5.4 s |
| 3 | Sync | 3.9 | 127 | 0 | 0 | 2.4 s | 2.7 s | 5.7 s |
Two things are worth reading off the table.
Throughput before the failure. Asynchronous confirmed about 2,898 bookings in the 15 seconds before the cut, which is about 193 a second across both regions. Synchronous confirmed 126 to 135, about 9 a second. The lab's explanation: each booking updates the same event counter row, and with synchronous replication that row stays locked for the 80 ms round trip to Europe. Bookings across both regions went through one at a time, so the best case was about 12 a second. Also, 1,432 to 1,451 US bookings timed out waiting for the lock in each sync run. The lab did not profile the database to confirm the lock is the cause, so read it as the most likely cause.
Where the RTO goes. The 5.4 seconds breaks into about 2.2 seconds of detection, 0.3 seconds of promotion, and about 2.9 seconds of clients still holding the old DNS answer. The single-region failover in the earlier Lab 18, with no distance, took 2.3 seconds, so a region adds detection you have to be sure of, and traffic you have to move.
The US primary confirms a booking before Europe has it. When the region goes dark, the confirmed-but-unreplicated bookings are gone from the new primary, and Europe's copy never heard of them, so it can sell the same seats again.
| Run | US bookings/s before | Confirmed by US | Lost | Sold twice | Detected | RTO |
|---|---|---|---|---|---|---|
| 1 | 97.7 | 2,893 | 11 | 18 | 2.2 s | 5.4 s |
| 2 | 97.9 | 2,903 | 10 | 14 | 2.2 s | 5.4 s |
| 3 | 97.8 | 2,898 | 13 | 17 | 2.2 s | 5.4 s |
Confirmed per second = confirmed bookings in the 15 s before the cut, averaged over the three runs (async about 193, sync about 9 for both regions together). One machine, Toxiproxy delay, not a real ocean.
Caveats
- The distance is simulated, on one machine. All three regions were containers on one laptop, joined by Toxiproxy delay. The results describe what that delay does to real Postgres. They do not include the jitter, packet loss or bandwidth limits of a real link, which all make cross-region writes slower and less predictable.
- The DNS share depends on the harness. In these runs the clients re-checked DNS just after the cut, before the promotion, so they kept the old answer for the full 5 seconds. The 2.9 seconds is that phase, not a law. In real life, the wait after promotion can be anywhere from zero to five seconds, depending on when the client last looked.
- One kind of failure. The lab cut every link to the US, which is a clean failure. It did not test a region that is slow, partly reachable, or flapping, and it did not test what happens when the old primary comes back and has writes the new one lacks.
- Failover to one replica. Only the European replica was promoted, by a script with a fixed rule of three failed checks. There was no quorum (a vote among regions) and no test of two regions disagreeing about who is primary.
- Small runs. Three failover runs per mode and one distance run are enough to show the pattern. They are not enough for tail statistics across many failures.
- Not tested here: writes in every region at once (the next chapters cover that with last-write-wins and CRDTs), routing by location, data residency rules, and the lab's suggested fix of a shorter DNS cache lifetime (TTL, time to live), which the lab lists as an exercise.
The checklist
- Count the round trips. A write across regions costs one round trip, and a transaction costs one per statement. Send one statement where you can.
- Know what asynchronous replication loses. Everything confirmed but not yet copied is at risk. Decide whether losing it is acceptable, and what the system does with the seats, orders or balances it touched.
- Keep synchronous replication off hot rows. A round trip paid while holding a shared counter row turns into a queue. Split the row, or do not hold it across the round trip.
- Budget the failover. Detection, promotion and DNS caching all add to the recovery time. Measure each one separately.
Quiz
1.A client in Europe writes one row to a primary database in the US, 75 ms each way. Roughly how long does the write take, and why?
2.Asynchronous replication lost 10 to 13 confirmed bookings, but 14 to 18 seats were sold twice. Why more double sales than losses?
3.With synchronous replication, the lab confirmed about 9 bookings a second across both regions, against about 193 with asynchronous replication. What is the most likely cause?
Check your understanding
Try each question before opening its answer.
A write from Europe to the US primary costs 154 ms at 75 ms each way, but a write to a database in Europe costs 0.2 ms. What is the 154 ms made of?
One round trip across the link: 75 ms out and 75 ms back, which is 150 ms, plus a few milliseconds of overhead. The local write never leaves the region, so it pays almost nothing for distance.
Why did the three-insert transaction take about five times as long as one write?
Because it was five statements, each waiting for its answer before the next was sent: BEGIN, three inserts and COMMIT. Five round trips of about 150 ms come to about 750 ms, and the measured 769 ms includes overhead. Sending the work as one statement takes one round trip.
Asynchronous replication lost 10 to 13 bookings in each run. Why did 14 to 18 seats end up sold twice?
Because the European copy never received the lost bookings, so it did not know those seats were taken, and it handed them out again. The old US primary, still alive in the dark region, may also have saved a few bookings whose confirmation never reached a client. That second part is the lab's likely explanation, not something it tested directly.
With synchronous replication, why did the sites confirm only about 9 bookings a second, when the failover itself lost nothing?
Because every booking updated one shared counter row, and with synchronous replication the row stayed locked for the 80 ms round trip to Europe. Bookings in both regions went through that row one at a time, so the best case was about 12 a second. Nothing was lost, but the business nearly stopped before the failure.
The RTO was 5.4 seconds. How much of it was waiting for DNS, and why does that number change in real life?
About 2.9 seconds. Detection took about 2.2 seconds and promotion about 0.3 seconds. The remaining wait was clients holding a DNS answer cached for 5 seconds. In these runs the clients had re-checked just before the promotion, so they waited the full cache time. In real life, the wait depends on when each client last looked, and it can be anywhere from zero to five seconds.
Next up: Chapter 47, last-write-wins vs CRDTs: this chapter kept one primary, and every region still had a single place that took writes. The next one lets every region write at once, and asks what happens to a like count, a shopping cart and a shared document when two regions change the same thing.