Backoff namespace provides composable retry delay strategies for use in Workflow.step retry configuration. Import it directly from @durable-effect/workflow.
Backoff.exponential
Delay grows exponentially:base * factor^attempt.
Signature
Parameters
Starting delay for the first retry. Accepts a duration string (
"1 second")
or milliseconds (1000).Multiplier applied at each attempt. A factor of
2 doubles the delay each
time. Must be greater than 1 for exponential growth.Maximum delay cap. Once the calculated delay exceeds this value, it is
clamped. Accepts a duration string or milliseconds.
Example
Backoff.linear
Delay grows linearly:initial + (attempt * increment).
Signature
Parameters
Delay for the first retry. Accepts a duration string or milliseconds.
Amount added to the delay on each subsequent retry. Accepts a duration
string or milliseconds.
Maximum delay cap. Accepts a duration string or milliseconds.
Example
Backoff.constant
Fixed delay between every retry attempt.Signature
Parameters
Fixed delay between retries. Accepts a duration string (
"5 seconds") or
milliseconds (5000).Example
Backoff.presets
Pre-configured strategies for common scenarios.Presets reference
Exponential backoff starting at 1 second, capped at 30 seconds.
Delays:
1s → 2s → 4s → 8s → 16s → 30s.
Use for most external API calls.Exponential backoff starting at 100ms, capped at 5 seconds.
Delays:
100ms → 200ms → 400ms → 800ms → 1.6s → 5s.
Use for internal services with low latency targets.Exponential backoff starting at 5 seconds, capped at 2 minutes.
Delays:
5s → 10s → 20s → 40s → 80s → 120s.
Use for rate-limited external APIs.Constant 1-second delay between every retry.
Use for polling scenarios or when predictable timing matters.
Example
BackoffStrategy type
TheBackoffStrategy type is returned by all Backoff.* functions and accepted by RetryConfig.delay.
addJitter
Add ±10% randomness to a delay in milliseconds to prevent the thundering herd problem.Signature
Parameters
Base delay in milliseconds to apply jitter to.
Fraction of the delay used as the jitter range. Default
0.1 applies ±10%
randomness. For example, a 1000ms delay with factor 0.1 produces a value
between 900ms and 1100ms.Workflow.step when retry.jitter is true (the default). Use addJitter directly only when building custom retry logic outside of the step primitive.
parseDuration
Parse a human-readable duration string or number to milliseconds.Signature
Parameters
Duration to parse. If a number, it is returned as-is (treated as
milliseconds). If a string, it is parsed using the supported unit suffixes.
Supported formats
Error if the string format is not recognized.