Advertisement
Advanced Redis, Lists in Redis

How would you implement a reliable queue pattern using Redis lists that prevents losing a task if the worker processing it crashes?

Short answer

You use the RPOPLPUSH or the newer LMOVE command to atomically move a task from the main queue into a separate processing list at the same time it is retrieved, so if a worker crashes while handling that task, it remains visible in the processing list and can be detected and…

Save Redis mock interview
Advertisement
AModel answer
You use the RPOPLPUSH or the newer LMOVE command to atomically move a task from the main queue into a separate processing list at the same time it is retrieved, so if a worker crashes while handling that task, it remains visible in the processing list and can be detected and reprocessed by a monitoring process, rather than being lost entirely.
Example

RPOPLPUSH task_queue processing_queue -- Worker processes the task, then removes it -- from processing_queue only once fully complete LREM processing_queue 1 'completed_task'

Real-world example
A payment processing system moves each task into a dedicated processing list as a worker picks it up, ensuring that if the worker crashes mid task, a monitoring process can detect the stuck task still sitting in the processing list and safely retry it.
Likely follow-ups
  • How does a monitoring process detect tasks that have been stuck in the processing list too long?
  • What is the difference between RPOPLPUSH and the newer LMOVE command?
Related topics