# Compute a backoff delay with full jitter

Double the window on every attempt, cap it, then pick a point inside it.

Canonical: https://1loc.dev/email/compute-an-exponential-backoff-delay/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function backoffMs({ attempt, baseMs, capMs, random }) { return Math.round(random * Math.min(capMs, baseMs * 2 ** attempt)); }
```

## Input

```json
{
  "attempt": 3,
  "baseMs": 500,
  "capMs": 30000,
  "random": 0.5
}
```

## Expected output

```json
2000
```

## Edge case

Input:
```json
{
  "attempt": 20,
  "baseMs": 500,
  "capMs": 30000,
  "random": 0.999
}
```
Output:
```json
29970
```

## Limits

- random is an input so the result is testable; pass Math.random() in production. Honor a Retry-After header when the server sends one.
- Every attempt must reuse the same idempotency key: Oveyon deduplicates a saved key for 24 hours, so a late retry does not send twice.

The lab validates types and size before calling this function. Add equivalent validation at your own trust boundary.

## Source and license

Author: Oveyon, written for this edition; not part of the original 1loc collection.
Copyright (c) 2026 Oveyon
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
