← Snapchat Interview Insights

Snapchat·Data Scientist·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Aug 2025Remote

Summary

Snapchat data scientist interview that was basically a gauntlet of SQL edge cases around friendship request data. Four tasks, all connected, and they kept layering on complexity. Felt like a take-home but with someone watching.

Questions Asked (4)

Q1

Write a single SQL query that returns, for each date in a given 7-day UTC window, the columns: day, same-day accepts, total requests, and same-day accept rate. A same-day accept means the request and approval share the same UTC date. The output must include days with zero requests.

Product Analytics & MetricsData Modeling
Author's notes

The zero-request days requirement is what got me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a date spine (e.g., generate_series or recursive CTE) to create all 7 days, then LEFT JOIN aggregated request data to ensure zero-request days appear. Aggregate requests by UTC date, counting total requests and same-day accepts, then compute the rate with proper handling of division by zero.

Pro tip: Explicitly state your assumptions about the data model (e.g., one row per request with an approval timestamp) and clarify how you handle NULLs or zero denominators—this shows you think about edge cases and data quality.

1. Generate the date spine

Create a list of all dates in the 7-day UTC window using a date generator function or recursive CTE. This ensures days with no requests are included.

2. Aggregate request metrics by date

From the requests table, group by the UTC date of the request. Count total requests and count same-day accepts (where approval date equals request date).

3. Join spine with aggregated data

LEFT JOIN the date spine to the aggregated metrics on date, so that days without requests get NULLs. Use COALESCE to replace NULL counts with 0.

4. Calculate the same-day accept rate

Compute the rate as same-day accepts divided by total requests, using NULLIF or a CASE statement to avoid division by zero. Format or round as needed.

5. Select and order final columns

Output day, same-day accepts, total requests, and same-day accept rate, ordered by day ascending.

Key Points to Mention

  • Use of a date spine (e.g., generate_series in PostgreSQL) to include all days, even those with zero requests.
  • Definition of same-day accept: request_date = approval_date (both in UTC).
  • Handling of zero denominators: use NULLIF or CASE to avoid division by zero, returning 0 or NULL as appropriate.
  • Aggregation logic: COUNT(*) for total requests, COUNT(CASE WHEN ...) or SUM(CASE WHEN ...) for same-day accepts.
  • LEFT JOIN to preserve all dates from the spine and COALESCE to replace NULL counts with 0.
  • Assumptions about the data model: one row per request, approval timestamp may be NULL if not yet approved.

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

Q2

Write SQL to compute the percentage of friendship requests from last week where the requester is not marked as spam. Only include requests with a timestamp in the defined UTC window, and report the result to two decimal places.

Product Analytics & MetricsRoot Cause Analysis
Author's notes

