Skip to content

[feat] Add configurable jitter strategy (full, equal, decorrelated, none) to backoff calculations #48

Open

Description

@AryanSharma48

Description:

Problem

Currently:

  • smooth-api-ts hardcodes Equal Jitter (half + Math.random() * half).
  • smooth-api-py hardcodes Full Jitter (random.uniform(0, capped)).
    Users cannot configure deterministic backoff for testing or choose their preferred jitter distribution algorithm.

Proposed Solution

  1. Add jitter?: 'full' | 'equal' | 'decorrelated' | 'none' to BackoffConfig in both TypeScript and Python.
  2. Implement standard AWS-style jitter algorithms:
    • none: Deterministic exponential ($base \times 2^{attempt}$) capped at $maxDelay$.
    • full: Random value between $0$ and $capped$.
    • equal: $half + \text{rand}(0, half)$.
    • decorrelated: $min(maxDelay, \text{rand}(baseDelay, prevDelay \times 3))$.
  3. Default to equal across both packages for parity.

Acceptance Criteria

  • BackoffConfig updated in packages/smooth-api-ts/src/types.ts and packages/smooth-api-py/smooth_api/config.py.
  • calculateBackoff / calculate_backoff updated in both packages.
  • Unit tests added verifying that calculated delays stay strictly within [0, maxDelay] bounds for all 4 strategies.

References

Activity

  1. shreyansh0207 commented on Sep 10, 2026

    @shreyansh0207
    Contributor

    Hi @AryanSharma48, apologies — I forked the repo and implemented this directly instead of commenting first to ask. I've opened a PR with the TypeScript implementation: #53

    Summary of what I did:

    • Added jitter field to BackoffConfig in types.ts
    • Implemented all 4 strategies (none, full, equal, decorrelated) in calculateBackoff
    • Added prevDelay tracking in the retry loop so decorrelated jitter works correctly
    • Added unit tests covering all 4 strategies, verifying delays stay within [0, maxDelay]

    I focused on TypeScript only for now — happy to implement the Python side (smooth-api-py) as well if you'd like, just let me know! And let me know if you'd prefer I follow a different process next time.

  2. AryanSharma48 commented on Sep 10, 2026

    @AryanSharma48
    OwnerAuthor

    @shreyansh0207 No worries! Just a good thing to get assigned first as it removes possibility of 2 people working on the same issue!

    The implementation was good, ive left some comments regarding some nitpicks. Have a look at them and you can proceed with the python implementation as well!

  3. changed the title [-]feat(core): Add configurable jitter strategy (`full`, `equal`, `decorrelated`, `none`) to backoff calculations[/-] [+][feat] Add configurable jitter strategy (`full`, `equal`, `decorrelated`, `none`) to backoff calculations[/+] on Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions