Reliability

Timeouts retries and circuit breakers

A deadline bounds how long a caller waits; a retry is another attempt; a circuit breaker temporarily rejects calls when a dependency is unhealthy. Together these mechanisms can limit cascading failures when configured around a real operation contract. Use an AbortSignal when the underlying API cooperates. A Promise.race timeout alone does not cancel its losing operation. Retry only classified transient failures for safe/idempotent operations, with a total deadline, maximum attempts and jittered backoff. A breaker typically transitions closed to open, then permits a limited half-open probe before closing or reopening. Bulkheads limit concurrent work; load shedding rejects excess work instead of accumulating an unbounded queue. These policies are not a guarantee of success. Do not retry validation failures or assume an expired request never caused a side effect. Avoid testing actual backoff by relying on arbitrary elapsed times. Sources: https://nodejs.org/download/release/v22.16.0/docs/api/errors.html.

Formal Syntax & Structure

nodejs syntaxnodejs
AbortSignal.timeout(ms); signal.aborted

Working Example

Example Snippetnodejs
import {setTimeout as delay} from 'node:timers/promises';import assert from 'node:assert/strict';const controller=new AbortController();const task=delay(1000,'done',{signal:controller.signal});controller.abort();await assert.rejects(task,{name:'AbortError'});console.log('cancelled');
Node.js Reference