Async Processing
Background jobs (Celery, Sidekiq, SQS consumers), event-driven offloading
Asynchronous processing decouples time-consuming operations from the request/response cycle, enabling web servers to return immediately while work happens in the background. Tasks like sending emails, processing images, generating reports, and calling slow third-party APIs should never block HTTP responses. Celery (Python/Redis/RabbitMQ), Sidekiq (Ruby/Redis), BullMQ (Node.js/Redis), and SQS consumers (AWS) are the industry-standard implementations. Event-driven architectures extend this to inter-service communication via Kafka or SNS/SQS fanout.
Key Points
- Background jobs: enqueue work units (job class + serialized arguments) to a durable queue; worker processes consume and execute asynchronously.
- Celery: Python distributed task queue supporting Redis and RabbitMQ brokers; tasks decorated with @celery.task, scheduled with beat scheduler, monitored with Flower UI.
- Sidekiq: Ruby background job framework using Redis — processes 500+ jobs/second per worker process; built-in retry with exponential backoff, dead job queue.
- SQS consumers: AWS-managed queue service with at-least-once delivery; long polling reduces empty receives; visibility timeout prevents double processing.
- Idempotency: background jobs must be idempotent — network errors cause retries; use idempotency keys (job ID) to detect and skip already-processed jobs.
- Dead letter queues (DLQ): jobs that fail N times (e.g., 5) move to DLQ for manual inspection — prevents poison pill messages from blocking queue processing.
- Event-driven offloading: on Order Created, publish Kafka event; downstream services (inventory, notifications, analytics) consume independently — decoupled, scalable.
- Job priority queues: Sidekiq Pro and Celery support priority — critical notifications processed before bulk email campaigns sharing the same worker pool.
Real-World Example
Stripe processes billions of async events daily — webhook delivery, payment retries, fraud scoring, and email receipts are all Sidekiq background jobs. Their workers consume from Redis queues across 1,000+ Ruby processes, with DLQs and Stripe Dashboard surfacing failed jobs for on-call engineers.