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
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
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
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
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
Return the result
The application sends the resolved value back to the client. Future matching requests may now be served from Redis.
- 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
Related visual explainers
How does a CDN work?
A content delivery network serves cacheable content from edge locations closer to users. The edge can answer immediately on a cache hit or fetch the object from an origin on a miss, then reuse it according to cache-control rules.
How does vector search work?
Vector search converts a query into an embedding and finds stored vectors that are nearby according to a similarity metric. Large systems usually use approximate nearest-neighbor indexes to trade a small amount of recall for much faster retrieval.