Ch. 6 · Node.js

Node.js Latency Measurement and Event Loop Delay

Node.js Latency Measurement and Event Loop Delay. Learn the reasoning, a practical example, common mistakes and an interview exercise.

~2 min readadvancedupdated Oct 3, 2026

Request latency includes queueing, dependencies and local work. Event-loop delay is one signal, not a complete explanation.

Before you start

You should know JavaScript promises, asynchronous errors and the distinction between a process and a request. When following a server example, identify the resource owner and the point where work completes. Try experiments locally with bounded input instead of assuming production traffic behaves like a single request.

The practical goal is to reason through this situation: Correlate p95 latency with event-loop delay, CPU and upstream timing. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.

Step-by-step walkthrough

Step 1: Measure distributions

Compare median, p95 and p99 latency rather than relying only on an average.

Step 2: Attribute request time

Collect queue, dependency and local-processing spans alongside CPU and event-loop delay.

Step 3: Repeat representative load

Use realistic concurrency and input sizes, then compare the same conditions after changing one suspected bottleneck.

Worked scenario

Correlate p95 latency with event-loop delay, CPU and upstream timing.

A p95 spike with low event-loop delay and long database spans suggests a different bottleneck from a CPU spike delaying all callbacks. Correlation guides the next experiment but does not prove cause. Include errors and throughput in results so apparently faster responses caused by rejecting work are not mistaken for an improvement.

Common mistake

Average latency can hide a small but serious slow-request population.

Verify the behavior

Compare distributions, throughput and failures over equivalent workloads. Check whether the proposed change improves the actual constrained phase.

Interview exercise

Locate a bottleneck.

Answer and reasoning

Compare distributions and trace spans under representative load before applying optimization or increasing concurrency.

Continue learning

Compare the scenario with the Node.js interview questions and test your understanding with the Node.js MCQs. For terminology and implementation details, consult the reference material.

More in Node.js

read ✓Node.js · mid

Node.js Response Compression with zlib

Compress HTTP responses with gzip or brotli streams, negotiate the encoding, and avoid compressing data that is already compressed.

~2 min readread →
read ✓Node.js · hard

Node.js Clustering Across CPU Cores

Use cluster to run several workers on all cores, restart crashed workers, and understand shared-port and shared-state limits.

~2 min readread →
esc