Background worker
AWS Lambda (SQS trigger) / Amazon ECS
Processes jobs from a queue outside the request path: emails, image resizing, reports.
In a monolith
Background job runner
The same codebase started in worker mode (Celery / ARQ / Sidekiq) pulling jobs from Redis or a jobs table.
In a distributed system
Consumer fleet
Independent consumers scaled on queue depth. Every message is delivered at least once, so handlers must be idempotent.
On AWS
AWS Lambda (SQS trigger) / Amazon ECS
Lambda with an SQS event source for short jobs; ECS services scaled on queue depth for long or heavy jobs; AWS Batch for big batch work.
- Lambda + SQS trigger$Zero servers, scales with the backlog, 15-minute max per job
- ECS on Fargate (queue-scaled)$$Long jobs and custom runtimes; scale on queue depth
- AWS Batch$$Large, compute-heavy batch jobs
- Reach for it when
- Something in a request is slow, can fail and retry, or doesn’t need to finish before you reply.
- What it costs you
- Eventual consistency: results appear later
- Duplicates (at-least-once delivery) → idempotent handlers
- Poison messages need a DLQ; the backlog needs monitoring
- When it dies
- Jobs pile up in the queue but nothing user-facing breaks — emails and thumbnails just arrive later. When workers return they drain the backlog.
Interview follow-ups
How do you make a worker idempotent?
Check a dedupe key (message or business ID) against a table with a unique constraint, or make the write naturally idempotent (upsert, set instead of increment).
How do you scale workers?
On queue depth or age of the oldest message, not CPU. More consumers = more parallelism; ordering survives only within FIFO message groups.
What if a job keeps failing?
Retry with backoff a few times, then move it to a dead-letter queue and alert — never let it loop forever.
Connection rules
It talks to
Gets traffic from
- Scheduler
- Workflow
- Queue
- Pub/sub topic
- Event stream
- Object storageOnly when: S3 can invoke a function directly (S3 → Lambda); a queue in between adds buffering and retries.
- DLQOnly when: A separate consumer that inspects or replays failed messages — usually manual or alarm-driven.
Never
- Worker → CDNYour code doesn’t send traffic to the CDN — the CDN pulls from origins.
- Worker → WorkerWorkers hand work to each other through queues.
- Worker → DLQProducers publish to the main queue; the broker moves failures to the DLQ.
- Clients → WorkerWorkers aren’t on the request path — they pull jobs from a queue.
- Load balancer → WorkerWorkers pull from queues; they don’t receive HTTP traffic.
- API gateway → WorkerWorkers pull from queues; they’re not HTTP targets.
- App server → WorkerDon’t call workers directly — enqueue a job.
- Service → WorkerDon’t call workers directly — enqueue a job.
- Realtime server → WorkerDon’t call workers directly — enqueue a job.