Reuse connections for outbound HTTP
A new TLS handshake per request costs a round trip or three. Node's fetch reuses connections by default through undici. The older http module does not unless you give it an agent.
import { Agent, setGlobalDispatcher } from "undici";
setGlobalDispatcher(new Agent({ keepAliveTimeout: 10_000, connections: 64 }));Check with the curl -w timings: if connect and tls are non-zero on every call from your service, connections are not being reused.
httpperformance