When a single connection is not enough, undici offers three pooling strategies.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nodejs/undici/llms.txt
Use this file to discover all available pages before exploring further.
Pool manages multiple connections to a single origin and selects the first available one. BalancedPool spreads requests across multiple origins using a round-robin algorithm. RoundRobinPool connects to a single origin but cycles through connections evenly — useful when the origin sits behind a load balancer that distributes TCP connections across backend servers.
All pool classes extend Dispatcher. Methods (request, stream, pipeline, dispatch, connect, upgrade, close, destroy) and events (connect, disconnect, drain) are the same as those documented in the Dispatcher reference.
Pool
Pool creates a set of Client instances to a single origin and dispatches each incoming request to the first available client.
new Pool(url, options?)
The origin URL (protocol, hostname, port only).
Maximum number of
Client instances. When null, the pool creates
connections on demand without limit.body.factory
(origin: URL, opts: object) => Dispatcher
default:"(origin, opts) => new Client(origin, opts)"
Custom factory for creating each connection. Useful when you need to
decorate individual clients with interceptors.
Milliseconds before an idle
Client instance is removed from the pool and
closed. When null, clients live until the pool is closed.ClientOptions are also accepted and forwarded to each Client instance created by the pool.
Basic Pool usage
Pool with a custom client factory
Properties
true after pool.close() has been called.true after pool.destroy() has been called or close has completed.Aggregate statistics across all clients in the pool.
BalancedPool
BalancedPool accepts multiple origin URLs and distributes requests across them in a round-robin fashion. Each origin is backed by a Pool instance. You can add and remove origins at runtime.
new BalancedPool(upstreams, options?)
One or more origin URLs (protocol, hostname, port only).
body.factory
(origin: URL, opts: object) => Dispatcher
default:"(origin, opts) => new Pool(origin, opts)"
Custom factory for creating each per-origin
Pool.PoolOptions are accepted and forwarded to each Pool instance.
BalancedPool across multiple origins
Methods
In addition to the standardDispatcher methods, BalancedPool provides:
balancedPool.addUpstream(upstream)
Adds a new origin to the pool at runtime.
Origin URL to add (protocol, hostname, port only).
balancedPool.removeUpstream(upstream)
Removes a previously-added origin. In-flight requests to that origin complete normally.
Dynamic upstream management
Properties
Current list of upstream origin URLs.
Aggregate stats across all origin pools (same structure as
Pool.stats).RoundRobinPool
RoundRobinPool connects to a single origin but maintains multiple connections and cycles through them in round-robin order. Unlike Pool (which picks the first available connection), RoundRobinPool distributes requests evenly across all connections. This matters when the single origin hostname is backed by a load balancer that assigns each TCP connection to a different backend server.
new RoundRobinPool(url, options?)
The origin URL (protocol, hostname, port only).
Number of
Client instances to create. When null, connections are created
on demand.body.factory
(origin: URL, opts: object) => Dispatcher
default:"(origin, opts) => new Client(origin, opts)"
Custom factory for each connection.
Milliseconds before an idle
Client is removed and closed.ClientOptions are also accepted.
RoundRobinPool in a Kubernetes environment
Properties
Aggregate stats across all connections (same structure as
Pool.stats).When to use Pool vs Agent
| Scenario | Recommended class |
|---|---|
| Single origin, multiple connections | Pool |
| Single origin, round-robin over load balancer | RoundRobinPool |
| Multiple origins, round-robin | BalancedPool |
| Dynamic set of origins | Agent |