Core Fundamentals• 30 Min
Managing Long-Running Background Tasks
MEDIUM
Managing Long-Running Background Tasks
Operations like generating complex tax PDF reports, running ML model inference, or exporting database backups take seconds to minutes, making synchronous HTTP request/response loops unfeasible.
1. Asynchronous Job Lifecycle Pattern
- Submit: Client sends
POST /reports/generate. - Accept (202 Accepted): Server enqueues job into Kafka / SQS and returns
HTTP 202 Acceptedwith aLocation: /reports/status/{job_id}header. - Execution: Celery / Temporal worker consumes the job, updating status in Redis.
- Completion Delivery:
- Client Polling: Client polls status endpoint every 2 seconds with exponential backoff.
- Server-Sent Events (SSE): Server pushes real-time progress percentages (
progress: 75%). - Webhooks: For B2B integrations, server executes an HTTP POST to the client's webhook endpoint upon job completion.
Key Architecture Trade-Offs & Decision Matrix
| Decision Factor | Choice A | Choice B | Selected Architectural Rationale |
|---|---|---|---|
| Communication Protocol | REST over HTTP/2 | WebSockets / gRPC | Use REST for stateless CRUD APIs; use WebSockets for low-latency bidirectional streaming. |
| State Management | Centralized Distributed Store | Local Memory with Sticky Sessions | Centralized Redis / Database state allows seamless container auto-scaling and zero-downtime rolling deploys. |
| Concurrency Control | Optimistic Locking (version column) | Pessimistic Locking (SELECT FOR UPDATE) | Optimistic locking delivers superior throughput for low-conflict consumer operations. |
Related Topics
Expand your knowledge by learning about adjacent concepts in system design.
Core FundamentalsMEDIUM
Consistent Hashing Architecture & Implementation
Deep dive into consistent hashing algorithms, virtual nodes, token rings, and minimal key remapping during cluster resizing in distributed databases.
Core FundamentalsMEDIUM
Networking Essentials
Learn the important parts of networking that you'll need to know for your system design interviews
Core FundamentalsMEDIUM
API Design
Master API Design for distributed systems and FAANG interviews: REST vs GraphQL vs gRPC, idempotency keys, cursor pagination, 202 async jobs, security, and RFC 7807 errors.
Cheat Sheet Utility
View and print a concise system design reference card.