Keep a failing dependency from taking you down
Compose timeout, retry, and a circuit breaker so a degraded upstream fails fast instead of hanging every caller.
Task
A downstream API starts timing out and erroring. Retrying alone just piles more load on something already struggling, and a hung request ties up a caller indefinitely. You want bounded calls, a few smart retries, and a breaker that stops hammering a dependency that is clearly down.
Example
One way: layer timeout, retry, and circuit on a single stitch.
import { } from 'stitchapi';
const = ({
: 'https://api.example.com',
: '/orders',
: { : '10s', : '3s' },
: { : 3, : [429, 503], : 'expo-jitter' },
: { : 5, : 30_000 },
});
const = await ();How it works
Three layers compose. timeout bounds each
attempt (3s) and the whole call (10s) with a real AbortSignal, so a hung
request is actually cancelled, not leaked. retry
recovers transient 429/503s with jittered backoff inside that budget.
circuit watches the failures: after
five consecutive it trips open and calls fast-fail for 30 seconds
(STITCH_CIRCUIT_OPEN) instead of hammering
a dead dependency, then lets a single trial call probe recovery. Together: a blip
is retried, a hang is cut, and an outage stops being yours to absorb. All three
report on the event stream (phases retry,
circuit).