Redis Distributed Locks (Redlock caveats)
Design a small subsystem that relies on Redis Distributed Locks (Redlock caveats). Outline components, data flow, failure modes, and metrics.
Answers use simple, clear English.
Quick interview answer
Use Redis Distributed Locks (Redlock caveats) as the core idea. Example shape: Cron job on N pods: only one runs nightly billing via Redis lock with 5min TTL + heartbeat extend..
Detailed answer
Use Redis Distributed Locks (Redlock caveats) as the core idea. Example shape: Cron job on N pods: only one runs nightly billing via Redis lock with 5min TTL + heartbeat extend.. Watch for: Clock skew / long GC can cause double execution; not CP like etcd.. Measure success via latency/error/saturation. Core: SET key token NX EX ttl acquires lock; release with Lua comparing token. Redlock multi-master debated — prefer DB advisory locks or etcd for strict correctness. Real-time example: Cron job on N pods: only one runs nightly billing via Redis lock with 5min TTL + heartbeat extend. Pros: Simple; fast; works for many coordination tasks. Cons: Clock skew / long GC can cause double execution; not CP like etcd. Common mistakes: DEL without token check; no TTL (dead lock holder); lock too short for work. Best practices: Unique token + Lua release; fencing tokens for storage writes. Audience level: Engineering Manager.
Full explanation
SET key token NX EX ttl acquires lock; release with Lua comparing token. Redlock multi-master debated — prefer DB advisory locks or etcd for strict correctness.
Real example & use case
Cron job on N pods: only one runs nightly billing via Redis lock with 5min TTL + heartbeat extend.
Pros & cons
Pros: Simple; fast; works for many coordination tasks. Cons: Clock skew / long GC can cause double execution; not CP like etcd.
Common mistakes
DEL without token check; no TTL (dead lock holder); lock too short for work.
Best practices
Unique token + Lua release; fencing tokens for storage writes.
Follow-up questions
- How would you test Redis Distributed Locks (Redlock caveats)?
- What metrics prove Redis Distributed Locks (Redlock caveats) is healthy in prod?
- How does Redis Distributed Locks (Redlock caveats) change at 10× traffic?