Backendcore
Queues & workers
Move slow or bursty AI work off the request path; workers process at a controlled rate.
What it is and why it exists
Ingestion, batch inference, long agent runs and notifications go through a queue: producers enqueue quickly, workers consume at a rate the providers allow, retries happen without the user waiting, and spikes become backlog instead of errors.
Quick prototype
BackgroundTasks in FastAPI.
In production, at scale
A durable queue, idempotent consumers (at-least-once delivery), dead-letter queues, visibility timeouts longer than the job, concurrency per worker tuned to rate limits, and queue-depth autoscaling.
Vendors and tools
| Celery / ARQ / RQ / Dramatiq | Python job queues |
|---|---|
| BullMQ | Node job queues |
| Kafka / RabbitMQ / Redis Streams | Brokers |
On AWS: SQS + Lambda or ECS workers, with DLQs; EventBridge for routing events.
How it fails
- Visibility timeout shorter than an LLM call → duplicate processing
- No DLQ, poison messages retried forever
What the interviewer asks next
Why must consumers be idempotent?
Queues deliver at least once: a crash after doing the work but before acknowledging means the message comes back. Without idempotency you index twice, email twice, charge twice.