Building a Reliable Python Task Queue with Redis Streams
A Python task queue can be built reliably using Redis Streams by leveraging consumer groups and the Pending Entries List (PEL) to ensure at-least-once delivery. This architecture prevents data loss during worker crashes by requiring explicit acknowledgments (XACK) before removing tasks from the queue. Three weeks ago, I watched my production logs turn into a graveyard of "Task Disappeared" errors. I was running a fleet of AI agents designed to process long-running document analysis tasks using the Gemini API. My architecture was simple: a FastAPI endpoint received a request, pushed a task into a Redis List using LPUSH , and a background worker pulled it out with BRPOP . It worked perfectly in staging. In production, under the pressure of 50 concurrent users, it crumbled. The problem was the inherent "at-most-once" delivery of simple Redis lists. When a Cloud Run instance scaled down or hit a memory limit, the worker would pop the task from the list, start proces...