What is connection pooling for HTTP requests in Node.js?

Answer

HTTP connection pooling (keep-alive connections) reuses existing TCP connections for multiple HTTP requests to the same server, avoiding the overhead of TCP handshake and TLS negotiation for every request. Node.js's built-in http/https modules support this via http.Agent. By default, Node.js uses a global agent with keep-alive disabled (or limited). For high-throughput outbound HTTP requests: const agent = new https.Agent({ keepAlive: true, maxSockets: 50, maxFreeSockets: 10, timeout: 60000 }); const response = await fetch(url, { agent });. The axios library uses keep-alive by default. undici — the newer, high-performance HTTP client in Node.js core — uses connection pools internally and is much faster than the older http module. Key settings: maxSockets (max concurrent connections per host — higher increases throughput but consumes server resources), keepAlive (reuse TCP connections), and timeout (idle socket timeout). For microservices making many outbound calls, proper pool tuning can significantly reduce latency and CPU usage.