Monthly Billed GPU Hours Per Customer And Instance Type
Last updated: November 29, 2026
Quick Overview
Given a table of VM lifecycle events (start and stop) with customer and instance type, write SQL that reports billed GPU hours per customer, instance type and calendar month, splitting usage that spans a month boundary.
Crusoe
November 29, 20260
0
0 solved
Given a table of VM lifecycle events (start and stop) with customer and instance type, write SQL that reports billed GPU hours per customer, instance type and calendar month, splitting usage that spans a month boundary.
Usage metering is the backbone of Crusoe Cloud billing, and finance needs GPU hours by month even when a training VM runs across a boundary. The screen checks pairing of start and stop rows, handling VMs that are still running, and splitting intervals across months.
What the Interviewer Expects
- Pairs each start with its stop and treats a missing stop as running until the report cutoff
- Multiplies duration by GPUs per instance rather than counting VM hours
- Splits intervals that cross month boundaries
- Groups by customer, instance type and month
- Mentions how to validate totals against raw usage
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 make this incremental so it does not rescan all history daily?
- Stop events sometimes arrive twice. How do you deduplicate?
- How would you bill by the second with a one-minute minimum?
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
Assume vm_events(vm_id, customer_id, instance_type, gpus, event_type, event_ts) with event_type in ('start','stop'), and each VM has at most one start then one stop per run. A run with no stop is ...
Approach
- Use
LEADover each VM's events to pair a start with the next event. 2) Clip the end to the cutoff. 3) Generate one row per month the run touches withgenerate_seriesand clip the run to that mo...