Redis Deep Dive
Redis is the dominant distributed cache. It is an in-memory data store that supports strings, hashes, lists, sets, sorted sets, bitmaps, and more — far beyond simple key-value caching. Local Redis calls are typically very fast because data lives in RAM; once you add network hops, measure p50/p99 rather than assuming a fixed latency.
Persistence options matter for production. RDB (Redis Database) takes point-in-time snapshots at intervals — fast recovery, but you may lose data since the last snapshot. AOF (Append Only File) logs every write operation — more durable, slower recovery. Most teams use both: RDB for fast restarts, AOF for durability. Redis Pub/Sub enables real-time messaging between services — useful for cache invalidation broadcasts. For caching specifically, strings with SETEX (set with expiry) and hashes for structured objects are the most common patterns.
Security boundary: do not cache authorization decisions or full auth cookies in a shared cache without careful key design and TTL. Keep Redis off the public internet — require network controls and AUTH/ACL; treat cache contents as sensitive as the data you store there.
Exercise
Store a user profile as a Redis hash with EXPIRE, read one field with HGET, and implement a simple INCR rate-limit key with TTL. Note that Redis must not be exposed to the public internet without auth/network controls.