← TikTok Interview Insights

TikTok·Data Scientist·Technical Phone Screen·Senior

Senior
Jun 2026Remote

Summary

TikTok data science interview with a brutal SQL question covering funnel analysis, drop-off detection, and rolling windows all in one shot. The schema was manageable but the requirements kept stacking up in ways that made it hard to stay organized under pressure.

Questions Asked (3)

Q1

Write PostgreSQL to analyze a 4-step shopping funnel (view_product, add_to_cart, checkout_start, purchase) across multiple tables. For each country and event date, compute step-to-step conversion rates after deduplicating to the first occurrence per user, session, and product, and only counting a conversion if both steps appear in timestamp order within the same user-session-product group.

Product Analytics & MetricsData Modeling
Author's notes

This took me way longer than it should have.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the funnel definition and data model, then outline a SQL strategy that deduplicates events to the first occurrence per user-session-product, assigns step order, and uses conditional aggregation or window functions to compute step-to-step conversions. Emphasize that conversions require both steps to occur in timestamp order within the same group, and that results should be grouped by country and event date.

Pro tip: Mention that you would validate the funnel logic with a small sample or sanity checks (e.g., ensuring purchase counts never exceed checkout counts) before scaling to the full dataset, and discuss how you'd handle edge cases like multiple sessions per user or missing steps.

1. Clarify requirements and data model

Confirm the funnel steps, table structures, and definitions of user, session, and product. Ask about time zones, date boundaries, and whether events can occur across multiple days.

2. Deduplicate to first occurrence per group

Use ROW_NUMBER() partitioned by user, session, and product, ordered by timestamp, to keep only the first occurrence of each event type. This ensures each step is counted once per group.

3. Assign step order and validate sequence

Map event types to step numbers (1-4) and use window functions or self-joins to check that step N+1 occurs after step N within the same group. Only count a conversion if the sequence is valid.

4. Compute step-to-step conversion rates

Aggregate by country and event date, counting distinct groups that reached each step. Calculate conversion rates as the ratio of counts between consecutive steps, ensuring the denominator is the previous step's count.

5. Present results and discuss edge cases

Show the final query or pseudocode, and explain how you would handle edge cases like multiple sessions, missing steps, or out-of-order events. Suggest validation checks and potential optimizations.

Key Points to Mention

  • Deduplication logic using ROW_NUMBER() or DISTINCT ON to keep first occurrence per user-session-product.
  • Ensuring timestamp order within each group for valid conversions (e.g., using window functions or self-joins).
  • Conditional aggregation with CASE statements or FILTER clauses to count step completions.
  • Grouping by country and event date, and handling date truncation or time zone conversion.
  • Edge cases: multiple sessions per user, missing intermediate steps, and events spanning multiple days.
  • Performance considerations: indexing, partitioning, and avoiding unnecessary joins for large datasets.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

For each user in a given month, identify their most frequent drop-off step across sessions, where a drop-off means the last funnel step reached without the next step occurring in the same session or within 24 hours by the same user and product. Also compute the median elapsed time from the prior step to that drop-off across their sessions.

Product Analytics & MetricsAlgorithms & Data Structures
Author's notes

The 24-hour cross-session window completely blindsided me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining the funnel steps and session boundaries, then for each user-product-session, identify the last step reached and check if the next step occurs within the session or within 24 hours. Aggregate drop-off counts per user per month to find the most frequent drop-off step, and compute the median elapsed time from the prior step to drop-off across sessions.

Pro tip: Clarify the definition of 'drop-off' upfront—specifically, whether the 24-hour window is a rolling window from the last step or from session end—and mention how you'd handle edge cases like users with multiple products or incomplete sessions.

1. Define funnel and session logic

Specify the ordered funnel steps and how sessions are defined (e.g., 30-minute inactivity timeout). Determine how to handle multiple sessions per user per month.

2. Identify drop-off events per session

For each session, find the last funnel step reached. Check if the next step occurs in the same session or within 24 hours by the same user and product. If not, mark it as a drop-off.

3. Aggregate drop-off counts per user per month

Group drop-off events by user, month, and drop-off step. Count occurrences to determine the most frequent drop-off step for each user in the given month.

4. Compute median elapsed time

For each user's most frequent drop-off step, calculate the time from the prior step to the drop-off event across all their sessions, then compute the median.

5. Validate and handle edge cases

Check for ties in drop-off frequency, missing prior steps, or sessions spanning month boundaries. Decide on tie-breaking rules and how to treat incomplete data.

Key Points to Mention

  • Sessionization logic and how it affects drop-off identification
  • The 24-hour window: rolling vs. fixed, and timezone considerations
  • Handling multiple products per user and ensuring product-level granularity
  • Tie-breaking when multiple drop-off steps have the same frequency
  • Median vs. mean for elapsed time due to skewness and outliers
  • Scalability: using window functions or map-reduce for large datasets

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

For each day in a given month and by country, compute a 7-day rolling conversion rate from add_to_cart to purchase. The denominator is unique user-product add_to_cart events on day D, and the numerator is the subset where the same user and product has a purchase event within 7 days after the add_to_cart timestamp, across any session.

Product Analytics & MetricsA/B Testing & Experimentation
Author's notes

Rolling windows with a cross-session purchase lookup are annoying to write cleanly.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the metric definition and edge cases (e.g., multiple add_to_cart events, timezone handling, country assignment). Then outline a SQL-based solution using window functions or self-joins to match add_to_cart events with subsequent purchases within 7 days, ensuring uniqueness at the user-product level. Finally, discuss how to compute the rolling 7-day conversion rate and validate the results.

Pro tip: Mention the importance of handling time zones consistently and using the add_to_cart timestamp as the anchor for the 7-day window, not the purchase timestamp. Also, consider using a calendar table to ensure all days are included even if no add_to_cart events occur.

1. Clarify Requirements and Edge Cases

Ask clarifying questions about the definition of unique user-product add_to_cart events, how to handle multiple add_to_cart events for the same user-product within the 7-day window, and whether the 7-day window is inclusive. Also confirm time zone and country assignment logic.

2. Data Preparation and Aggregation

Filter events for the relevant month and countries. For each day D, identify unique user-product pairs that had an add_to_cart event on that day. This forms the denominator.

3. Identify Purchases within 7 Days

For each add_to_cart event, find if the same user and product had a purchase event within 7 days after the add_to_cart timestamp. Use a self-join or window function to match events, ensuring the purchase occurs after the add_to_cart and within the window.

4. Compute Daily Conversion Rate

For each day D and country, count the number of unique user-product pairs that converted (numerator) and divide by the total unique user-product add_to_cart pairs on day D (denominator). This gives the daily conversion rate.

5. Calculate 7-Day Rolling Average

Compute the rolling 7-day average of the daily conversion rates, ensuring that the rolling window is based on calendar days and handles missing days appropriately (e.g., using a calendar table or window functions with date ranges).

Key Points to Mention

  • Definition of unique user-product add_to_cart events: deduplicate by user_id and product_id per day.
  • Handling multiple add_to_cart events: if a user adds the same product multiple times on the same day, count as one; if on different days, each day's event is considered separately.
  • Time window logic: purchase must occur within 7 days after the add_to_cart timestamp, inclusive of the 7th day? Clarify.
  • Time zone consistency: ensure all timestamps are in the same time zone (e.g., UTC) or convert to local time based on country.
  • Use of window functions or self-joins to match add_to_cart and purchase events efficiently.
  • Rolling average calculation: use a 7-day window over daily conversion rates, possibly with a calendar table to fill missing dates.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.