Backend systems

How does Redis caching work?

A Redis cache keeps frequently requested data in fast in-memory storage so an application can avoid repeating slower database or service work. A common cache-aside flow checks Redis first, falls back to the source on a miss, then stores the result with an expiration policy.

Step-by-step

  1. 1

    Receive a read request

    The application receives a request and derives a cache key from the resource and any inputs that affect the result.

  2. 2

    Check Redis first

    The application asks Redis for the key. When the value is present and still valid, the request can be served without querying the slower source.

  3. 3

    Handle a cache miss

    If Redis does not contain a usable value, the application reads from the database or upstream service that owns the authoritative data.

  4. 4

    Populate the cache

    The freshly loaded value is written to Redis, often with a TTL or another expiration and invalidation policy that fits the data.

  5. 5

    Return the result

    The application sends the resolved value back to the client. Future matching requests may now be served from Redis.

  6. 6

    Expire or invalidate

    Cached data eventually expires or is explicitly invalidated when freshness requirements demand it, preventing stale entries from living forever.

Keep learning