← Meta Interview Insights

Meta·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Aug 2023Remote

Summary

Got a SQL-heavy data science screen at Meta focused on a messaging platform dataset. Four parts to one big question, which felt like a lot to unpack in real time. The conversation engagement angle was interesting but the timing calculation tripped me up a bit.

Questions Asked (4)

Q1

Given a messages table with sender, receiver, and timestamps, write SQL to count unique conversations that started in the past 7 days, where a conversation is defined as an unordered sender-receiver pair.

Product Analytics & MetricsData Modeling
Author's notes

The unordered pair thing is what gets people.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the definition of a conversation and the time window, then normalize each sender-receiver pair into a canonical unordered form (e.g., using LEAST and GREATEST). Group by that canonical pair, find the earliest message timestamp per pair, and count pairs whose earliest timestamp falls within the past 7 days.

Pro tip: Mention that you would validate the result by spot-checking a few conversation pairs and comparing the count to a simple sanity check (e.g., total distinct pairs in the window), and note that using LEAST/GREATEST is more efficient than a self-join for large tables.

1. Clarify requirements and edge cases

Confirm the definition of 'started' (first message in the conversation) and the exact 7-day window (e.g., last 7 days from today). Ask about timezone handling and whether messages from the same sender to themselves should be excluded.

2. Normalize unordered pairs

Use LEAST(sender, receiver) and GREATEST(sender, receiver) to create a canonical representation of each conversation, ensuring (A,B) and (B,A) map to the same pair.

3. Find conversation start times

Group by the canonical pair and compute MIN(timestamp) as the conversation start time. This identifies when each unique conversation began.

4. Filter by time window and count

Filter the grouped results to only include conversations whose start time is within the past 7 days, then count the distinct canonical pairs.

5. Validate and discuss performance

Sanity-check the result (e.g., ensure count is not larger than total distinct pairs in the window) and mention indexing strategies or partitioning for large-scale data.

Key Points to Mention

  • Use of LEAST and GREATEST to handle unordered pairs efficiently
  • Definition of conversation start as MIN(timestamp) per canonical pair
  • Filtering with a date/time function (e.g., timestamp >= CURRENT_DATE - INTERVAL '7 days')
  • Handling of timezones and potential data quality issues (e.g., nulls, self-messages)
  • Performance considerations: indexing on sender, receiver, timestamp; avoiding self-joins
  • Validation: comparing count to distinct pairs in the window or spot-checking specific conversations

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

Q2

Of those conversations from the past 7 days, what percentage contain at least one message where has_reaction equals 1?

Product Analytics & Metrics
Author's notes

Pretty straightforward once you have the conversation CTE set up from part one.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the exact definitions of 'conversation' and 'message' in the context of the data model, then write a SQL query that identifies conversations with at least one message where has_reaction = 1 in the last 7 days, and compute the percentage of such conversations out of all conversations in that period. Validate the result by checking edge cases and ensuring the time window is correctly applied.

Pro tip: Always confirm whether 'conversation' includes group chats and whether the 7-day window is based on message timestamp or conversation creation date, as these assumptions can significantly impact the metric.

1. Clarify definitions and assumptions

Define what constitutes a conversation (e.g., 1:1, group) and a message (e.g., text, media). Confirm the time window: last 7 days based on message timestamp or conversation activity.

2. Identify relevant tables and fields

Locate tables containing conversation IDs, message IDs, timestamps, and the has_reaction flag. Ensure you understand the granularity (e.g., one row per message).

3. Write query to find conversations with reactions

Use a subquery or join to select distinct conversation IDs that have at least one message with has_reaction = 1 in the last 7 days.

4. Compute the percentage

Count the number of such conversations and divide by the total number of conversations with at least one message in the last 7 days, then multiply by 100 to get the percentage.

5. Validate and interpret

Check for data quality issues (e.g., nulls, duplicates) and consider if the metric aligns with business definitions. Discuss potential implications.

Key Points to Mention

  • Definition of 'conversation' and 'message' in the data model
  • Time window: last 7 days based on message timestamp
  • Use of DISTINCT to avoid double-counting conversations
  • Handling of edge cases: conversations with no messages, messages without reactions
  • Calculation: (conversations with reaction / total conversations) * 100
  • Potential need to filter out bots or spam conversations

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