Simpler than it looked but I second-guessed myself on the join direction.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the exact UTC window for 'last week' and the definition of 'not marked as spam' (e.g., requester's spam flag is false). Then write a SQL query that filters requests within that window, counts total requests and requests where the requester is not spam, and computes the percentage rounded to two decimal places.

Pro tip: Always confirm the time window and spam definition with the interviewer before writing SQL; this shows attention to detail and avoids incorrect assumptions. Also, consider using a single query with conditional aggregation for efficiency.

1. Clarify requirements

Ask the interviewer to confirm the exact UTC start and end timestamps for 'last week' and how 'not marked as spam' is defined (e.g., a boolean flag on the requester).

2. Identify tables and columns

Determine the table containing friendship requests, the timestamp column, and the column indicating whether the requester is marked as spam (likely a user table joined on requester_id).

3. Write the SQL query

Use conditional aggregation: COUNT(CASE WHEN requester_is_spam = false THEN 1 END) * 100.0 / COUNT(*) to get the percentage, filtering by the timestamp window.

4. Format and validate

Round the result to two decimal places using ROUND(..., 2) and verify the query logic with sample data or edge cases (e.g., no requests).

Key Points to Mention

  • Exact UTC window definition (e.g., last week from Monday 00:00 to Sunday 23:59:59 UTC)
  • Definition of 'not marked as spam' (e.g., requester's spam flag is false)
  • Use of conditional aggregation to compute numerator and denominator in one pass
  • Handling of NULLs or missing spam flags (e.g., treat as not spam or exclude)
  • Rounding to two decimal places with ROUND function
  • Potential need to join with a users table to get requester's spam status

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

Q3

If the users table is incomplete and some requesters have no record there, write SQL returning three percentages for the same window: one excluding unknown requesters, one treating unknowns as spam, and one treating unknowns as not spam. Also return the counts used for each denominator.

Data ModelingProduct Analytics & MetricsTechnical Trade-offs
Author's notes

This is where the interview got interesting.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the schema and the definition of 'unknown requesters' (e.g., missing user_id in users table). Then write a single SQL query that computes the three percentages using conditional aggregation, ensuring each denominator is clearly defined and returned alongside the percentages.

Pro tip: Explicitly state your assumptions about the data (e.g., how you identify unknown requesters) and consider edge cases like NULLs or duplicate records. This shows you think about data quality and reproducibility.

1. Clarify the schema and definitions

Identify the relevant tables (e.g., requests, users) and how to determine if a requester is unknown (e.g., LEFT JOIN on user_id yields NULL). Confirm the time window and the definition of 'spam'.

2. Design the aggregation logic

Use conditional aggregation (CASE WHEN) to compute counts for each scenario: excluding unknowns, treating unknowns as spam, and treating unknowns as not spam. Ensure the denominators are correctly defined for each percentage.

3. Write the SQL query

Construct a single query that calculates the three percentages and the corresponding counts. Use subqueries or CTEs for clarity if needed.

4. Validate and explain results

Check that the percentages sum to 100% within each scenario and that the counts align with expectations. Be prepared to discuss the implications of each treatment of unknowns.

Key Points to Mention

  • Use of LEFT JOIN to identify unknown requesters
  • Conditional aggregation with CASE WHEN for multiple metrics
  • Definition of denominators: total requests vs. requests with known users vs. all requests
  • Handling of NULLs and potential data quality issues
  • Interpretation of results: how treating unknowns as spam or not spam affects spam rate
  • Performance considerations: indexing, filtering by time window early

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

Q4

List at least three edge cases you considered for the above queries, such as NULL approved_at, approvals falling outside the date window, duplicate requests between the same pair, or timezone cutoffs. Explain explicitly how your SQL handles each.

Data ModelingTechnical Trade-offsRoot Cause Analysis
Author's notes

I listed NULL approved_at (handled because DATE(NULL) is NULL so it never equals DATE(requested_at)), approvals outside the window (same-day accept only checks the date match, not whether approved_at is in the window, which is actually a design choice worth flagging), and the timezone thing since all boundaries are UTC so DATE() on a UTC timestamp is fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by acknowledging that edge cases are critical for robust SQL, then list 3-4 specific edge cases relevant to the query context (e.g., NULL approved_at, duplicate requests, timezone cutoffs). For each, explain the exact SQL technique used to handle it, such as COALESCE, DISTINCT, or timezone conversion functions, and briefly mention the impact on results if unhandled.

Pro tip: Tie each edge case back to a real-world scenario at Snapchat, like how timezone cutoffs affect daily active user metrics across global markets, to show business impact and technical depth.

1. Identify relevant edge cases

List 3-4 edge cases that directly apply to the query context, such as NULL approved_at, approvals outside the date window, duplicate requests between the same pair, and timezone cutoffs.

2. Explain SQL handling for each

For each edge case, describe the specific SQL construct used to handle it, e.g., COALESCE for NULLs, WHERE clauses for date windows, DISTINCT or GROUP BY for duplicates, and AT TIME ZONE for timezone conversion.

3. Discuss trade-offs and alternatives

Mention any trade-offs, such as performance implications of DISTINCT versus GROUP BY, or why a particular timezone handling was chosen over another.

4. Connect to business impact

Briefly explain how each edge case, if unhandled, could skew metrics or lead to incorrect insights, tying back to Snapchat's use cases like user engagement or ad performance.

Key Points to Mention

  • Use of COALESCE or IS NULL checks to handle NULL approved_at values
  • Filtering with WHERE clauses to exclude approvals outside the date window
  • Using DISTINCT or GROUP BY to deduplicate requests between the same pair
  • Timezone conversion with AT TIME ZONE or UTC normalization to handle cutoffs
  • Impact of edge cases on data quality and metric accuracy
  • Performance considerations when handling large datasets

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