Video in progress

A service has to run active in two regions (say, Tashkent and Frankfurt). How do you set up the Redis cache, and what consistency problems come up?

Usually a separate, independent cache in each region, with invalidation events distributed through a cross-region queue. An active-active Redis with replication (Redis Enterprise based on CRDTs or similar) allows writes on both sides, but you need to understand the conflict resolution semantics and the cost.

📖 Answer

The latency between regions is 50-150 ms. If every cache request goes to the other region, the cache loses its point. So the cache itself has to be local. The question is how it stays "correct".

Option A: independent local caches. Each region reads from its own DB replica and fills its own Redis. On a write, an invalidation event (Kafka MirrorMaker or a managed global topic) goes to both regions.

The problem: the DB replica in Frankfurt is 500 ms behind the primary in Tashkent. If the invalidation arrives before the replica does, Frankfurt deletes the cache entry, and the next read gets the old value from the stale replica and puts it back in the cache. The solution is to apply the invalidation only after the replication position (LSN) has caught up, or to write with versions (only a newer version is written to the cache), plus a short TTL.

Option B: active-active Redis (CRDT). You can write in both regions, and changes are merged asynchronously. Counters (INCR) add up well; for strings it's usually "last writer wins". This exists in commercial products and is expensive; it's not in open-source Redis. For a cache it's usually overkill.

Option C: don't cache global data locally. For some things (balance, inventory count) the right way is a "home region": the user's data is written and read in one region, and the cache is there too.

I usually split the data by type:

  • rarely changing, global (catalog, translations): A, and we tolerate a few seconds of staleness;
  • user-specific: C, and the user is routed to their own region;
  • cross-region counters (rate limit, quota): each region gets its own share of the limit, and an exact global number isn't needed.

You must agree on a number with the business in writing: "how many seconds stale can the cache be". Without that number, every staleness bug turns into an incident.