← systems library
async & jobs
Async Job Queue
Background work done right — retries, dead-letters, idempotency, and who owns the broker.
Considerations
- <b>Idempotency keys are mandatory.</b> At-least-once delivery means every job can run twice — dedupe on a key, make writes idempotent.
- <b>Visibility timeout / lease:</b> a job in flight is hidden, not gone. Long tasks must heartbeat or extend the lease or they get re-delivered.
- <b>Retries = exponential backoff + jitter, with a cap.</b> After N attempts the message goes to the DLQ, not into an infinite loop.
- <b>The DLQ is not optional.</b> Alert on its depth, inspect poison messages, and redrive after the fix ships.
- <b>Autoscale on queue depth / oldest-message age, not CPU.</b> That is the signal that you are falling behind.
- <b>Ordering costs throughput.</b> Use FIFO only where business logic truly needs it; keep large payloads out of the queue (store a pointer).
- <b>Observability:</b> queue depth, oldest-message age, processing rate, and failure rate — without these the pipeline is a black box.