Celery and background jobs · senior
Queues, priorities, vendor limits and choosing a task library
One shared queue lets bulk work delay urgent work. Separate queues and workers, vendor rate limits and an interface of your own make a task system survive a sale. Other libraries trade features for simplicity.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Cause of an SMS backlog on a sale evening: one default queue for everything, and a campaign queued 1.8 lakh tasks ahead of OTP and order tasks.
- Route critical tasks to their own queue with task_routes and dedicated workers (-Q critical). Pause the campaign at its source. Use queues by priority: critical, default, bulk.
- More workers did not help because the vendor allows a fixed number of messages per second and answers 429 beyond it; retries refill the queue and extra workers open more database connections.
- Celery rate_limit is per worker, not global. For a vendor-wide limit use a shared token bucket in Redis. OTP tasks get expires so stale ones are skipped.
- Design: priority queues and worker pools, vendor limits, a second vendor for OTP failover, autoscaling on queue length (KEDA) capped by vendor and database limits, campaigns throttled where they are produced.
- Celery has the most features (routing, canvas, beat, rate limits, many brokers) and the most configuration. RQ is simple, Redis only. Dramatiq has safer defaults (ack after processing, retries with backoff). arq is asyncio-native on Redis, but check its maintenance status. Django 6.0 has a Tasks framework, but it ships no worker; a backend package must run the jobs.
- Other options: a managed queue (SQS with a consumer, Cloud Tasks) or a PostgreSQL job table with SKIP LOCKED for fewer moving parts.
- Decide on delivery guarantees, retries and visibility, scheduling, async support, operating cost, team knowledge, monitoring and project health. Put enqueue calls behind a small interface of your own so a later switch touches one module. During the incident tell business and support what is delayed and what is fine.
The red pen
Common traps: mistake → fix
Mistake: Add more workers when the queue grows
Fix: check the vendor limit and database connections first.
Mistake: Celery rate_limit limits the whole system
Fix: it limits each worker.
Mistake: Pick the library with the most features
Fix: pick on guarantees, team and maintenance.
Mistake: Django Tasks runs jobs by itself
Fix: it needs a worker backend.
Easy to hard
Questions interviewers ask, easy to hard
- Order SMS arrive 40 minutes late and OTPs expire. What do you check?
- Why did adding workers not help?
- How do you design queues for a sale?
- Celery, RQ, Dramatiq, arq or Django Tasks for a new FastAPI service?
- How do you keep the choice reversible?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.