← TikTok Interview Insights

TikTok·Data Scientist·Onsite - System Design / Architecture·Senior

SeniorPrefer not to say
Jun 2026Remote

Summary

TikTok data scientist interview that went deep into streaming systems and experimentation infrastructure. One long technical question that basically covered six sub-problems back to back, which felt like a design session more than a traditional interview.

Questions Asked (2)

Q1

Design a streaming system that detects sample ratio mismatch across many concurrent experiments, using two partitioned input streams: one for experiment assignments and one for pageviews. The system needs to deduplicate per user per experiment using idempotent state, maintain rolling per-variant counts in O(1) memory while handling late events up to 24 hours, run a chi-square goodness-of-fit check every minute with Yates correction and alert when p < 1e-4 and the absolute difference is at least 0.3 percentage points, filter out bot-like users who receive too many assignments in a short window, and support horizontal sharding across workers.

System DesignA/B Testing & ExperimentationAlgorithms & Data Structures
Author's notes

This was a lot to hold in your head at once.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and constraints, then propose a high-level architecture that processes the two streams with stateful operators for deduplication and counting. Detail the state management, windowing, and alerting logic, emphasizing scalability and fault tolerance. Conclude with trade-offs and potential optimizations.

Pro tip: Emphasize the use of approximate data structures like HyperLogLog for deduplication to achieve O(1) memory, and discuss how to handle late events with allowed lateness and state retention. Also, mention the importance of monitoring and tuning the alert thresholds to balance sensitivity and false positives.

1. Clarify Requirements and Constraints

Ask about expected scale (number of experiments, users, events per second), latency requirements, and data sources. Confirm the need for exactly-once semantics and the handling of late events up to 24 hours.

2. Design High-Level Architecture

Propose a streaming pipeline using a distributed stream processor (e.g., Flink, Spark Streaming) with two sources: assignments and pageviews. Outline stages: ingestion, deduplication, bot filtering, windowed aggregation, and alerting.

3. Detail State Management and Deduplication

Explain how to deduplicate per user per experiment using idempotent state, such as a keyed state store with TTL or a probabilistic data structure like HyperLogLog. Discuss how to maintain rolling counts per variant in O(1) memory using count-min sketch or similar.

4. Implement Windowing and Late Event Handling

Describe using event-time windows with allowed lateness of 24 hours, and how to update counts when late events arrive. Mention the need for state retention and periodic checkpointing for fault tolerance.

5. Define Alerting Logic and Scalability

Outline the chi-square test with Yates correction, computed every minute, and the alert condition (p < 1e-4 and absolute difference ≥ 0.3 percentage points). Discuss horizontal sharding by experiment ID and load balancing across workers.

Key Points to Mention

  • Use of approximate data structures (HyperLogLog, count-min sketch) for O(1) memory deduplication and counting.
  • Event-time processing with allowed lateness and state TTL to handle late events up to 24 hours.
  • Bot filtering based on assignment frequency thresholds within a sliding window.
  • Chi-square goodness-of-fit test with Yates correction for continuity, computed on rolling counts.
  • Alerting condition combining p-value and effect size to reduce false positives.
  • Horizontal sharding by experiment ID and ensuring idempotent state for exactly-once processing.

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

Q2

How would you validate this SRM detector using historical data replay without leaking ground truth into the detection logic?

A/B Testing & ExperimentationTechnical Trade-offs
Author's notes

Shorter sub-question but honestly the sneakiest part.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying what the SRM detector is (e.g., sample ratio mismatch check in A/B tests) and the goal of historical replay validation. Then outline a rigorous validation protocol that simulates detection on historical experiments while strictly preventing ground truth leakage, and discuss how to measure performance. Emphasize the importance of temporal integrity and pre-registration of detection logic.

Pro tip: Use a time-based split to mimic production: train/tune the detector only on data before a cutoff, then evaluate on later experiments. This prevents leakage and simulates real-world deployment where future data is unavailable.

1. Define SRM detector and validation goal

Clearly specify the SRM detector's logic (e.g., chi-squared test on assignment counts) and what 'validation' means: does it correctly flag true SRM without false alarms? Establish success metrics like precision, recall, and detection latency.

2. Curate historical experiment data

Select a set of past experiments with known ground truth (whether SRM occurred). Ensure the data includes assignment logs, timestamps, and any metadata needed to replay the detector.

3. Design leakage-free replay protocol

Simulate the detector as if running in production: for each experiment, feed only data available up to each point in time, and never use future data or ground truth labels. Use a time-based split: tune on older experiments, evaluate on newer ones.

4. Execute replay and collect predictions

Run the detector on the historical data in chronological order, recording its decisions (flag/no flag) at each step. Ensure the detector's parameters are frozen from the tuning phase.

5. Evaluate and iterate

Compare detector outputs to ground truth labels to compute performance metrics. Analyze false positives/negatives, and refine the detector if needed, repeating the process with a new time-based split to avoid overfitting.

Key Points to Mention

  • Temporal integrity: use only past data to predict future SRM, mimicking production.
  • Ground truth isolation: never expose the detector to true SRM labels during replay.
  • Time-based splitting: tune on older experiments, test on newer ones to avoid leakage.
  • Performance metrics: precision, recall, F1, and detection latency for SRM.
  • Simulation of production conditions: replay data in chronological order with no future information.
  • Pre-registration of detection logic: fix the detector's parameters before evaluation to prevent overfitting.

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