Inside the event loop

Macrotasks, microtasks, and phases

The event loop runs in phases, each with its own queue of callbacks. You don't need all six for interviews, but you need three plus one rule:

  • Timers β€” runs setTimeout / setInterval callbacks whose time is up.
  • Poll (I/O) β€” retrieves and runs I/O callbacks (a DB reply, an incoming request). This is where most of your code runs.
  • Check β€” runs setImmediate callbacks, right after poll.

These queued callbacks are called macrotasks, and Node runs one per tick of a phase.