Course contentsShow
← Node.js
Lesson 1711 of 1,98015. Logging, Observability, and MetricsFree lesson

Visualizing Request Flows

Examine waterfall diagrams to identify the slowest steps in a multi-service transaction.

In this lesson, you will learn how to analyze waterfall diagrams to pinpoint latency bottlenecks within a distributed, multi-service Node.js architecture.

Anatomy of a Waterfall Diagram

When you instrument your Node.js application with distributed tracing, each incoming request is assigned a traceId. As that request traverses your microservices—moving from an API Gateway to an Auth service, then to a Database, and finally to a cache—every unit of work is captured as a span.

A waterfall diagram is a temporal visualization of these spans. It stacks them vertically, showing their start and end times relative to the total request duration. By examining the horizontal length of these bars, you can instantly spot "stair-stepping" patterns that reveal where your execution is stalled.

Identifying the Bottleneck

To identify the slowest step, look for the critical path: the continuous, uninterrupted chain of spans that dictates the total response time.

Consider this scenario:

  1. Service A (Gateway) calls Service B (Auth): 20ms
  2. Service B performs internal logic: 50ms
  3. Service B calls Service C (Database): 300ms
  4. Service C returns to Service B: 310ms (cumulative)

In the waterfall view, you will see a massive gap in the row for Service B that aligns perfectly with the duration of the call to Service C. If the bars for your database query or external API call span nearly the entire length of the parent trace, you have found your bottleneck.

Why This Matters

Raw metrics like P99 latency tell you that a system is slow, but they don't tell you where. Waterfall diagrams provide the "why." If you see a long gap between two spans in a waterfall, it often indicates asynchronous overhead, context switching, or time spent waiting for a connection pool—issues that standard logs or counter-based metrics often obscure.

By analyzing these flows, you move beyond guessing whether the slowness is in your code or your infrastructure, allowing you to focus your optimization efforts on the specific dependency causing the request to drag.

Key Takeaway: The waterfall diagram allows you to visualize the critical path of a request, turning abstract latency metrics into a clear map of which service or dependency is consuming the most time.