We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
This idea carries a full system design question on its own. Each walks through the full answer.
System Design Masterclass · Data Replication Distribution
Free preview: the first 2 parts of this 8-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Data Replication Distribution
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
It is easy and good
“It is really nice and good Please join the course”
When MySQL, Postgres, or MongoDB replicates data, the first design decision is: does the primary wait for replicas before confirming the write?
If it waits, the write is slower but safer. If it doesn't wait, the write is fast but there's a window where the data exists on only one machine. If that machine dies during that window, the data is gone.
Asynchronous is the "don't wait" approach, and it's the default mode for almost every database. MySQL defaults to async replication. Postgres streaming replication defaults to async. MongoDB replica sets default to async. The reason is simple: it's fast.
Amazon Aurora, which powers a huge chunk of AWS's RDS workloads, uses a form of async replication internally. Shopify's entire database fleet runs async replication across their 900+ MySQL shards. For the vast majority of workloads, the speed benefit is worth the tiny risk.
But that tiny risk isn't zero. In 2020, a financial services company lost 30 seconds of transaction data during a primary failure because their async replicas hadn't caught up yet. Those 30 seconds contained hundreds of stock trades that had to be manually reconciled from exchange logs. "Async is fine for most things" doesn't mean "async is fine for everything."
The mechanics are straightforward:
The key point is step 3. The client gets "success" before any replica has seen the data. The happens asynchronously, hence the name.
This means there's always a window, however small, where:
Under normal conditions, this window is measured in milliseconds. Replicas are usually less than 100ms behind. But under heavy write load, network issues, or replica maintenance, the window can grow to seconds or minutes.
The fundamental guarantee: Your write is durable on the primary's disk. It is NOT guaranteed to be on any replica. If the primary's disk is destroyed (rare but possible), unreplicated writes are lost.