Async Programming & Timers Interview Questions (Node.js)
10 Async Programming & Timers questions from the Node.js track. Read each short answer here, then open a question for the full explanation, examples, common mistakes, and sources.
- Junior
What is the practical difference between using async/await and dealing directly with promises in Node.js?
async/await is just syntactic sugar built on top of promises that makes code look like synchronous code, allows error handling with try/catch, and improves the readability of stack traces.
Read the full explanation - Mid-level
Compare Promise.all, Promise.allSettled, and Promise.race in Node.js in terms of behavior and error handling.
Promise.all fails as soon as any promise is rejected, Promise.allSettled waits for all to complete in success and failure, while Promise.race settles its result with the first promise to finish whatever its state.
Read the full explanation - Senior
Why is running hundreds of promises through Promise.all dangerous and how do you apply concurrency limiting?
Running a huge number in parallel drains network ports, file handles, and server memory, and concurrency must be restricted with a limiter (a pool or semaphore).
Read the full explanation - Senior
What is the AsyncLocalStorage technique in Node.js and what problems does it solve in request tracing?
It provides a local context store that lets you share request data (such as the request ID and user) across all asynchronous operations without passing it manually.
Read the full explanation - Mid-level
How does the priority of microtasks differ from macrotasks in task processing in Node.js?
Microtasks run as soon as the current task ends and before any later macrotask, which means the microtask queue is drained completely before advancing through the event loop phases.
Read the full explanation - Mid-level
How do errors travel in asynchronous code and what is the danger of errors inside traditional callbacks?
Promise errors travel through rejection chains, while outer try/catch blocks fail to catch errors inside traditional callbacks, causing the server to crash.
Read the full explanation - Senior
What is the event loop starvation phenomenon caused by CPU-intensive tasks and how do you avoid it?
It happens when a long synchronous computation monopolizes the main thread, preventing I/O and timers from being processed, and it can be avoided by chunking the computation or delegating it to worker threads.
Read the full explanation - Mid-level
What is the top-level await feature in ES modules in Node.js and what are the cautions of using it?
It lets you use await directly at the top level of the file without wrapping it in an async function, and its caution is that it can delay loading dependencies or freeze the app's startup.
Read the full explanation - Senior
How do async iterators and the for await...of loop help consume data streams in Node.js?
They provide a unified API for consuming streamed data item by item or batch by batch, with automatic backpressure and pausing the fetch until the consumption of the item finishes.
Read the full explanation - Senior
What is the concept of async disposable resources and the Symbol.asyncDispose symbol?
A pattern for managing and cleaning up resources automatically (such as network connections and files) when leaving the scope through the await using keyword.
Read the full explanation