Build an L7 Engagement Histogram for Facebook App Users
Last updated: November 29, 2026
Quick Overview
Using a daily activity table, compute for a given date how many users were active on exactly 1, 2, ... 7 of the trailing seven days (the L7 distribution), among users active at least once in that window.
Meta
November 29, 20260
0
0 solved
Using a daily activity table, compute for a given date how many users were active on exactly 1, 2, ... 7 of the trailing seven days (the L7 distribution), among users active at least once in that window.
L7 and L28 histograms are a classic Meta engagement view: they show whether a product has a core of daily users or a long tail of occasional visitors. The interviewer checks a simple window filter, distinct-day counting and a GROUP BY on an aggregate.
What the Interviewer Expects
- Filter to the seven-day window ending on the report date inclusive
- Count distinct active days per user
- Group by that count to build the histogram
- Add percent of window-active users
- Mention what a healthy versus unhealthy shape looks like
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you compute L7 for every day in a month without seven self-joins?
- How would you compare the L7 shape before and after a launch?
- Would you include users who were inactive all week as an L0 bucket?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
daily_active(user_id, ds) has one row per user per active day, but may contain duplicates from late-arriving logs. Report date :d. Window is :d - 6 through :d....
Approach
Two levels of aggregation: per user, count distinct days in the window; then per count, count users. A window function over the second level gives the share. Doing the distinct count first matters bec...