Skip to content

feat: Add Exponential Backoff With Jitter on Retry - #17

Merged
ThomasHartDev merged 3 commits into
mainfrom
thomas/feat/retry-backoff
Sep 4, 2026
Merged

feat: Add Exponential Backoff With Jitter on Retry#17
ThomasHartDev merged 3 commits into
mainfrom
thomas/feat/retry-backoff

Conversation

@ThomasHartDev

Copy link
Copy Markdown
Owner

Work-queue nack used to requeue immediately, and the pump could hand the same payload back in the same tick. That is a retry storm: every failing consumer wakes together and hammers a dependency that is already unhappy.

A nack or handler throw now waits before redelivery. For none, full, and equal jitter the wait is min(cap, base * 2^(attempt-1)), then jitter (full by default). Decorrelated ignores attempt and walks lastDelayMs: the next delay is drawn between base and min(cap, last * 3). Other ready work still goes out while a retry sits on the delayed list. Pass retryBackoff: false when you want the old immediate requeue. Tests drive this with ManualClock so we do not sleep.

The package barrel also re-exports DeadLetterQueue so existing tests that import those names from src/index keep typechecking.

Closes #16.

Nack and handler throw wait min(cap, base * 2^(attempt-1)) before
redelivery, with full/equal/decorrelated jitter so retries do not
align. A delayed retry list keeps other ready work moving.
Omitted retryBackoff now has a nack-and-wait test so the constructor
default cannot flip silently. README usage nacks, advances ManualClock,
then shows redelivery. Decorrelated lastDelayMs is spelled out and
covered at the queue.
@ThomasHartDev
ThomasHartDev force-pushed the thomas/feat/retry-backoff branch from 2424870 to 3f1c456 Compare September 4, 2026 20:32
@ThomasHartDev
ThomasHartDev merged commit e0f279a into main Sep 4, 2026
1 check passed
@ThomasHartDev
ThomasHartDev deleted the thomas/feat/retry-backoff branch September 4, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exponential backoff with jitter on work-queue retry

1 participant