← Google Interview Insights

Google·Data Scientist·Technical Phone Screen·Senior

SeniorPrefer not to say
Jun 2026Remote

Summary

Trust & Safety SQL case for a Data Scientist role at Google. Two heavy analytical tasks back to back, both in BigQuery, both with a pile of edge cases baked in. The kind of interview where you really feel the gap between knowing SQL and knowing it well enough to get every boundary condition right under pressure.

Questions Asked (2)

Q1

You're given a Trust & Safety schema in BigQuery with users, events, content, and moderation decisions. Define a 7-day confirmed violation rate per 1,000 active users, broken down by country, and write a single BigQuery SQL query to compute it. Be explicit about how you handle country attribution, which decisions count, late-arriving decisions, and the exact time window boundaries.

Product Analytics & MetricsData ModelingRoot Cause Analysis
Author's notes

The country attribution piece is where I nearly tripped.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the metric definition: confirmed violations are moderation decisions with a final 'confirmed' status, attributed to the user's country at the time of the violating event. Then define a 7-day window with explicit boundaries (e.g., UTC days) and compute the rate as (distinct users with ≥1 confirmed violation in window) / (distinct active users in window) * 1000, using a single SQL query with CTEs for clarity.

Pro tip: Use a window function or a calendar table to ensure you include all days in the 7-day period, even if there are no violations, and always state your assumptions about late-arriving data (e.g., decisions arriving after the window closes) and how you handle them (e.g., exclude or include with a lookback).

1. Define the metric and clarify ambiguities

State that 'confirmed violation rate per 1,000 active users' means the number of unique users with at least one confirmed violation in the 7-day window divided by the number of unique active users in the same window, multiplied by 1,000. Clarify that 'confirmed' means a moderation decision with a final status indicating a violation (e.g., 'confirmed_violation').

2. Specify time window and late-arriving data handling

Choose a 7-day window with explicit boundaries, e.g., from 2024-01-01 00:00:00 UTC to 2024-01-07 23:59:59 UTC. For late-arriving decisions, decide whether to include decisions that arrive after the window but pertain to events within the window; a common approach is to use a lookback period (e.g., 7 days after window end) to capture late decisions, and state this assumption.

3. Determine country attribution

Attribute each violation to the country of the user at the time of the violating event. Use the user's country from the events table (e.g., event_country) or from a user profile snapshot if available; if not, use the country from the user's most recent event before the violation. Be explicit about the choice.

4. Write the SQL query with CTEs

Construct a single BigQuery SQL query using CTEs: one for active users per country in the window, one for confirmed violations per country in the window (with late-arriving decisions included based on your rule), and then join and compute the rate. Use COUNT(DISTINCT user_id) for both numerator and denominator.

5. Validate and explain edge cases

Mention potential edge cases: users with multiple violations counted once, users with no country (exclude or assign to 'unknown'), and decisions that are later overturned (only count final confirmed decisions). Also note that the denominator should include all active users, not just those with events in the window if active is defined differently.

Key Points to Mention

  • Definition of 'confirmed violation': moderation decision with final status indicating a violation, not pending or overturned.
  • Country attribution: use the country at the time of the violating event, not the user's current country.
  • Time window boundaries: explicit UTC start and end timestamps, inclusive of start and end days.
  • Late-arriving decisions: include decisions that arrive after the window but pertain to events within the window, using a lookback period.
  • Active users: distinct users with at least one event in the 7-day window, regardless of violation status.
  • SQL implementation: use COUNT(DISTINCT user_id) and ensure proper joins to avoid double-counting.

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

Q2

Using the same schema, compute 28-day auto-flag precision by rule_id. Deduplicate flags to the earliest per (content_id, rule_id) pair, then define a true positive as a violation decision that lands within 48 hours after the flag time. Write a single BigQuery SQL query.

Product Analytics & MetricsData ModelingTechnical Trade-offs
Author's notes

The 48-hour match window is a strict half-open interval on the left and closed on the right, so flag_time < decision_time <= flag_time + INTERVAL 48 HOUR.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by deduplicating flags to the earliest per (content_id, rule_id) using a window function, then join to violation decisions within 48 hours to compute true positives. Finally, aggregate by rule_id to calculate precision as true positives divided by total flags.

Pro tip: Clarify the schema and assumptions (e.g., flag_time and decision_time columns) before writing SQL, and mention edge cases like multiple decisions or missing decisions to show thoroughness.

1. Deduplicate flags

Use ROW_NUMBER() OVER (PARTITION BY content_id, rule_id ORDER BY flag_time) to select the earliest flag per pair.

2. Join with violation decisions

Left join the deduplicated flags to violation decisions on content_id where decision_time is between flag_time and flag_time + 48 hours.

3. Identify true positives

Mark a flag as a true positive if at least one violation decision falls within the 48-hour window.

4. Aggregate by rule_id

Group by rule_id and compute precision as COUNT(true positives) / COUNT(total flags) for each rule.

Key Points to Mention

  • Use of window functions for deduplication
  • Time window logic (48 hours after flag time)
  • Left join to ensure all flags are counted
  • Handling of multiple violation decisions per flag
  • Precision calculation and grouping by rule_id
  • Assumptions about schema and data types

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