Per-Minute Request Counts From Cumulative Counters That Reset on Restart

Last updated: November 29, 2026

Quick Overview

Servers export a cumulative request counter that resets to zero when a process restarts. Given scraped snapshots from many hosts, write Python that converts them into total new requests per minute across the fleet, handling resets correctly.

Meta
Data Manipulation (SQL/Python)
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Data Manipulation (SQL/Python)
Hard

0

0

0 solved


Servers export a cumulative request counter that resets to zero when a process restarts. Given scraped snapshots from many hosts, write Python that converts them into total new requests per minute across the fleet, handling resets correctly.

A Python question in Meta production engineering and infrastructure data loops, mirroring how monitoring systems turn monotonic counters into rates. The interviewer checks per-host ordering, reset detection, attribution of deltas to time buckets, and reasoning about what is lost at a reset.

What the Interviewer Expects
  • Group snapshots by host and sort by time
  • Take differences between consecutive snapshots
  • Detect a drop as a reset and use the new value as the delta
  • Attribute each delta to the bucket of the later snapshot
  • Explain undercounting around resets and scrape gaps
Key Topics to Cover
counters
delta computation
reset handling
time bucketing
monitoring
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
  • Requests between the last scrape and the crash are lost: can you bound the error?
  • How would you spread a delta across several minutes when scrapes are sparse?
  • What changes if the counter can wrap at 2^32?
  • How would you detect a host that restarts in a loop?
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

Input: (host, ts_seconds, cumulative_count) in any order. Each host's counter only goes up except when the process restarts, after which it starts at 0. Output: {minute_start: total increase} acro...

Approach

Group by host and sort. For consecutive snapshots, if the value did not decrease, the delta is the difference. If it decreased, the process restarted between the two scrapes; the best estimate is the ...


Submit Your Answer
Markdown supported