Sessionize Consumer App Events with a 30-Minute Inactivity Gap

Last updated: November 29, 2026

Quick Overview

Given raw consumer app events with user_id, timestamp and event name, write pandas code that splits each user's events into sessions whenever more than 30 minutes pass between events, and returns one row per session with start, end, event count and whether it ended in a completed checkout.

DoorDash
Data Manipulation (SQL/Python)
Data Scientist
DoorDash
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given raw consumer app events with user_id, timestamp and event name, write pandas code that splits each user's events into sessions whenever more than 30 minutes pass between events, and returns one row per session with start, end, event count and whether it ended in a completed checkout.

Client session ids on the DoorDash app are unreliable when users background the app between browsing restaurants and ordering, so DS teams often rebuild sessions from raw events. A Python screen uses this to test vectorized pandas (shift, cumsum, groupby) rather than row loops, and careful handling of the exact gap boundary.

What the Interviewer Expects
  • Sort by user and time before computing gaps
  • Use groupby shift to compare each event to the previous one for the same user
  • Turn the new-session flag into ids with a grouped cumulative sum
  • Aggregate to one row per session with named aggregations
  • State whether a gap of exactly 30 minutes starts a new session
Key Topics to Cover
sessionization
pandas groupby
shift and cumsum
event data
vectorization
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
  • How would you cap a session at 3 hours even if events keep arriving every 20 minutes?
  • How would you compute this in SQL with window functions?
  • How would you attribute a checkout to the store first viewed in the session?
  • The table has 2 billion rows. What changes?
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 events has columns user_id, ts (datetime64) and event (for example app_open, store_view, checkout_complete). Rows may arrive unsorted. A new session starts on a user's first event ...

Approach

Sort by user_id, ts. groupby('user_id')['ts'].shift() gives each event's previous timestamp for the same user (NaT for the first). A boolean new_session is true where the previous time is missin...


Submit Your Answer
Markdown supported