Q3

Compute the average number of days between the first message in a conversation and the first message that received a reaction.

Product Analytics & MetricsData Modeling
Author's notes

This is where I fumbled.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the definitions of 'conversation', 'first message', and 'first message that received a reaction', then outline the data model and SQL logic to compute the time difference per conversation and average it. Discuss edge cases and validation steps to ensure accuracy.

Pro tip: Always confirm whether the reaction must be on the first message itself or any message, and whether to include conversations with no reactions—this shows attention to detail and prevents misinterpretation.

1. Clarify definitions and assumptions

Define what constitutes a conversation (e.g., thread_id), the first message (earliest timestamp), and the first message that received a reaction (earliest message with a reaction). Confirm whether to include conversations without reactions and how to handle ties.

2. Identify relevant tables and fields

Locate tables for messages (message_id, conversation_id, sender_id, timestamp) and reactions (message_id, reaction_type, timestamp). Ensure you can join them on message_id.

3. Compute per-conversation metrics

For each conversation, find the timestamp of the first message and the timestamp of the first message that received a reaction. Calculate the difference in days between these two timestamps.

4. Aggregate and handle edge cases

Average the per-conversation differences. Decide how to handle conversations with no reactions (exclude or treat as null) and consider outliers or negative values (if reaction timestamp precedes message timestamp due to data issues).

5. Validate and interpret results

Sanity-check the average (e.g., distribution, median) and discuss potential biases (e.g., conversations with reactions may be shorter or longer). Consider segmenting by user or conversation type for deeper insights.

Key Points to Mention

  • Definition of 'conversation' and 'first message'—likely using conversation_id and MIN(timestamp).
  • Definition of 'first message that received a reaction'—using MIN(timestamp) among messages with at least one reaction.
  • SQL approach: join messages and reactions, use window functions or subqueries to get first message and first reacted message per conversation.
  • Handling conversations with no reactions: exclude them or treat as NULL, and discuss the impact on the average.
  • Time unit conversion: ensure timestamps are in a consistent unit (e.g., seconds) and convert to days by dividing by 86400.
  • Potential data issues: reactions before messages, duplicate reactions, and how to handle them.

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

Q4

Suggest a metric and analysis approach to test whether conversations that include at least one reaction are more active overall than conversations without any reactions.

A/B Testing & ExperimentationProduct Analytics & Metrics
Author's notes

Open-ended and I kind of rambled.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by defining a clear metric for conversation activity, such as messages per conversation or daily active participants, and then design an analysis that compares conversations with at least one reaction to those without, while controlling for confounding factors. Use a matched cohort or propensity score matching to isolate the effect of reactions, and validate with an A/B test if possible.

Pro tip: Emphasize that correlation does not imply causation—reactions may be more common in already active conversations. Propose a randomized experiment or instrumental variable approach to establish causality, and discuss how to measure long-term engagement beyond immediate activity.

1. Define the metric

Choose a quantifiable measure of conversation activity, such as number of messages, unique participants, or session duration per conversation. Ensure it captures the overall activity level and is comparable across conversations.

2. Segment conversations

Split conversations into two groups: those with at least one reaction and those without. Define the time window and unit of analysis (e.g., conversation-day) clearly.

3. Control for confounders

Identify and adjust for factors that could influence both reaction presence and activity, such as conversation size, topic, or participant demographics. Use matching, stratification, or regression to isolate the effect.

4. Analyze and test

Compare the activity metric between groups using statistical tests (e.g., t-test, Mann-Whitney) and calculate effect sizes. Consider time-series analysis to observe trends before and after reactions occur.

5. Validate causally

If possible, design an A/B test where reactions are randomly enabled or prompted in some conversations. Alternatively, use quasi-experimental methods like difference-in-differences or instrumental variables to strengthen causal inference.

Key Points to Mention

  • Define conversation activity clearly (e.g., messages per user per day, reply depth, time to response).
  • Account for confounding variables like conversation size, age, and participant engagement history.
  • Use propensity score matching or regression adjustment to compare similar conversations.
  • Consider temporal dynamics: reactions may be a consequence rather than a cause of activity.
  • Propose an A/B test or natural experiment to establish causality.
  • Discuss limitations and potential biases, such as selection bias and reverse causality.

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