Skip to main content
PreparationZone Logo
PrepZone

Distributed Cache Architecture

Client-side vs server-side caching, replication, and cache layers in production.

Pass checkpoint below

Read these first

Why this matters

  • A single Redis instance caps out around 100–200K ops/sec; VaultCommerce's peak cart traffic needs a clustered topology with consistent hashing.
  • Client-side caching reduces network hops but introduces staleness across pods.
  • Production interviews ask you to diagram L1/L2 cache layers and explain what happens when a node dies.
App
RedisCache
PostgresSource of truth
Redis
App checks cache first. On miss, reads DB and populates cache.

Client-side vs server-side caching

Two distribution models

  • Client-side (embedded) — each app instance holds a local cache (Caffeine, Guava); zero network on hit.
  • Server-side (remote) — dedicated Redis/Memcached cluster; all pods share one cache pool.
  • Hybrid L1 + L2 — local cache in front of Redis; fastest hits, shared warmth on L2.
Java
VaultCommerce hybrid stack:

  Request → Caffeine L1 (5s TTL, per pod)
              ↓ miss
            Redis L2 (10 min TTL, cluster)
              ↓ miss
            Postgres (source of truth)

L1 catches repeated reads within a single pod during a burst. L2 shares warmth across the fleet. Invalidating L2 via pub/sub triggers L1 eviction in every pod.

Redis Cluster topology

VaultCommerce runs a 6-node Redis Cluster — 3 primaries, 3 replicas — with consistent hashing across 16,384 slots:

Java
redis_cluster:
  primaries: 3
  replicas_per_primary: 1
  hash_algorithm: crc16_slot
  client: lettuce_cluster_aware
  failover: automatic_promotion

When redis-2 fails, its replica promotes and serves slots previously owned by the failed primary — cart reads continue with sub-second failover.

TopologyProsCons
Single instanceSimplest opsSPOF, memory ceiling
Primary + SentinelHA failoverNo horizontal scale
Redis ClusterScale + HAMulti-key ops need hash tags
Memcached poolMulti-threaded blobsNo native HA — client reroutes
  • Single instance

    ProsSimplest ops
    ConsSPOF, memory ceiling
  • Primary + Sentinel

    ProsHA failover
    ConsNo horizontal scale
  • Redis Cluster

    ProsScale + HA
    ConsMulti-key ops need hash tags
  • Memcached pool

    ProsMulti-threaded blobs
    ConsNo native HA — client reroutes

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 3 sections

  • Cache layers in production
  • Hot key mitigation
  • Observability and failure modes

Test yourself

Answer these before moving on — recall is what makes it stick.