Daily TTFT Percentiles And Error Rate Per Model
Last updated: November 29, 2026
Quick Overview
Given a request log table for an inference API, write SQL that returns, for each model and day, the request count, the error rate, and the p50 and p95 time to first token computed over successful requests only.
Fireworks AI
November 29, 20260
0
0 solved
Given a request log table for an inference API, write SQL that returns, for each model and day, the request count, the error rate, and the p50 and p95 time to first token computed over successful requests only.
Fireworks tracks latency per model to hold SLOs and publish performance numbers, so analytics and platform engineers write this kind of query often. The interviewer checks filtering inside aggregates, ordered-set percentile functions and date bucketing.
What the Interviewer Expects
- Bucket timestamps by UTC day
- Compute error rate over all requests but percentiles over successful ones
- Use an ordered-set aggregate for percentiles
- Avoid integer division in the rate
- Order the result usefully
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you compute p95 per tenant only for tenants with at least 100 requests?
- How would you compute the same metrics from pre-aggregated histograms instead of raw rows?
- Why might p95 TTFT over all models be misleading?
- How would you flag days where p95 rose more than 20% versus the trailing 7-day median?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Table request_logs(request_id, model, api_key, created_at timestamptz, status text, ttft_ms int, output_tokens int). status is 'ok' or an error code; ttft_ms is null for requests that failed b...
Approach
Group by model and date_trunc('day', created_at at time zone 'UTC'). Use count(*) for volume, avg of a boolean cast for error rate, and percentile_cont ... within group with a FILTER clause ...