Tool brief

Redis Guide: Caching, Counters, Queues and State

Decide where Redis belongs in an application. Use TTL, eviction, persistence, and restart tests to distinguish a disposable cache from durable state.

Editorial update

Decision in brief

Use Redis when an application needs low-latency shared state such as a cache, temporary counter or fast membership check and the application can honor the chosen expiry and failure policy. Keep durable records in a system designed to meet their recovery and correctness requirements. Decide what must happen when Redis is empty, slow or unavailable before adding it.

Plan for an empty cache: Set expiry. Test eviction. Drill a miss.
Define how the app behaves when Redis is empty, slow or unreachable.

Choose Redis by what loss would mean

Redis keeps data structures such as strings, hashes, sets and sorted sets in memory. TTL limits how long an individual key lives; the maxmemory eviction policy governs behavior when memory pressure rises. A TTL does not guarantee a key stays present until expiry under an eviction policy.

Redis RDB persistence saves snapshots. AOF records write operations according to the configured persistence policy. Measure recovery and acknowledged-write loss under the exact setup. If software licensing drives an alternative choice, check the edition and release in the vendor’s license table instead of applying one version’s terms to every release.

Kind of stateStarting designTest before shipping
Rebuildable result cacheUse TTLs and eviction with an upstream source of truthCold cache and upstream protection during high miss rates
Shared rate counterUse an atomic counting pattern and explicitly choose outage behaviorExpiration and concurrent updates with known inputs
Transient messagesTreat Pub/Sub as live-only; evaluate Streams when replay or consumer groups are neededSlow subscriber, disconnect, repeat processing and retention
Irreplaceable record or critical workflow stateKeep a durable store and define delivery or idempotency guaranteesRestart, restore and observed loss against the business contract

Two HN reports on service and memory budgets

In a thread about GPU scheduling, author lneiman said their team used Redis and Lua to track rapidly changing load for a client-side router. Their results were specific to that service. The useful test is whether fresh shared state improves the application metric and how stale state changes routing.

In the KiviDB Show HN, murtazayusuf said snapshot memory spikes and out-of-memory events in a previous deployment motivated the project. That is one participant’s report about a Redis-compatible system. It points to monitoring resident memory at peak writes and during snapshot activity, even if the steady-state working set fits.

Stage cold-cache, memory-pressure, and restart tests

Use synthetic keys and your approximate value sizes and access skew. Write down acceptable p95 latency, upstream traffic and recovery time before introducing Redis.

  1. Replay the workload with Redis disabled to establish the upstream load. Repeat with a warm cache, reporting hit rate, p95 latency and memory.
  2. Raise the working set past the intended memory threshold in an isolated instance. Observe cache misses, evictions or rejected writes and measure upstream fan-out.
  3. Restart or disconnect the staging instance, then measure recovery and whether any expected state was lost. Check the application remains within its stated fail-open or fail-closed contract.
  4. Accept Redis when latency improves enough to justify the added service and degraded modes stay within limits. Stop if a cache miss or restart breaks a business invariant.

Related articles