42. You must group web events into sessions after thirty minutes of inactivity. What would your SQL approach need to specify?
MediumSQL
Technical
Show model answer
Partition events by the agreed identity and order them deterministically by timestamp and a tie-breaker. Use the previous timestamp to flag a new session when the gap crosses the specified threshold, then cumulatively sum the flags.
Agree whether exactly thirty minutes starts a new session and how late events, anonymous identities and clock errors are handled. Test tied timestamps and a late event that bridges two previously separate sessions.
What interviewers listen for
- Define identity and gap boundaries
- Use lag plus cumulative session starts
- Test late and tied events