Q31: Why does Node.js core HTTP client lack built-in DNS caching and how do you resolve it?
Node.js core http.request() resolves DNS hostnames on every single request using dns.lookup(), which executes system calls on the Libuv thread pool without caching results. Under heavy HTTP traffic, this can stall worker threads and cause socket bottlenecks. Developers mitigate this by using custom HTTPS Agents with lookup caching packages (e.g., dnscache) or keep-alive sockets.
Key Takeaways
- Core HTTP clients perform fresh DNS lookups per request without caching.
- Absence of DNS caching causes thread pool saturation; fix using persistent agents or lookup caching modules.
Knowledge Check
Which core subsystem handles dns.lookup() system resolution calls in Node.js?