Skip to content

feat: add computeRetryDelay helper for backoff with jitter (#585)#593

Open
toniasteve15-ui wants to merge 1 commit into
accesslayerorg:mainfrom
toniasteve15-ui:feat/585-retry-delay-helper
Open

feat: add computeRetryDelay helper for backoff with jitter (#585)#593
toniasteve15-ui wants to merge 1 commit into
accesslayerorg:mainfrom
toniasteve15-ui:feat/585-retry-delay-helper

Conversation

@toniasteve15-ui

Copy link
Copy Markdown

#closes #585

Add helper for computing the next retry delay using exponential backoff with jitter

Closes #585

Description

This PR introduces a shared utility helper to compute exponential backoff delays with jitter. This prevents repeated simultaneous webhook and alert delivery attempts by randomizing retry timers across distributed tasks.

Summary

Webhook retries and alert delivery retries both utilize exponential backoff, but each previously calculated this delay independently without unified jitter distribution. This shared helper uniformly applies exponential backoff with a randomized jitter, replacing inline independent calculations.

Scope Covered

  • Added computeRetryDelay(attempt, baseMs, maxMs) in src/utils/retry-delay.utils.ts.
  • Computes min(baseMs * 2^attempt, maxMs).
  • Implements randomized jitter scaling up to 20% of the computed delay limit.
  • Ensures the final output strictly never exceeds maxMs, even when jitter is maximally applied.
  • Added 5 Jest unit tests verifying lower boundaries, doubling backoff logic, and maxMs hard ceilings.

Acceptance Criteria Met

  • Delay doubles with each attempt up to maxMs
  • Jitter is added within 20% of the computed delay
  • Delay never exceeds maxMs
  • Attempt 0 returns approximately baseMs

Testing Instructions

Run the unit test suite locally:

pnpm test src/utils/__tests__/retry-delay.utils.test.ts

#closes

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.

Add helper for computing the next retry delay using exponential backoff with jitter

2 participants