Chapter 21 / 24 · System Design

Multi-region and disaster recovery

What an hour without Dabba costs, what a second region costs, why cities make active-active practical, and the drills that show whether failover works.

This chapter lets you decide whether Dabba should run in more than one region, choose between the main ways of doing it, and estimate what each costs in money, complexity and lost orders. The honest answer for many systems is “not yet”, and the chapter should leave you able to defend that answer as well as the opposite one.

Dabba today runs in one cloud region, in Mumbai, spread across three availability zones (separate data centres a few kilometres apart, with independent power and networking). A board member asks a reasonable question after reading about a cloud outage: “What happens to Dabba if the Mumbai region goes down at dinner?” The truthful answer is that Dabba stops, everywhere, until the region returns. Whether that is acceptable is a business question with an engineering price attached. Our job is to make the price clear.

Put a number on an hour without Dabba

Start with what an outage costs. The brief from the first chapter gives about a million orders a day, 15% of them in the dinner hour: about 150,000 orders, 42 a second. With an assumed average order of ₹400, that is about ₹6 crore of orders in the hour, of which Dabba’s commission might be a fifth: about ₹1.2 crore of revenue, plus the harder-to-price loss of restaurants and riders who had a bad evening and customers who installed a competitor.

Now the likelihood. Losing a single zone is a routine event over a year; losing a whole region for hours is rare, with major providers having a handful of notable regional incidents across all their regions per year. Suppose Dabba should expect one multi-hour regional outage every few years. A second region costs, at minimum, a standing copy of the data and the capacity to take over, and in practice a large share of the engineering team’s attention for a year to build and then a steady tax to keep working. Spread over years, the expected loss from regional outages may be smaller than the cost of preventing them.

That arithmetic changes with scale and with promises. If Dabba grows to 50 cities and three million orders a day, the hour costs three times as much. A contract with a large restaurant chain or a corporate meals customer may include an availability commitment. A regulator may ask for a tested disaster-recovery plan. And reputation does not scale linearly: one long outage on the evening of a cricket final is remembered for longer than its revenue suggests. The decision should be revisited when any of these change, not made once.

Before any of that, there is a cheaper step that covers the common case. Running every tier across three zones, with databases replicating synchronously between zones and capacity to lose one zone without autoscaling, survives the failures that actually happen most years. Many teams who believe they need two regions have not yet finished doing this well in one.

Two numbers per kind of data

Disaster recovery is specified with two numbers. The recovery point objective (RPO) is how much recent data we can afford to lose, measured in time: an RPO of 5 seconds means anything written in the 5 seconds before the disaster may be gone. The recovery time objective (RTO) is how long until service is back. Both have a price, and the price falls steeply as the numbers relax. The useful move is to set them separately for each kind of data, because Dabba’s data is not equally precious.

DataIf lostReasonable RPORecovery approach
Orders and paymentscustomers charged for food that never comessecondscontinuous replication; reconcile the gap with the provider
Rider payouts ledgerriders paid wronglysecondsreplicated; rebuildable from orders and bank records
Menus and restaurantsrecent menu edits lostminutesreplicated; restaurants re-edit
Rider live locationsnothing lastingnot applicablerebuilt from the next pings in 5 seconds
Dish photosbroken imageshoursobject storage replicated across regions
Analytics eventsgaps in dashboardshoursreplay from the source of truth

This table already reduces the problem. Of the 10,000 rider location writes a second, none need to cross a region at all; the new region rebuilds its geo index from pings within seconds of riders being routed to it. The part that needs care is small in volume (tens of order and payment writes a second) and large in consequence.

The map is drawn by data residency

Before choosing a design, check where the data may live. India’s rules here come from more than one place. The Reserve Bank of India’s 2018 directive on storage of payment system data requires payment system operators to store that data only in India, and payment providers typically pass matching obligations to merchants in their contracts. The Digital Personal Data Protection Act allows transfers of personal data abroad except to countries the government restricts, but sector regulators can be stricter, and enterprise customers often require Indian hosting in their contracts. The legal detail belongs to counsel. The design consequence is simple: Dabba’s second region should also be in India.

That is convenient. Cloud providers offer more than one Indian region (AWS has Mumbai and Hyderabad, Google Cloud has Mumbai and Delhi, Azure has several), and the regions are close. Mumbai to Hyderabad is a few hundred kilometres; a round trip between regions is on the order of 15 to 25 ms, compared with 100 ms or more between continents. At that distance some choices that are impractical elsewhere, such as waiting for a remote copy before confirming a payment write, cost tens of milliseconds rather than hundreds.

Active-passive: a standby you have to keep honest

In active-passive, Mumbai serves all traffic and Hyderabad holds a continuously updated replica of the databases, plus enough infrastructure to take over. Replication is asynchronous, so writes are confirmed to customers as soon as Mumbai has them. Failover means: decide that Mumbai is gone, promote the Hyderabad replicas to primaries, start or scale up the services there, and point traffic at them.

Predict first

Dabba runs active-passive with asynchronous replication. At the dinner peak, replication lag to Hyderabad averages about 2 seconds. Mumbai becomes unreachable at 20:15:00. Roughly how many orders are affected, and what state are they in?

Show the worked answer

At about 42 orders a second, the last 2 seconds hold around 85 orders that Mumbai confirmed and Hyderabad never received. Some of those customers saw “order placed” and were charged by the payment provider; some restaurants received the order on their tablets and started cooking. In Hyderabad, after failover, those orders do not exist.

The design must be able to find and repair them. The payment provider still has the captured payments with Dabba’s order references, so a reconciliation job after failover lists captures with no matching order and either recreates the order (if the restaurant has it) or refunds it. This is one reason earlier chapters insisted on idempotency keys and references that live outside Dabba: they make the lost tail recoverable. Lag also rises under load, so the RPO is worst exactly at peak, which is when to measure it.

The RTO of active-passive is the sum of steps people tend to underestimate: noticing the outage and deciding it is regional rather than a blip (a few minutes, and the decision is usually made by a person), promoting databases (a minute or two), scaling up services if the standby was kept small (several minutes, if the cloud’s control plane is healthy), moving traffic (DNS changes take effect as resolvers’ caches expire, so a 60-second TTL means a few minutes in practice), and warming cold caches while traffic arrives. Fifteen to thirty minutes is a realistic first target; under five requires most of this to be automated and rehearsed.

The standby’s main weakness is that it serves no traffic, so nothing tells you when it has stopped working. Configuration drifts: a new service is deployed to Mumbai and nobody adds it to Hyderabad. A secret is rotated in one region’s secret manager only. The standby was sized for last year’s traffic. Each of these is found on the day of the disaster unless it is found earlier on purpose.

Active-active, and why Dabba can home cities

In active-active, both regions serve traffic. The difficulty is writes. If a customer’s order can be modified in both regions at once, the two regions must either coordinate on every write (paying the inter-region round trip each time) or accept conflicting writes and merge them later, which for orders and payments is not acceptable. Most systems that call themselves active-active avoid the problem by giving every piece of data one home region at a time.

Dabba has an unusually clean way to do this, because almost everything it does is local to a city. A Bengaluru order involves a Bengaluru customer address, a Bengaluru restaurant and a Bengaluru rider. So each city is homed in one region, and the region holds what the city writes: the logical order shards for that city’s restaurants, and its riders in the region’s rider store. Everything is replicated asynchronously to the other region. A thin routing layer maps each request to a city (by the delivery address, the restaurant or the rider’s registered city) and sends it to that city’s home.

Notice that the city is not the shard key. The sharding chapter rejected city as a key, because Bengaluru alone would overload one database at a cricket-final peak, and chose a hash of restaurant_id over 8,192 logical shards. City homing is a placement layer above that key: it decides which region a logical shard lives in, while the hash still decides which logical shard a restaurant’s orders live in, and Bengaluru still spreads over many databases inside its region. The two nest because a restaurant belongs to exactly one city. They nest cleanly only if each logical shard holds restaurants of a single city, which a plain hash over all 8,192 does not give; the fix is to give each city a block of logical shards in proportion to its size and hash a restaurant within its city’s block. Since every order id carries its logical shard in 13 bits, this is a choice to make before ids are issued, not after: moving a restaurant to a different logical shard later would leave its old order ids pointing at the wrong place.

city routerdelivery address → city → homeregion A · Mumbaihomes (writes)MumbaiPuneDelhi NCRJaipurAhmedabadreplicas of region B citiesBengaluru · Hyderabad · Chennai · …region B · Hyderabadhomes (writes)BengaluruHyderabadChennaiKolkataKochireplicas of region A citiesMumbai · Pune · Delhi NCR · …failover = re-home a city: fence the old home, promote its replica, flip one router entry
Fig · Each city is written in exactly one region and replicated to the other. Moving a city is the unit of failover

A small amount of data is not city-shaped: customer accounts, saved addresses, payment method references, and the customer who orders in Mumbai on Monday and Pune on Friday. The customer_orders table, sharded by customer id, is derived from the order shards, so each region can rebuild its copy from the order events of both. The rest are global but small and rarely written. They can be homed in one region and read from replicas everywhere, accepting that a profile edit in the non-home region takes one inter-region round trip.

