Implementing Asynchronous Processing
1. Using Message Queues
| Choice | Use |
|---|---|
| RabbitMQ | Work queues, routing |
| SQS | Managed, simple |
| Kafka | Streams, ordered partitions |
| NATS JetStream | Lightweight, persistent |
2. Implementing Background Jobs
| Tool | Detail |
|---|---|
| Spring @Async / @Scheduled | In-process |
| Quartz | Distributed cron |
| Sidekiq / Celery / BullMQ | Per ecosystem |
| Practice | Idempotent + retry + DLQ |
3. Using Event-Driven Processing
| Aspect | Detail |
|---|---|
| Producers | Publish facts |
| Consumers | React independently |
| Decouples | Time and team |
4. Implementing Worker Pools
| Param | Guidance |
|---|---|
| Pool size | CPU-bound: cores; IO-bound: higher |
| Queue bound | Avoid OOM |
| Reject policy | CallerRuns / abort + alert |
5. Managing Long-Running Operations
| Pattern | Detail |
|---|---|
| 202 + status URL | Client polls |
| Webhook | Push when done |
| Operation resource | RFC operations/{id} |
| Cancellable | Expose DELETE |
6. Using Webhooks
| Practice | Detail |
|---|---|
| Sign payload | HMAC + timestamp |
| Retry w/ backoff | 2xx = success |
| At-least-once | Receivers must dedupe |
| Replay UI | Manual redelivery |
7. Implementing Polling vs Push Mechanisms
| Approach | When |
|---|---|
| Polling | Simple, firewall-friendly |
| Long polling | Lower latency than poll |
| SSE | Server → client stream |
| WebSocket | Bidirectional |
| Webhook | Server-to-server push |
8. Managing Job Queues
| Element | Detail |
|---|---|
| Priority queues | Critical first |
| Delayed jobs | Schedule future |
| Visibility timeout | Re-deliver if not ack'd |
| DLQ | After N failures |
9. Implementing Status Tracking
| Field | Detail |
|---|---|
| State | queued → running → done/failed |
| Progress | 0–100% optional |
| Result URL | When complete |
10. Handling Async Failures
| Strategy | Detail |
|---|---|
| Retry w/ jitter | Exp. backoff |
| DLQ + alert | Inspect & reprocess |
| Poison pill | Move out of band |
| Compensating action | Saga step undo |
11. Implementing Async Request-Reply
| Element | Detail |
|---|---|
| Reply queue | Per-client temp queue |
| Correlation ID | Match reply to request |
| Timeout | Cancel waiter |
12. Using Async Processing Tools
| Tool | Use |
|---|---|
| Temporal / Cadence | Durable workflows |
| Step Functions | AWS-managed orchestration |
| Camunda / Zeebe | BPMN engines |
| Kafka Streams / Flink | Stream processing |