ObservabilityIntermediate

Here is a trace of a slow request. Read it to me.

“A trace shows: Gateway 20 ms → User Service 35 ms → Order Service 180 ms, and inside Order Service a Database span of 140 ms. What do you conclude, what do you check next, and how did the trace id get from the gateway to the database span?”

What this tests

  • Reading a span tree: self time vs child time, serial vs parallel
  • Recognising patterns: N+1, serial fan-out, slow single query
  • Context propagation (W3C traceparent) and instrumentation boundaries
  • What a trace cannot tell you and where you go next

Answers by level

Read the beginner answer first and notice what is missing.

Total is roughly 235 ms if the calls are serial; the Order Service span is 180 ms, of which 140 ms is one database child span, so Order Service has 40 ms of self time and the database is where the time is. But "140 ms database span" hides the shape: expand it. If it is one span, it is one slow query — look at its statement and plan. If it is 38 short spans of 3–4 ms in sequence, it is an N+1 across a service boundary, and the fix is a batched query, not an index. The trace shows serial vs parallel: sequential child spans stacking end to end is the signature.

The trace id travelled in the traceparent header: the gateway created the trace, each HTTP client injected the header, each server extracted it and created a child span, and the database client library wrapped the query call in a span under the current context. If any hop is not instrumented, the tree breaks there and you see an orphan — see Distributed Tracing.

Green flags · Red flags

Strong green flag · Asks whether the User Service call is on the critical path and whether the slow shape is conditional on request data.
Green flags
  • Computes self time vs child time and asks whether calls are serial
  • Expands the database span and names the N+1 signature
  • Explains traceparent injection/extraction hop by hop
  • Knows where the trace stops and reaches for database tools
  • Compares against a fast trace of the same endpoint
Red flags
  • "The database is slow, add an index." — without looking at the number of spans
  • Cannot say how the trace id reaches the next service
  • Assumes the trace shows what the database did internally
  • Does not distinguish one 140 ms query from 38 × 3.7 ms queries

Follow-up questions

F1
The database span turns out to be 38 sequential 3.7 ms queries. Fix?
F2
The work continues in a background job and the trace stops at the enqueue. Why?
F3
Could you find this N+1 with metrics alone?

Scenario

Support escalates one slow order page: 2.3 s. The trace shows Gateway 12 ms, Auth 20 ms, Order Service 2,240 ms containing 61 database spans of 30–40 ms each, in sequence, one per line item. The team's first proposal is a bigger database instance. Read the trace aloud, explain what it rules out, and specify the fix.

Learn this topic