Skip to content

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

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

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