When a region fails, its cities are re-homed to the survivor: fence the old home so it cannot accept writes if it comes back confused, promote the replicas of those cities, and update the routing entries. The orders lost in replication lag are the same tail as in active-passive, and are repaired the same way. What active-active buys is that the surviving region was already running hot, with warm caches, current configuration and proven deployment. It is not a standby that might not work; it is production.

The step that needs the most care is “fence the old home”. Imagine Mumbai is not dead but cut off: its servers run, but the rest of the world cannot reach them reliably. Hyderabad takes over Jaipur and starts accepting Jaipur orders. Some Jaipur riders’ apps, on networks that can still reach Mumbai, keep talking to it, and Mumbai keeps accepting their updates. Now two regions both believe they own Jaipur, and the same order can be assigned to two riders, one in each region’s database. Dabba prevents this with an epoch number per city, stored in a small, strongly consistent configuration store. Re-homing a city increments its epoch, and each region’s database writes for that city carry the epoch they were made under; a region holding a stale epoch refuses Jaipur writes until it learns the new one. The city-to-region map itself is small enough to be held in every region and at the edge, so the router does not become a new single point of failure in the region it is meant to route around.

The price is capacity and complexity. Each region must be able to carry every city if the other fails, so in normal operation each runs at no more than about half its capacity, roughly doubling the compute bill relative to one region. Every service must be city-aware in its routing. Cross-city features (a corporate account spanning cities, nationwide leaderboards) need explicit design. And deployments now go to two regions, which the next chapter turns into an advantage: one region becomes a natural canary for the other.

PostureRPORTORunning costFits Dabba when
One region, three zones, tested backupsminutes (backups) to seconds (zone replicas)hours for a regional loss1×10 cities, no external availability promises
Pilot light (data replicated, little running)seconds30–60 min~1.2×a regulator or contract asks for a DR plan
Warm standby (scaled-down copy running)seconds10–30 min~1.5×an hour of outage clearly costs more than the standby
Active-active, homed by citysecondsminutes~2×, plus engineering50 cities, peak hours worth crores, a team to run it

A failover nobody has run is a hypothesis

The value of any of these designs depends on whether failover works on the day, and the only evidence is having done it. Here is what Dabba’s first drill, moving the single city of Jaipur from Mumbai to Hyderabad at 04:00 on a Tuesday, actually found.

The database promotion worked in 90 seconds. Then the Jaipur riders’ apps kept sending locations to Mumbai for eleven minutes: the app cached the resolved IP address of the API host and ignored the DNS TTL. The payment provider’s webhooks kept going to a hostname that pointed only at Mumbai, so payments captured in Hyderabad were not confirmed until someone updated the provider’s dashboard by hand. The secret manager holding the SMS key had never been replicated, so OTP logins failed in Hyderabad. And the runbook step “scale up the assignment workers” called the cloud’s autoscaling API in Mumbai, which, in a real regional outage, would not have answered.

None of these were exotic. Each was a dependency on the failed region hidden inside the recovery path. The fixes followed a principle that the Amazon Builders’ Library calls static stability: the surviving region should be able to carry the load without making any changes through the control plane during the event. That means the capacity is already running, the secrets are already present, the webhook hostname already routes to both regions, and the apps reconnect through a global endpoint that does not depend on client DNS behaviour.

After the fixes, the drill became routine: one small city a month, then a large city a quarter, always at low traffic and always timed. The measured RTO becomes the number reported to the board, replacing the one in the design document. Moving the city back (the fail-back) is drilled too; it is often riskier, because the returning region has cold caches and has to catch up on replication before it can take writes.

When to stay in one region

At ten cities, with no contractual availability promise and a small team, Dabba should probably not build active-active. It should run across three zones in one region, keep backups in a second Indian region, restore them on a schedule to prove they work, keep infrastructure as code so that the region could be rebuilt, and write down a realistic RTO of several hours. That is a defensible position, and it is far better than an untested second region that gives false confidence.

Note also what multi-region does not fix. It does not help when the cause is a bad deploy, a corrupting bug or an expired certificate, because those reach both regions. It does not help when a shared dependency, such as the payment provider, fails. For Dabba those causes are far more frequent than regional loss. The triggers to revisit the decision are specific: an hour of peak outage costing more than a year of the second region, a contract or regulator requiring a tested recovery time, or growth to the point where city homing is also needed for capacity.

That last point about deploys deserves its own chapter. The next one, on shipping safely, deals with the cause behind most of Dabba’s real incidents: changes we make ourselves, and how to make them in small, reversible steps.