mediumConceptMidSeniorStaff
Walk me through the phases of the Node event loop.
Node.js event loop phases explain callback ordering across timers, poll, check, nextTick and promise microtasks. Correct answers separate macro-task phases from microtasks instead of memorising one log order.
4 min readUpdated 2026-08-15
Answer
Short answer
Timers, I/O callbacks and setImmediate run in event loop phases, while process.nextTick and promise microtasks drain between turns. Use that model to predict callback order and avoid starving I/O with unbounded microtasks.
Was this answer helpful?
Likely follow-ups
- In what order would a promise callback, a setTimeout, a setImmediate and a process.nextTick run?
- Why is setTimeout versus setImmediate non-deterministic in the main module but deterministic inside an I/O callback?
- What happens if a process.nextTick callback recursively schedules another nextTick?
- Where do worker threads help with a blocked loop and where do they not?
- How does an async function's await interact with the microtask queue compared to a .then chain?
Related questions
- A promise rejects and nothing is awaiting it. What does Node do?hardAlso on async and microtasks4 min
- Your Node service has low CPU but latency spikes for every request at the same moment. What is happening?mediumAlso on event-loop and performance4 min
- Here is a script mixing setTimeout, a promise chain and an await. Tell me the order the logs come out in, and why.mediumAlso on event-loop and microtasks4 min
- You kick off background work from a controller action and it throws once the response has gone out. What is happening?mediumAlso on async5 min