Compute Per Org Camera Offline Minutes From Heartbeats
Last updated: November 29, 2026
Quick Overview
Given a heartbeats table (camera_id, received_at), where online cameras check in every minute, and a cameras table (camera_id, org_id), compute for one day each org's number of cameras that went offline, number of outages, and total offline minutes, where an outage is a gap of more than 5 minutes between heartbeats.
Verkada
November 29, 20260
0
0 solved
Given a heartbeats table (camera_id, received_at), where online cameras check in every minute, and a cameras table (camera_id, org_id), compute for one day each org's number of cameras that went offline, number of outages, and total offline minutes, where an outage is a gap of more than 5 minutes between heartbeats.
Verkada tracks device health across millions of cameras, and customer success needs per-org uptime numbers for reports. This screen checks window functions (gaps and islands), careful definitions of what counts as offline, and awareness of day boundaries.
What the Interviewer Expects
- Uses LAG partitioned by camera ordered by time to find gaps
- States the outage definition and how offline minutes are counted
- Joins to cameras to roll up by org
- Notices the day-boundary problem for gaps that cross midnight
- Mentions cameras with no heartbeats at all in the day
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 do you include cameras that sent zero heartbeats that day?
- How would you make this an incremental daily job instead of a full scan?
- How would you exclude planned maintenance windows from the uptime number?
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
Heartbeat cadence is 60 s, so a normal gap is about 1 minute. An outage is any gap over 5 minutes. Offline minutes for a gap = gap minus the 1 minute expected cadence. Times are UTC. One row per heart...
Approach
For each camera, order heartbeats and use LAG to get the previous timestamp. Compute the gap in minutes, keep rows where the gap is over 5, then aggregate by org....