Build something like this?

Root hub

Redis as a distibuted cache

Overview of a cache-aside architecture. Web and mobile clients reach stateless app services through an API gateway and load balancer. The app services read and write a Redis Cluster and fall back to PostgreSQL, the source of truth, on a cache miss. Redis Sentinel is shown as the alternative high-availability option. A Cache Knowledge group holds the reference topics: flows, TTL and eviction, problems and fixes, strategies, production caveats and sizing. Each node drills into its own layer board.

10 layersby Supportv1Published Dec 1, 2026

About this system

Redis as a Distributed Cache: System Landscape

Built from the one-page "Redis as a distributed cache" cheat sheet.

Request path

Web / Mobile Clients → API Gateway → Load Balancer → App Services

  • Clients speak HTTPS only.
  • The gateway handles auth, rate limiting, routing and TLS.
  • The load balancer spreads requests over stateless app instances.

Data path

  • App Services → Redis Cluster: GET/SET/DEL over RESP/TCP. The app decides when to use the cache. Redis never calls the database.
  • App Services → PostgreSQL: SQL on a cache miss and on writes. PostgreSQL is the source of truth.
  • Redis Sentinel is the alternative HA setup to Redis Cluster. Pick one.

Cache Knowledge (reference topics)

TopicCovers
Cache-aside FlowsA) hit, B) miss with DB fallback, C) write DB then invalidate
TTL & EvictionExpiry, jitter, maxmemory and eviction policies
Cache Problems & FixesStampede, penetration, avalanche, hot keys, stale data
Cache StrategiesNative Redis features vs cache-aside, read-through, write-through, write-behind
Redis in ProductionAsync replication, failover loss, partitions, lag, sharding, persistence, memory, monitoring
Back-of-EnvelopeHit ratio and latency estimates (illustrative)

Layer boards

App Services, Redis Cluster, PostgreSQL, Redis Sentinel and the six topics above each drill into their own layer.

Key rule

Redis is NOT the source of truth. Data in the cache can be lost or stale, and PostgreSQL holds the authoritative copy.

The map

The map · Spine

Architecture

What's on this map
  • API Gateway · gateway
  • App Services · microservice
  • Back-of-Envelope · concept
  • Cache-aside Flows · process
  • Cache Knowledge · knowledge domain
  • Cache Problems & Fixes · concept
  • Cache Strategies · concept
  • Load Balancer · aws elb
  • PostgreSQL · data store
  • Redis Cluster · data store
  • Redis in Production · concept
  • Redis Sentinel · infrastructure component
  • TTL & Eviction · concept
  • Web / Mobile Clients · frontend app

The map · Layers

Layers10

+3 more

What's on each layer

App Services

Inside the stateless application tier: three identical app instances, each with a Redis client, a PostgreSQL connection pool and the cache-aside lookup logic. The app decides when to use the cache. Redis never calls the database.

  • App #1 · microservice
  • App #2 · microservice
  • App #3 · microservice
  • Cache Lookup Logic · component
  • PG Pool · library package
  • Redis Client · library package

Back-of-Envelope

Quick sizing maths for the cache: how to read the hit ratio from INFO stats, four latency tiers and an average-latency calculation showing why cache placement matters. All figures are illustrative, not benchmarks.

  • Average latency at 94% hits · concept
  • Hit ratio (from INFO stats) · concept
  • In-process memory · concept
  • PostgreSQL indexed read · concept
  • Redis, other region · concept
  • Redis, same zone · concept

Cache-aside Flows

The three cache-aside flows between app, Redis and PostgreSQL: A) cache hit, B) cache miss with DB fallback, C) data change by writing the DB then invalidating the cache. Also why the order matters and why data can still go stale.

  • It can still go stale · concept
  • A) Cache HIT (fast path) · process
  • B) Cache MISS -> database fallback · process
  • C) Data changes -> write DB, then invalidate · process
  • Participants · component
  • Why this order? · concept

Cache Problems & Fixes

The five classic cache problems, stampede, penetration, avalanche, hot keys and stale data, each linked to its fix.

  • Fix: TTL jitter, replicas, rate-limit · process
  • Fix: local cache, split copies · process
  • Fix: cache 'not found', Bloom filter · process
  • Fix: DEL after COMMIT, TTL, CDC · process
  • Fix: lock / refresh early · process
  • Cache avalanche · concept
  • Hot keys · concept
  • Cache penetration · concept
  • Stale data · concept
  • Cache stampede · concept

Cache Strategies

Who does the work in each caching approach: what Redis provides natively versus the patterns that the app or a caching library builds, namely cache-aside, read-through, write-through and write-behind.

  • Native in Redis · concept
  • Patterns built by the APP or a caching library · concept
  • Cache-aside (lazy loading) · process
  • Read-through · process
  • Write-behind / write-back · process
  • Write-through · process

PostgreSQL

The durable source of truth: a primary with ACID guarantees, WAL and indexes, a disk for durability and two asynchronous streaming read replicas. Includes the rule that Redis is not the source of truth.

  • Disk · data store
  • PostgreSQL Primary · data store
  • Read Replica 1 · data store
  • Read Replica 2 · data store
  • Redis is NOT the source of truth · policy
  • Redis vs PostgreSQL (persistence layer) · concept

Redis Cluster

How Redis Cluster spreads and protects data: keys map to 16,384 hash slots, slots are owned by three primaries, each primary has a replica, and nodes gossip over a cluster bus that drives automatic failover.

  • Cluster Bus & Failover · infrastructure component
  • Hash Slot Routing · component
  • Primary A (shard A) · data store
  • Primary B (shard B) · data store
  • Primary C (shard C) · data store
  • Replica A1 · data store
  • Replica B1 · data store
  • Replica C1 · data store

Redis in Production

What can go wrong in production: asynchronous replication, write loss on failover, network partitions, replica lag, sharding limits, persistence trade-offs, memory limits and the need for monitoring.

  • Replication is ASYNC by default · concept
  • Cache consistency · concept
  • Failover can lose acknowledged writes · concept
  • Memory limits · policy
  • Monitor · process
  • Network partitions · concept
  • Persistence: RDB and AOF · concept
  • Replication lag · concept
  • Sharding = horizontal scaling · concept

Redis Sentinel

High availability without sharding: three Sentinel processes monitor one primary and its replicas, agree on a failure and elect a leader to promote a replica. Includes the decision between Cluster and Sentinel.

  • Sentinel S1 · infrastructure component
  • Sentinel S2 · infrastructure component
  • Sentinel S3 · infrastructure component
  • Primary · data store
  • Replica 1 · data store
  • Replica 2 · data store
  • Cluster vs Sentinel · decision

TTL & Eviction

What happens inside one Redis node: the keyspace lives in RAM, TTL expires keys automatically (with jitter to avoid mass expiry), and an eviction policy decides what to remove once maxmemory is reached.

  • Expiry vs eviction · concept
  • Inside one Redis node: keyspace in RAM · concept
  • maxmemory · policy
  • allkeys-lfu · policy
  • allkeys-lru · policy
  • noeviction · policy
  • volatile-lru · policy
  • volatile-ttl · policy
  • Commands run one at a time · concept
  • TTL = automatic expiration · concept
  • TTL jitter · process