Core Concepts

Backend Observability

Detect slow replies, find where a turn waited, and use correlated events to explain why.

Free~17 min

Observability uses the data a system emits, called telemetry, to work out what happened. Measure the outcome the user waits for, then trace the work that produces it. Logs can explain the decisions the system made along the way.

Measure the reply the user sees

In this example of the ChatGPT design, the browser gets 202 Accepted after 120 ms and first text at 1.74 seconds. These timings are illustrative. The gateway's request chart stops at acceptance. To account for the rest, follow the turn, the work for one reply, through the router, worker, and stream back to the browser.

A metric is a numeric measurement we can aggregate across many operations. To measure first-text latency, the browser starts a timer when the user submits and stops it when the first approved text is visible. Within one page lifetime it can measure elapsed time on its own clock. That includes upload, admission, queueing, model work, and the trip back to the screen.

The service-level indicator (SLI) is the fraction of eligible, measured accepted turns that show first text within 800 ms. Use one outcome per turn even if the browser retries submission or reconnects to the stream. An observed miss of the 800 ms deadline is bad even if no text ever appears. For this example, count an explicit user cancellation before the deadline separately. Some browsers may close or lose the connection before they report an outcome. Measure reporting coverage against accepted turns separately, and treat a drop in coverage as a loss of visibility. Use a scripted browser that periodically submits a prompt along the same path to spot failures the client telemetry missed. Google SRE on implementing SLIs

Availability covers a different failure. Here we track the share of eligible submissions that reach a valid, terminal reply within the product's reply deadline. An unexpected 503 at admission or a stream that fails after displaying the first paragraph counts against availability. Bad user input and explicit cancellation are outside this example's eligibility rules. Classify a valid policy refusal as a handled outcome. Record documented per-account rate limits separately from eligible attempts. That preserves visibility into intentional rejections without counting them as infrastructure failures. A slow turn can eventually finish successfully. A fast start can still end in failure.

Page on the rate of missed outcomes

The service-level objective (SLO) sets a target for that indicator. In this example we aim to show first text within 800 ms on 99% of eligible, measured accepted turns over a rolling 30 days. The remaining 1% is the error budget for the period. It includes latency misses as well as complete failures that miss the latency deadline.

During the incident, 500 of 10,000 eligible, measured turns miss first text within a one-hour window. The bad-event fraction is 5%. Dividing it by the allowed 1% gives a burn rate of 5. A burn rate of 5 means each batch of requests at that miss rate uses five times its share of the budget. The actual budget consumed also depends on how many requests arrive.

Monitoring collects and displays these measurements over time. An alert evaluates a rule and notifies whoever is on call when action is needed. As an illustrative paging rule, require burn above 4 in both the last hour and the last five minutes. The longer window looks for substantial impact, and the short one checks whether it is still happening. If 40 of the last 800 eligible, measured turns missed the deadline, the five-minute burn rate is also 5 and this rule pages.

The on-call engineer can use the alert to open charts for first-text misses, admission errors, time pending, and ready workers, sliced by model pool. Choose real thresholds and windows from the budget, traffic, and response time your team needs. At very low traffic, check the denominator as well as the ratio. A single miss out of one observed turn is a 100% miss rate. Google SRE on alerting on SLOs

For the ratio, combine counts across hosts before dividing. A histogram counts durations in ranges. With matching ranges across hosts we can add bucket counts and estimate p95, the time by which about 95% of measured first-text arrivals had occurred. Averaging each host's p95 gives the same weight to a quiet host as a busy one and can miss the tail of the combined distribution. Use a histogram to see how long slow turns take. Keep a count at 800 ms and record observed turns with no text so the deadline indicator includes them. OpenTelemetry metrics

Follow one slow turn

A span records one operation with a start time and duration. A trace collects spans from the services that handled the same request. A trace view puts the spans along a timeline so we can see when work started and where operations overlap.

The gateway assigns this turn the ID reply-184, which we can look up later in logs. The turn becomes durably pending at 90 ms. The gateway then sends the acceptance, which reaches the browser at 120 ms. A worker claims it at 1,400 ms. That leaves 1,310 ms of queue wait before model work starts. The first approved text appears in the browser at 1,740 ms, 340 ms after the claim. Those final 340 ms cover generation, the text check, and delivery to the browser. In other slow turns, those stages could dominate instead.

