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
Data Manipulation (SQL/Python)
Data Engineer
Fireworks AI
November 29, 2026
Data Engineer
Phone Screen
Data Manipulation (SQL/Python)
Easy

0

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
SQL
Percentiles
Aggregation
Latency metrics
FILTER clause
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 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 Problems
Sample 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 ...


Submit Your Answer
Markdown supported

Related Questions