Distributed systems

Active-active across regions, without lying to yourself

Active-active sounds like a latency feature and behaves like a data-modelling problem. If two regions accept writes for the same record, something has to decide which one wins, and that something is now part of your product.

The proposal always arrives the same way: users in Singapore see 180 ms adds, so move the write path there too. What follows is a discussion about replication that skips the only question that matters - what should happen when both regions edit the same row within the same second.

Last-write-wins is a data loss policy

Most "multi-master" setups resolve conflicts by timestamp. Timestamps come from clocks, clocks disagree, and the loser's write disappears without an error anywhere. For a shopping cart that is annoying; for an inventory count or a permissions table it is silent corruption that surfaces weeks later in a reconciliation job.

Before choosing a mechanism, classify the data. Records that are single-writer by nature are easy. Records that are genuinely concurrent need a merge rule that is part of the domain model, not a fallback in the replication layer.

The CRDTs we actually trust

Conflict-free replicated data types give every replica a deterministic merge, so no write is lost in transit. In practice we use four, and we reject the rest until a concrete need appears:

TypeUseTrade-off
G-counter / PN-counterView counts, quota consumptionCannot go negative without care
OR-SetTags, membership, allow listsTombstones need compaction
LWW-registerProfile fields with a clear ownerClock skew decides the winner
Sequence CRDTOrdered lists, commentsMetadata grows with edit history

An inventory balance is deliberately absent from that list. Stock is not a set and not a counter with commutative decrements in every failure mode; we model reservations as single-writer in one region and replicate the resulting ledger.

A write path with an honest budget

Cross-region round trips are 180 to 250 ms, so a write that requires synchronous acknowledgement in both regions has given back everything active-active was supposed to win. Our rule is explicit: commit locally, replicate asynchronously, and publish the replication lag target per dataset. Reads that must be read-your-writes use a session token that pins the client to the region that accepted the write until the version is visible elsewhere.

The budget for user-facing data is a local commit under 20 ms and a replication p99 under 600 ms. Anything that cannot tolerate that window belongs in a single-writer dataset, not in an active-active one.

Test with partitions, not dashboards

Every active-active design we have shipped was validated by cutting the inter-region link, not by watching a latency graph. The test blocks traffic for sixty seconds, writes to both sides, restores the link and then asserts that each write survives with a deterministic merge outcome.

The uncomfortable check

If a failover drill never partitions the network, it is a load test with a more dramatic name. Schedule the partition during working hours, with the product owner watching, at least once per quarter.

Active-active is worth it when the domain has genuinely commutative operations and the team is willing to own the merge rules. When it does not, a primary region with fast read replicas is the cheaper, more honest architecture.

Newer noteConsistent hashing and bounded loads