How does Node.js handle concurrency on a single thread?
Through the event loop and non-blocking I/O. Async operations are delegated to libuv, so the thread processes other requests while waiting. When operations complete, their callbacks are queued and processed one at a time by the event loop.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in How the Node.js Event Loop Handles Concurrency on a Single Thread
No. Node.js handles many concurrent connections. The JavaScript code runs on one thread, but I/O operations are delegated to libuv, so the thread is free to process other requests while waiting for I/O to complete.
Because it uses far less memory than thread-per-request. One thread serves thousands of connections, since the thread is never blocked waiting for I/O. The trade-off is that CPU-heavy work on the main thread blocks everything.
When a callback does heavy synchronous computation, it blocks the event loop and all connections. This is the main scalability concern in Node.js, and why you must keep the main thread non-blocking by offloading CPU-heavy work.
Still have questions?
Browse all our FAQs or reach out to our support team
