Hourly Queue Wait Percentiles By Subscription Tier
Last updated: November 29, 2026
Quick Overview
From a pandas event log with columns job_id, tier, event ('queued' or 'started') and ts, compute for each tier and hour the number of jobs plus p50 and p95 seconds between first queued and first started.
Luma AI
November 29, 20260
0
0 solved
From a pandas event log with columns job_id, tier, event ('queued' or 'started') and ts, compute for each tier and hour the number of jobs plus p50 and p95 seconds between first queued and first started.
Queue wait is the metric Dream Machine users feel most, and tier promises (faster for paid plans) need to be checked hourly against GPU capacity. The interviewer looks for reshaping events into one row per job, handling duplicate or missing events, and choosing the right time bucket.
What the Interviewer Expects
- Reshape long events into one row per job
- Deduplicate repeated events by taking the earliest
- Drop or separately report jobs that never started
- Bucket by queue time, not start time, and justify it
- Compute percentiles per group
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 report jobs still waiting at the end of the hour so p95 is not biased low?
- How would you compute this incrementally every five minutes?
- How would you alert when paid-tier p95 exceeds free-tier p50?
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
Each job should log one queued and one started event, but retries can log started twice and some jobs never start (cancelled or still waiting). Timestamps may come as strings, so parse to UTC. Tier is...
Approach
Pivot to one row per (job_id, tier) with the earliest timestamp of each event type. Keep rows with both events and a non-negative wait. Compute wait seconds, bucket on the queued hour (that is when ...