← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Meta data engineering interview focused almost entirely on a single SQL problem about modeling follow relationships. The question had enough layers that it took up most of the session, which I wasn't expecting.

Questions Asked (2)

Q1

Given a table of follow events with types like request, success, reject, and unfollow, write SQL to return the total number of currently active follow connections.

Data ModelingAlgorithms & Data Structures
Author's notes

The tricky part is that 'active' isn't just whether a follow_success ever happened.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the follow lifecycle as a state machine where each user pair has a current status determined by the latest event. Use a window function to pick the most recent event per (follower, followee) pair, then count pairs whose latest event is 'success' (or 'request' if pending counts as active).

Pro tip: Clarify with the interviewer whether 'active' includes pending requests or only accepted follows, and whether unfollows/rejects should be excluded. Also mention that using ROW_NUMBER() with a proper tie-breaker (e.g., event timestamp plus event ID) handles duplicate timestamps gracefully.

1. Clarify the definition of 'active'

Ask whether active means only successful follows, or also pending requests. Confirm that reject and unfollow events terminate the connection.

2. Identify the grain and latest event

Determine that each (follower_id, followee_id) pair can have multiple events. Use a window function like ROW_NUMBER() OVER (PARTITION BY follower_id, followee_id ORDER BY event_time DESC, event_id DESC) to get the latest event per pair.

3. Filter to active connections

From the latest events, keep only those where event_type is 'success' (and optionally 'request' if pending counts). Exclude 'reject' and 'unfollow'.

4. Count distinct pairs

Count the number of distinct (follower_id, followee_id) pairs that remain. Use COUNT(*) or COUNT(DISTINCT ...) as appropriate.

5. Write and explain the final SQL

Present a clean SQL query using a CTE or subquery with the window function, and explain each part. Mention edge cases like self-follows or duplicate events.

Key Points to Mention

  • State machine interpretation of follow events: request -> success/reject, success -> unfollow, etc.
  • Use of window functions (ROW_NUMBER, RANK) to get the latest event per pair.
  • Handling ties in event timestamps with a secondary sort key (e.g., event_id).
  • Filtering out terminal states (reject, unfollow) and counting only active states.
  • Considering whether pending requests count as active connections.
  • Performance considerations: indexing on (follower_id, followee_id, event_time) and partitioning.

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

Q2

Extend your solution to return, for each calendar day, how many active follow connections existed at the end of that day.

Data ModelingProduct Analytics & Metrics
Author's notes

This is where things got messy for me.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model each follow as an interval with a start date (when the follow was created) and an end date (when it was removed, or open-ended if still active). Then, for each calendar day, count the number of intervals that cover that day, ensuring the end date is exclusive to reflect end-of-day semantics. Use a sweep-line algorithm or a calendar table with cumulative sums to efficiently compute daily active counts.

Pro tip: Clarify the definition of 'active at the end of the day'—if a follow is created and removed on the same day, it should not count. Also, mention that you would handle time zones consistently (e.g., UTC) to avoid off-by-one errors.

1. Define the interval semantics

Treat each follow as a half-open interval [start_date, end_date), where start_date is the creation date and end_date is the removal date (or NULL if still active). This ensures a follow removed on day D is not counted as active at the end of day D.

2. Generate a calendar table

Create or use a calendar table that contains every date in the range of interest. This will serve as the basis for the daily counts.

3. Compute daily active counts

For each day in the calendar, count the number of follow intervals where start_date <= day < end_date (or end_date IS NULL). This can be done with a join and aggregation, or more efficiently with a sweep-line approach that tracks cumulative changes.

4. Optimize for scale

If the data is large, use a sweep-line algorithm: create events for each follow start (+1) and end (-1), sort by date, and compute a running sum to get active counts per day. This avoids expensive joins.

5. Validate and handle edge cases

Test with edge cases such as follows created and removed on the same day, follows that never end, and days with no activity. Ensure the output includes all calendar days, even those with zero active follows.

Key Points to Mention

  • Half-open interval semantics to correctly handle end-of-day counts
  • Use of a calendar table to ensure all days are represented
  • Sweep-line algorithm for efficient computation on large datasets
  • Handling of NULL end dates for active follows
  • Time zone consistency (e.g., UTC) to avoid date boundary issues
  • Edge cases: same-day create/remove, zero-activity days, and data gaps

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