Compute Time to First Token and Decode Speed From Token Logs

Last updated: November 29, 2026

Quick Overview

Given a requests table with when each API request arrived and a token_events table with one row per generated output token, compute each request's time to first token and its decode throughput, then report per-model medians for the last day.

Cerebras
Data Manipulation (SQL/Python)
Data Engineer
Cerebras
November 29, 2026
Data Engineer
Phone Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given a requests table with when each API request arrived and a token_events table with one row per generated output token, compute each request's time to first token and its decode throughput, then report per-model medians for the last day.

Speed is the headline metric for a fast inference cloud, so analytics and platform roles must turn raw token logs into TTFT and tokens-per-second numbers that match what customers feel. The interviewer checks clean aggregation and careful metric definitions.

What the Interviewer Expects
  • Defines TTFT as first token time minus request arrival
  • Defines decode speed over tokens after the first, divided by time since the first token
  • Guards against single-token responses (division by zero)
  • Uses percentile functions rather than averages for latency
  • Filters the time window on arrival time, not event time
Key Topics to Cover
SQL aggregation
percentiles
latency metrics
TTFT
throughput
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you report p99 instead, and why is it noisier?
  • How would you separate queueing time from prefill time?
  • How would you compute this incrementally in a streaming job?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

requests(request_id, model, received_at) with one row per API call, and token_events(request_id, token_index, emitted_at) with token_index starting at 0. I assume timestamps share a clock (the ser...

Approach

Aggregate tokens per request: first emission, last emission, token count. Join to requests. TTFT = first minus received. Decode speed = (count - 1) / (last - first), because the first token's cost is ...


Submit Your Answer
Markdown supported

Related Questions