Sessionize TikTok Shop Live Events Into an Ordered Purchase Funnel

Last updated: November 29, 2026

Quick Overview

From a raw event log of TikTok Shop LIVE viewers, split each user's events into sessions with a 30 minute inactivity gap, then report per day how many sessions reached view product, add to cart after viewing, and purchase after adding to cart, in that order.

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

0

0

0 solved


From a raw event log of TikTok Shop LIVE viewers, split each user's events into sessions with a 30 minute inactivity gap, then report per day how many sessions reached view product, add to cart after viewing, and purchase after adding to cart, in that order.

An onsite SQL round for e-commerce data roles at ByteDance, where live shopping on TikTok Shop and Douyin is a core business and funnel metrics drive streamer and merchant tooling. The interviewer checks gaps-and-islands sessionization with window functions and whether you enforce step ordering inside a session rather than just counting event types.

What the Interviewer Expects
  • Builds sessions with LAG plus a running SUM of new-session flags
  • Treats the first event of each user as a session start (LAG is NULL)
  • Enforces order: cart must follow the first view, purchase must follow that cart, all within the same session
  • Aggregates at the session grain so a session counts at most once per step
  • Discusses cost on billions of rows and how to make it incremental
Key Topics to Cover
sessionization
window functions
gaps and islands
ordered funnels
e-commerce analytics
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 also cap a session at 4 hours even if events keep arriving?
  • How would you handle a session that spans midnight or arrives late from a mobile client?
  • How would you require the purchase to be for the same product that was viewed and carted?
  • How would you compute this incrementally each hour in Flink or Spark without reprocessing history?
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

live_shop_events(user_id, event_ts, event_type) with event_ts as epoch seconds and types such as enter_room, view_product, add_to_cart, purchase. A new session starts when the gap from the...

Approach
  1. Flag session starts with LAG(event_ts) per user; a NULL lag or a gap over 1800 s is a new session.
  2. Number sessions with a running SUM of the flags.
  3. Step 1: per session, the ea...

Submit Your Answer
Markdown supported