Articles
High Level Design
Technology Deep Dive
Node.js Event Loop
Overview
๐Ÿ”„

Node.js Event Loop

A first-principles course on the Node.js event loop โ€” from why a single thread needs it, through the phases, queues, timers, microtasks, libuv and the thread pool, all the way to a single master mental model for predicting any program's output.

16 Modules
๐Ÿ“ Modules

Module 01 โ€” Foundations

Why JavaScript's single thread makes blocking fatal and how non-blocking APIs offload the wait โ€” the motivation behind the event loop.

Aug 12, 20269 min read

Module 03 โ€” Node.js Architecture

The pieces that make up Node.js โ€” V8, core bindings, libuv, and the OS โ€” and the boundary between single-threaded JS and native land.

Aug 13, 20266 min read

Module 04 โ€” The Event Loop from First Principles

The event loop is just a C while-loop that runs ready callbacks โ€” trace one async operation from JavaScript call to callback.

Aug 14, 20266 min read

Module 05 โ€” Event Loop Phases

The six phases, the four libuv queues, the two microtask queues, and the exact priority order that governs async execution.

Aug 17, 20267 min read

Module 06 โ€” Timers

What setTimeout(fn, 0) really means โ€” timers as a minimum-delay promise, the min-heap, clamping to 1 ms, and why callbacks fire late.

Aug 18, 20265 min read

Module 07 โ€” The Poll Phase

The poll phase โ€” where I/O callbacks run and the only phase that can sleep, deciding whether to wait for the OS or move on.

Aug 19, 20266 min read

Module 08 โ€” setImmediate and the Check Phase

How setImmediate and the check phase work, why it differs from setTimeout(fn, 0), and the ordering inside I/O callbacks.

Aug 20, 20265 min read

Module 09 โ€” Microtasks

The microtask VIP lane โ€” nextTick, Promises, and queueMicrotask, their priority order, and how a recursive nextTick can freeze the loop.

Aug 21, 20269 min read

Module 11 โ€” Promises and async-await

How async/await desugars into Promises and microtasks โ€” code before the first await runs synchronously, the rest as a microtask.

Aug 13, 20265 min read

Module 12 โ€” Complete Execution Traces

Eight verified Node programs traced step by step โ€” call stack, every queue, and the active phase โ€” from basics to async/await and I/O.

Aug 13, 20267 min read

Module 14 โ€” libuv Deep Dive

How libuv gives Node a cross-platform event loop, thread pool, and async I/O โ€” and how handles vs requests keep the loop alive.

Aug 13, 20266 min read

Module 15 โ€” The Thread Pool

Which Node operations borrow libuv's worker threads, why 'single-threaded' is only half true, and how the default pool size of 4 shows up.

Aug 13, 20265 min read

Module 16 โ€” Event Loop Starvation

How one long or looping callback freezes the entire event loop, and how to chunk work with setImmediate to stay responsive.

Aug 13, 20266 min read

Module 17 โ€” Node.js Concurrency Model

Event loop vs thread pool vs Worker Threads vs Cluster โ€” Node's four concurrency mechanisms and when to reach for each.

Aug 12, 20265 min read

Module 18 โ€” Production Engineering

How event-loop behavior shapes real server latency, plus the Node tools to measure loop delay and utilization in production.

Aug 13, 20268 min read

Module 20 โ€” The Master Mental Model

A single-page master model of the event loop โ€” phases, queue priorities, the thread pool, and the rules to predict any output.

Aug 13, 20266 min read