Practice & Assessment
Test your understanding of Message Queues and Async Processing
Multiple Choice Questions
6A worker processes a payment job and charges the card, but crashes before sending the ACK to the queue. The queue redelivers the job. What is the risk?
What is the purpose of a Dead Letter Queue (DLQ)?
You publish an event to a Redis Pub/Sub channel. One subscriber is offline at that moment. What happens to the event for that subscriber?
A webhook server sends a POST to your callback URL. How do you verify it is genuinely from the expected sender?
When should you use pub/sub over a job queue?
A client polls GET /jobs/abc-123 every 100ms waiting for a result that takes 30 seconds. What is the main problem?
Coding Challenges
1Async report generation API with job status polling
Build a POST /reports endpoint accepting JSON with userId and reportType, enqueue a BullMQ job, and return 202 Accepted with jobId and statusUrl. Implement GET /jobs/:id returning job status (waiting, active, completed, failed) and result URL when complete. Worker simulates report generation with a 3-second delay and stores a fake result in Redis. Implement idempotency: if the same userId and reportType combination is already in-flight, return the existing jobId instead of creating a duplicate. Input: POST body with userId and reportType. Output: 202 with jobId on create, 200 with status and result on status check. Estimated time: 25-30 minutes.
Mini Project
Email Notification Worker System
Build a complete async notification system. API: POST /notifications accepts JSON with type (welcome, password-reset, order-confirmed), userId, and optional webhookUrl, returning 202 with jobId. Enqueue to BullMQ with priority: password-reset is priority 1, others priority 5. Worker: process jobs with simulated 500ms email send, retry 3 times with exponential backoff on failure, then move to DLQ. Implement idempotent processing using Redis SET to track processed job IDs for 24 hours. Webhook: if webhookUrl is provided, POST result to that URL signed with HMAC-SHA256. Status: GET /notifications/:jobId returns current job state and error message if failed. Admin: GET /admin/dlq returns all dead-lettered jobs with failure reasons. Demonstrate both polling and webhook delivery flows end to end.