Record the pending and claim times at the state transitions so the queue wait is measurable even when workers are idle or a trace is missing. Use comparable timestamps for the two transitions, for example timestamps recorded against the same database clock, with known measurement boundaries. Clocks on separate hosts can disagree. Use a local elapsed timer for measurements on one host and account for clock skew when assembling cross-host timelines. Parent and child spans or parallel operations can overlap, so adding every span duration can overstate elapsed time. OpenTelemetry traces

Carry context through the handoff

In this trace, the submit request finishes before the router dispatches the turn. The router and worker have their own memory. Save trace context, the identifiers and flags needed to relate operations, with the durable turn or in the metadata of a separate work queue. The consumer loads it before starting its own trace work. A span link records a relationship to the earlier span. This lets a separately traced worker attempt refer back to the producer, and a batch can link to several producers. Keep the same turn ID across attempts. Individual requests or worker attempts can have their own span and trace IDs. OpenTelemetry context propagation · OpenTelemetry messaging spans

Find the decision that made it wait

A structured log records an event and named fields that we can filter. Search for turn=reply-184 in the incident's time range. The router's log shows that it found the turn while no worker in the requested pool was ready to accept it. Match that to the trace timing and then look at the pool's readiness chart and rollout events.

gateway  turn.pending       turn=reply-184 pool=P3 trace=g1 span=submit
router   dispatch.deferred  turn=reply-184 pool=P3 trace=r1 span=route reason=no_ready_workers ready=0
worker   turn.claimed       turn=reply-184 pool=P3 trace=w1 span=claim

One deferred dispatch explains why this attempt could not start immediately. To establish the wider cause, compare ready workers and arrival rate for P3 over the alert window. Incoming traffic held steady while ready workers fell to zero. The rollout records show that the deployment stopped old workers from taking new jobs before their replacements passed readiness checks. Restore ready capacity and check that wait time and first-text misses fall while the number of workers ready to take new turns recovers.

A log needs enough fields to answer that question. Record the event name, time, service, pool, bounded outcome or reason, and the permitted identifiers. The logging bridge can attach the active trace and span IDs. Log the defer reason and count of ready workers at meaningful changes or sample repeated events so a busy polling loop does not produce a log line per check. Keep the aggregate wait and outcome counts independently. OpenTelemetry logs · OpenTelemetry context propagation

Keep the data affordable and safe

Cardinality here means how many distinct values a metric label can take. pool=P3 belongs on a metric if pool names come from a small configuration. A turn ID is different for each turn. If we add it as a label, the metrics system can create a new time series for every turn. Other labels can multiply that cost. Use scoped logs or retained traces to look up a turn. Treat an opaque ID as potentially identifying when it can be joined back to an account. Restrict its access and retention. Use an allowlist for fields sent to telemetry and keep prompts, reply text, credentials, and raw account identifiers out. This applies to propagated context as well as logs. OpenTelemetry metric cardinality · OpenTelemetry on sensitive data

Trace sampling controls which traces we keep. A head sampler decides early, before it can know whether the reply will be slow. A tail sampler can use spans it has received to keep more slow or failed traces, at the cost of buffering and processing those spans before deciding. Late or missing spans can leave it with an incomplete view. A missing trace can come from sampling, a broken context handoff, or an export failure. Compare independent metrics and logs to check whether a step ran. Watch your telemetry pipeline's dropped data too. Keep the SLI's event counts independent of trace sampling so the policy for retaining individual traces cannot change the error budget calculation. OpenTelemetry sampling

See also

  • Latency vs Throughput explains why tail latency can rise even when the service completes more work per second.
  • Time-Series Databases explains which label combinations create new series and how to keep useful summaries after raw samples expire.
  • Messaging and Work Queues follows work through a durable handoff, ownership, and retry.
  • Availability shows how to turn a reliability target into a budget and account for lost capacity.

Used in

  • ChatGPT uses the first-visible-text target, pending turn queue, and worker routing to make the slow stages measurable.

Done reading? Mark it so it sticks in your dashboard.

Discussion