Follow the request through retrieval and ranking

In a two-stage recommender, retrieval narrows a large catalog to a candidate set. Ranking scores that smaller set with a more expensive model. A practical serving path may also fetch features, queue requests for inference, and apply final business rules. Google describes the retrieval-and-ranking split in Deep Neural Networks for YouTube Recommendations.

Here is a synthetic trace for a single request. The two retrieval calls run in parallel, and feature fetching starts when both return. Every other stage in this example runs in sequence.

One request from arrival to response
StageIntervalDuration
Parse request0–2 ms2 ms
Retrieve candidates, source A2–10 ms8 ms
Retrieve candidates, source B2–20 ms18 ms
Fetch ranking features20–25 ms5 ms
Wait for ranker25–31 ms6 ms
Run ranker on GPU31–35 ms4 ms
Apply final rules and respond35–37 ms2 ms

The request takes 37 ms. Source B sets the retrieval time because it finishes last. Making source A twice as fast leaves this request at 37 ms. Cutting 6 ms from source B saves 6 ms end to end, assuming the other stages stay fixed. Halving ranker execution saves 2 ms under the same assumption.

Read traces from the slow requests

Track end-to-end p50, p95, and p99, then look at individual traces from the slow tail to see which spans delayed those requests. Stage percentiles describe different distributions and cannot be added to recover the overall p99. When requests fan out, occasional slow responses can become a consistent user-facing problem. See Google’s The Tail at Scale.

Instrument retrieval and feature calls separately. For the ranker, capture when a request enters the queue, when its batch starts, and when its result is available. This makes it possible to investigate whether a slow request waited for capacity, waited for a batch, or spent its time on device. OpenTelemetry’s guide to traces describes how spans represent these operations across a request.

Change one part of the path and measure again

If the batch queue dominates, compare batch size and maximum queue delay under both light and busy traffic. Batching can raise throughput, while waiting to form a batch can add latency at lighter loads. See the Triton dynamic batching guide for a concrete implementation.

If ranking time grows with the candidate set, try changing the retrieval limit and measure both latency and the effect on ranking quality. Keep the input mix and offered load comparable across runs, and check sustained throughput, timeouts, and the tail of end-to-end latency. A trace tells you which experiment to run. The service metrics tell you whether it helped.