Daily Active Minutes When Instagram Sessions Cross Midnight

Last updated: November 29, 2026

Quick Overview

Build sessions from Instagram foreground events with a 30-minute inactivity gap, then compute each user's active minutes per calendar day, splitting any session that crosses midnight between the two days.

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

0

0

0 solved


Build sessions from Instagram foreground events with a 30-minute inactivity gap, then compute each user's active minutes per calendar day, splitting any session that crosses midnight between the two days.

A harder SQL problem in Meta's data engineering onsite, where time-spent tables feed daily dashboards. The interviewer checks sessionization with window functions and, more importantly, that a session from 23:50 to 00:20 contributes 10 minutes to each day rather than 30 to one.

What the Interviewer Expects
  • Builds sessions with LAG and a running sum of new-session flags
  • Derives session start and end from the grouped events
  • Splits sessions across calendar days with a date spine join
  • Uses GREATEST and LEAST to clip each piece to its day
  • Explains time zone choice for the day boundary
Key Topics to Cover
sessionization
window functions
date spine
interval splitting
time spent
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
  • Which time zone should define the day for a global product?
  • How would you make this incremental so yesterday's partition is not rebuilt every day?
  • How would you treat the trailing time after the last event in a session?
  • What if a session spans more than two days because of a logging bug?
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

ig_events(user_id, event_ts) holds foreground events (taps, scrolls, views) in the user's local time. A new session starts when the gap from the previous event exceeds 30 minutes. Session length is ...

Approach

Step 1: LAG per user, flag a new session when the gap exceeds 30 minutes or there is no previous event, then a running SUM of flags gives a session number. Step 2: min and max timestamp per sessio...


Submit Your Answer
Markdown supported