Demonstration article / / 1 min read
Retry Budgets for Background Jobs
A practical model for bounding retries during partial failures and smoothing recovery.
Classify errors before retrying
A retry is useful when a dependency is likely to recover. Validation errors, unsupported message formats, and missing prerequisites need a different workflow. Include a stable reason in the terminal job record so an operator can diagnose and address the issue.
Limit the total work
Give a job an attempt cap and a time budget. The first controls how many times a job is executed. The second limits how long it remains eligible for retries. Move exhausted jobs to an inspectable terminal state, with a clear process for recovering them once the cause has been addressed.
const delay = Math.min(capMs, baseMs * 2 ** attempt);
const nextDelayMs = Math.floor(Math.random() * delay);
The spread from jitter reduces the number of workers retrying at the same instant. Use a deterministic random source in tests so that failures are repeatable.
Watch recovery as well as failure
Monitor queue age, terminal failures, and the rate of repeated attempts. Replay a small, representative batch when a dependency recovers so it has time to stabilize before most queued work resumes.
Read the Queue Relay case study for an example of combining retries with leases.