Script Valley
System Design: APIs, Caching & Scalability
Message Queues and Async Processing/Assessment

Practice & Assessment

Test your understanding of Message Queues and Async Processing

Multiple Choice Questions

6
1

A 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?

2

What is the purpose of a Dead Letter Queue (DLQ)?

3

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?

4

A webhook server sends a POST to your callback URL. How do you verify it is genuinely from the expected sender?

5

When should you use pub/sub over a job queue?

6

A client polls GET /jobs/abc-123 every 100ms waiting for a result that takes 30 seconds. What is the main problem?

Coding Challenges

1
1

Async 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.

Medium

Mini Project

1

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.

Hard
Practice & Assessment โ€” Message Queues and Async Processing โ€” System Design: APIs, Caching & Scalability โ€” Script Valley โ€” Script Valley