Write SQL for app metrics
NextdoorData Engineer · Technical ScreenLast updated
This question evaluates proficiency in SQL-based data engineering, focusing on time-zone-aware timestamp handling, aggregation of event and relationship data, cohort retention analysis, and computation of product metrics like DAU, new users, photo activity, and follower distributions.
You are given a simplified schema for a photo-sharing app:
users(user_id, user_name, joined_at)photos(photo_id, user_id, created_at)follows(follower_user_id, followed_user_id, created_at)user_events(event_id, user_id, event_type, occurred_at)
Assume all timestamps are stored in UTC. Unless otherwise stated, reporting should use the America/Los_Angeles timezone. A row in follows represents a follow created at created_at and still active afterward. DAU means the number of distinct users with at least one row in user_events on that local calendar day.
Also assume the dashboard is backed by these aggregate tables:
kpi_daily_base(report_date, new_users, total_users_eod, dau, new_photos, total_follow_edges_eod)follower_bucket_daily(report_date, bucket, user_count)wherebucketis one of0,1_2, or3_plusretention_cohort_daily(cohort_date, cohort_size, retained_w1_users)
Write SQL for the following tasks:
- Count the total number of users.
- Find the calendar month with the highest number of new user signups.
- Find the user with the largest follower count.
- Populate the daily aggregate tables from the raw tables so the dashboard can report:
- new users
- change versus 7 days earlier
- DAU
- change versus 7 days earlier
- new photos
- new photos per DAU
- change versus 7 days earlier
- total follower relationships
- percentage of users with 0 followers
- percentage of users with 1-2 followers
- percentage of users with 3+ followers
- Extend the SQL to compute week-1 retention, defined as: among users who signed up on day
D, the share who had at least one event on daysD+7throughD+13in the reporting timezone.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.