Skip to content

Redis as an edge cache — when it fits and how to deploy it

Using Redis as a regional or edge cache for application APIs — replicated read-replicas, geo placement, eviction, and where the pattern breaks.

Redis is not a CDN. It is, however, a fast in-memory store that you can deploy in regional clusters near your application to act as the L2 cache for API responses, computed objects, and session-style data that the CDN cannot cache. The pattern is “Redis at the edge of the application” — not the edge of the internet, but close enough to the user-facing service that the round-trip is microseconds, not milliseconds. This article is the operating model for that deployment.

How to verify

Check whether you have a regional Redis already and what it caches.

redis-cli -h cache.region-a.internal INFO replication
redis-cli -h cache.region-a.internal INFO keyspace
redis-cli -h cache.region-a.internal --latency-history -i 1 | head -5
redis-cli -h cache.region-a.internal MEMORY USAGE some:popular:key

If INFO replication shows role:master and no slaves, you have a single instance. If role:slave with a master_link_status:up, this is a read replica fed from a primary elsewhere.

What’s happening

The “Redis at the edge” pattern places a Redis instance (or a small cluster) close to each application region: one in us-east-1, one in eu-west-1, one in ca-central-1. The application reads from the local Redis and writes to the canonical store. The Redises do not share state directly — they are each populated by their local application on miss.

This is not the same as Redis replication for HA. A primary-replica setup ships writes one direction; if the primary is in us-east-1 and the replica is in eu-west-1, writes from EU still cross the Atlantic before they appear in EU’s replica. The edge-cache pattern accepts that each region has its own cache populated independently — the convergence comes from origin, not from cross-region replication.

The pattern fits when:

  • Cache content is computed from the database and is region-agnostic.
  • Cache invalidation is rare or driven by application-emitted events (which can fan out to each region).
  • The cost of multi-region replication (latency, complexity, conflict resolution) is higher than the cost of region-local cold misses.

It does not fit for session state — sessions need to follow the user, and a user hopping regions hits a cold cache. For session data, use a globally replicated store (KeyDB multi-master, DynamoDB Global Tables) or pin the session to a region.

The procedure

  1. Deploy Redis per region. Each region gets a small primary + replica pair for HA. No cross-region replication.

    # In each region's terraform/k8s/etc.
    redis-primary:
      instance: cache.m6g.xlarge
      az: us-east-1a
      replication: standalone
    redis-replica:
      instance: cache.m6g.xlarge
      az: us-east-1b
      replication: replica-of primary
  2. Wire the application to the local Redis only. The application’s connection string is region-specific.

    import os
    REGION = os.environ.get('AWS_REGION', 'us-east-1')
    REDIS_HOST = f'redis.{REGION}.internal'
    redis_client = redis.Redis(host=REDIS_HOST, port=6379, decode_responses=True)
  3. Populate on miss; invalidate explicitly. Reads go through cache-aside. Invalidations from origin events fan out to every region’s Redis.

    def get_product(pid):
        v = redis_client.get(f"product:{pid}")
        if v: return json.loads(v)
        p = db.products.find_one({'_id': pid})
        redis_client.set(f"product:{pid}", json.dumps(p), ex=600)
        return p
    
    # On origin model save, publish to all regions
    def on_product_save(pid):
        for region in REGIONS:
            r = redis.Redis(host=f'redis.{region}.internal')
            r.delete(f"product:{pid}")
  4. Set per-key TTL by data class. Products and catalog items: 10 min. User profile lookups: 5 min. API responses that include rolling counts: 30 sec. Match the staleness budget the data owner accepts.

  5. Monitor each region’s cache independently. A region-local cache problem is invisible from another region’s dashboard.

    # In each region's monitoring stack:
    redis_exporter -redis.addr redis://redis.us-east-1.internal:6379 -web.listen-address :9121
    # Scrape from the regional Prometheus

Common pitfalls

  • Treating “Redis with cross-region replication” as the edge-cache pattern — that is a different design with different failure modes.
  • Forgetting that the invalidation fan-out has its own failure modes. If a region’s Redis is unreachable when invalidation fires, that region keeps the stale entry until TTL.
  • Sizing the regional Redis to the global working set instead of the regional working set — most data is accessed in one region; the regional cache only needs the region’s slice.
  • Using cluster mode (sharded Redis) for a regional cache that fits on one node — adds complexity without buying anything.
  • Connecting the application across regions when the local Redis fails — the cross-region call is slower than the database. Fail open to the database instead.

In the engagements we run, regional Redis is the workhorse cache for multi-region applications. Stack Harbor’s multi-region environments practice treats the regional cache as part of the regional footprint — each region is self-contained, with the cache populated by the region’s traffic.