Try
↑ ↓ move↵ openesc close

Interview prep / Replication and lag

Senior · Replication and lag · System design interview question

Your product has users in Europe and North America, and the single leader is in the US. European users complain that saving anything takes 300 ms. What are your options, and what does each cost?

Sketch your own answer first, then compare it with the one below.

A strong answer

The 300 ms is the round trip to the leader, which replication cannot remove. Writes must reach the leader, and a synchronous follower in Europe would add its round trip too. So the options are about moving the leader or allowing more than one.

Option one: keep one leader and add European read replicas. Reads become fast, writes stay slow. This often fixes the complaint if reads dominate. Add read-your-writes routing so a user who has just saved is sent to the leader or to a replica that has applied their write.

Option two: partition by user home region. Each user's data has its leader in their own region, so most writes are local. Cross-region operations, such as European users interacting with US data, still pay the trip. Moving a user between regions needs a migration.

Option three: a leader in each region, replicating to each other asynchronously. Writes are fast everywhere. The price is write conflicts when two regions edit the same item, which need a resolution rule, and a harder operational story.

Before the heavy options, check where the time goes. Part of 300 ms may be connection setup, TLS handshakes or several sequential round trips per save, which batching or a regional gateway can cut.

I would start with replicas plus region-homed data for what is naturally per user, and leave multi-leader for data that really is edited from both sides.

Sources

Learn it by running it

The replication and lag lesson explains the mechanism behind this question, and its lab lets you change the parameters and watch the effect.

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms