Lesson 9 of 9 · 27m
Abuse Cases to Avoid: How Redis Gets Misused in Production
The recurring disasters: primary source of truth without durability, giant keys, KEYS scans, distributed locks done casually, queues without recovery, and cache/database split-brain.
Most Redis harm is self-inflicted. Not because Redis is bad, but because it is pleasant enough that people use it for everything. The senior move is knowing which uses are load-bearing infrastructure and which are a convenient prototype that escaped into production.
Using Redis as the system of record by accident
The trap starts harmlessly: 'we will temporarily store this important object in Redis.' Months later the relational database has an ID and Redis has the only copy of the state. If eviction, failed persistence, or failover removes it, there is nowhere to reconstruct from.
Decide explicitly which system is authoritative. If Redis is authoritative, durability, backup, failover, restore testing, access control, and capacity management become database-grade responsibilities. If it is not authoritative, every value must be expendable or reconstructable.
The distributed lock fairy tale
SET lock:order-991 token NX PX 30000This is only the beginning. Lock expiry races, pause-the-world GC, retry behavior, fencing tokens, and ownership checking determine whether mutual exclusion means anything. A lock that expires while work continues can admit a second worker. Releasing it blindly can then delete the second worker's lock.
Use established implementations where possible, understand Redlock's contested assumptions, and prefer idempotency or database constraints when correctness matters. Locks are coordination, not proof of correctness.
Queues without acknowledgement semantics
A list plus BRPOP is fast and simple — and loses jobs when consumers crash. Streams with consumer groups give pending states and explicit acknowledgement, but they still require retry, poison-message handling, trimming, and monitoring.
If 'the job disappeared' means money was not charged or a machine was never provisioned, compare Redis Streams honestly against dedicated queues and workflow systems. Operational familiarity matters, but so does semantic fit.
Giant values and hot keys
A celebrity key can saturate a shard even when memory is fine. Every request reads the same object, one core does the work, replicas copy the same write stream, and clients form a thundering herd.
Mitigate with replication-aware reads, local caches, sharded counters, or denormalization. Splitting a counter into counter:events:0..15 and summing it on read often beats pretending one atomic counter is free at internet scale.
KEYS, unbounded SCAN loops, and debug commands in request paths
KEYS * is a blocking full keyspace traversal. The correct production answer is almost always a designed index: a set, sorted set, stream, or relational query. SCAN is safer for maintenance because it iterates incrementally, but doing a full scan on every request just distributes the same cost forever.
Cache/database split brain
Writes that update PostgreSQL but fail to invalidate Redis create two truths. Writes that update Redis first and fail in PostgreSQL create a worse one. Order operations deliberately, use versioned data or outbox patterns where needed, and accept that distributed consistency is a design problem rather than a command flag.
Field notes
- If a Redis outage requires a complete product outage, it was not 'just a cache.'
- Test
FLUSHALLincident response hypothetically: what data is gone, what regenerates, what breaks first? - Session stores need expiry, rotation, and abuse controls; otherwise they become permanent credential warehouses.
- Pub/sub is fire-and-forget. If the consumer is offline, the message is gone.
- The best abuse detector is a design review question: 'what happens when this key is missing, stale, huge, hot, or written concurrently?'
Was this lesson helpful?