Skip to content

fix(queues): add jitter to exponential backoff retry delay - #16579

Open
brone1323 wants to merge 1 commit into
payloadcms:mainfrom
brone1323:fix/exponential-backoff-jitter
Open

brone1323 wants to merge 1 commit into
payloadcms:mainfrom
brone1323:fix/exponential-backoff-jitter

Conversation

@brone1323

Copy link
Copy Markdown

What

Adds decorrelated jitter (±50%) to the exponential backoff delay in calculateBackoffWaitUntil.

Before:

waitUntil = new Date(now.getTime() + Math.pow(2, totalTried) * delay)

After:

const baseDelay = Math.pow(2, totalTried) * delay
// Add decorrelated jitter (±50%) to prevent thundering-herd retry storms
// when many concurrent jobs fail at the same time.
const jitter = baseDelay * (0.5 + Math.random() * 0.5)
waitUntil = new Date(now.getTime() + jitter)

Why

When many concurrent jobs fail at the same time (e.g. a downstream service goes down), deterministic exponential backoff causes them all to retry at exactly the same intervals — creating a "thundering herd" that repeatedly hammers the backend in synchronized waves.

Adding ±50% jitter to the base delay breaks the synchronization and spreads retries across time, which is standard practice recommended by AWS, Google Cloud, and most distributed-systems resilience libraries.

  • fixed backoff type is not affected — it continues to use the exact delay as configured.
  • The exponential growth curve is preserved; only the variance around it changes.
  • No new dependencies. No API changes.

Closes #16318

Prevent thundering-herd retry storms when many concurrent jobs fail
simultaneously. Applies ±50% decorrelated jitter to the exponential
base delay so retries are spread across time rather than all firing
at the same predictable intervals.

Fixed backoff type is unaffected.

Closes payloadcms#16318
@github-actions

Copy link
Copy Markdown
Contributor

Pull Request titles must follow the Conventional Commits specification and have valid scopes.

Unknown scope "queues" found in pull request title "fix(queues): add jitter to exponential backoff retry delay". Scope must match one of: cpa, claude, codemod, db-*, db-d1-sqlite, db-mongodb, db-postgres, db-vercel-postgres, db-sqlite, db-d1-sqlite, drizzle, email-*, email-nodemailer, email-resend, eslint, evals, graphql, kv, kv-redis, live-preview, live-preview-react, live-preview-vue, next, payload-cloud, plugin-cloud, plugin-cloud-storage, plugin-ecommerce, plugin-form-builder, plugin-import-export, plugin-mcp, plugin-multi-tenant, plugin-nested-docs, plugin-redirects, plugin-search, plugin-sentry, plugin-seo, plugin-stripe, richtext-*, richtext-lexical, sdk, skills, storage-*, storage-azure, storage-gcs, storage-r2, storage-uploadthing, storage-vercel-blob, storage-s3, translations, ui, templates, examples(/(\w|-)+)?, deps.

feat(ui): add Button component
^    ^    ^
|    |    |__ Subject
|    |_______ Scope
|____________ Type

@github-actions github-actions Bot added the stale label Jun 14, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add jitter to exponential backoff in job queue retry

1 participant