Compute Current User Retention Rate From Daily Activity

Last updated: November 29, 2026

Quick Overview

Define a learner as current on day d if they were active on d and at least once in the seven days before d. Using a user_activity table of user_id and activity_date, compute for each day the share of learners who were current the previous day and are active again that day.

Duolingo
Data Manipulation (SQL/Python)
Data Scientist
Duolingo
November 29, 2026
Data Scientist
Onsite
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Define a learner as current on day d if they were active on d and at least once in the seven days before d. Using a user_activity table of user_id and activity_date, compute for each day the share of learners who were current the previous day and are active again that day.

Duolingo has written publicly about modeling growth by splitting daily actives into states such as new, current, reactivated and at-risk, with current user retention as a key lever. Onsite, this checks whether the candidate can turn a precise metric definition into correct SQL with self-joins on date windows.

What the Interviewer Expects
  • Deduplicates multiple activity rows per user per day first
  • Implements the seven-day lookback correctly with an exclusive current day
  • Joins current users on d to activity on d + 1 with a LEFT JOIN
  • Computes a ratio that avoids integer division
  • Explains how to validate with a tiny hand-built dataset
Key Topics to Cover
Self joins
Window-style lookbacks
Retention metrics
Growth accounting
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you compute the other user states (new, reactivated, resurrected) in the same query?
  • How would you make this efficient on billions of rows?
  • Why might CURR move when a streak feature launches even if learning is unchanged?
  • How does the learner's local time zone change the definition of a day?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

user_activity(user_id, activity_date) with possible duplicates; activity_date is the learner's local date. Metric for day t: among learners current on t - 1, the share active on t. Days before the...

Approach

Dedupe to distinct user-days. A user-day is current if an earlier day for the same user falls in [d - 7, d - 1]. Then LEFT JOIN each current user-day to the same user's activity on d + 1 and aggregate...


Submit Your Answer
Markdown supported

Related Questions