Learning pathsPricingChecking sign-in…
GUIDED PRACTICE

Redis: Cache and Data Structures

Redis is an in-memory data-structure server used for caching, counters, coordination hints and streams; its role must be explicit in the source-of-truth model.

Redis: Cache and Data Structures

Redis is an in-memory data-structure server used for caching, counters, coordination hints and streams; its role must be explicit in the source-of-truth model. Strings support values and counters; hashes represent fields; sets and sorted sets support membership and ranking; streams support consumer-group processing. TTL controls expiry; eviction reclaims memory. Replication and Sentinel/Cluster solve different availability and sharding needs. Lua makes selected Redis operations atomic, not transactions across Redis and a relational database.

Mechanism and worked example

A rate limiter can atomically refill and consume tokens in a script. Cache-aside product lookup may tolerate short staleness. Inventory reservation should remain in a transactional authoritative store unless Redis is deliberately engineered to meet durability and recovery requirements.

FeatureUseful forCaution
TTL/evictionBound cache lifetime and memoryExpiry and eviction differ
ReplicationRead copies and failoverRecent writes may be absent
ClusterHorizontal key distributionHot keys and cross-slot operations
LuaAtomic local transitionNo cross-database transaction
StreamsConsumer groupsRetention and pending recovery

Failure modes and operations

Eviction can remove keys before TTL. Async replication may lose recent writes during failover. Cluster resharding changes key placement; multi-key operations may require same-slot keys. Hot keys overload one shard. Cache outages can stampede the database.

Trade-offs and design boundary

Redis offers low-latency primitives but memory cost, persistence, replication lag and topology matter. Memcached may be simpler for pure cache workloads. Durable business invariants should remain in a database unless Redis is explicitly the authority.

Interview transfer exercise

Why is a Redis lock with TTL insufficient if an expired owner can resume? The protected destination needs a monotonically increasing fencing token and must reject stale owners.

Diagram: Application checks Redis primitive; Cache miss reads authoritative database; Source write commits then cache invalidates; Failover and eviction are expected events
Mechanism and decision flow for Redis: Cache and Data Structures.
Read the diagram

Application checks Redis primitive → Cache miss reads authoritative database → Source write commits then cache invalidates → Failover and eviction are expected events

Open original
Redis: Cache and Data Structures
Diagram: Application checks Redis primitive; Cache miss reads authoritative database; Source write commits then cache invalidates; Failover and eviction are expected events

Mechanism and decision flow for Redis: Cache and Data Structures.

18:00Self-guided practice timer
The timer resets when you leave this page. Save your design separately.
Your challenge

Why is a Redis lock with TTL insufficient if an expired owner can resume? The protected destination needs a monotonically increasing fencing token and must reject stale owners.

Your design draft

Clarify assumptions, explain your approach, and test the difficult cases. Save your draft, then compare it with the study notes.

Read study notes

Self-review checklist

Self-guided practice. Automated AI feedback and code execution are not connected.