Sessionize Mobile Banking App Events With Timeouts and Logouts
Last updated: November 29, 2026
Quick Overview
From a log of Capital One mobile app events, assign session numbers per customer where a new session starts after 30 minutes of inactivity or after a logout event, then report each session's start, end, event count, and whether a bill payment happened.
Capital One
November 29, 20260
0
0 solved
From a log of Capital One mobile app events, assign session numbers per customer where a new session starts after 30 minutes of inactivity or after a logout event, then report each session's start, end, event count, and whether a bill payment happened.
The Capital One mobile app is a primary servicing channel, and digital analytics teams rebuild sessions from raw event streams to measure things like time to pay a bill. The interviewer is checking LAG plus a running sum to build session ids, and whether you place the logout event in the session it ends rather than the next one.
What the Interviewer Expects
- Uses LAG on both timestamp and event type
- Marks a new session on first event, timeout gap, or a previous logout
- Builds session ids with a cumulative SUM of the new-session flag
- Keeps the logout in the session it closes
- Aggregates per session with a conditional flag for bill payment
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 cap sessions at four hours even if events keep arriving?
- How would you handle late-arriving events in a daily batch job?
- How would you compute median time from session start to bill payment?
- How would this change if the app emits background and foreground events?
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
app_events(customer_id, event_ts, event_type)with types such aslogin,view_balance,pay_bill,logout.- Timeout is strictly more than 30 minutes between consecutive events.
- The logout ...
Approach
- For each event, get the previous event's timestamp and type with LAG.
is_new = 1when there is no previous event, the gap exceeds 30 minutes, or the previous event was a logout.- Running SUM...