shuffleet
Home
Practice
Problems
Lessons
Plans
Compete
Challenges
Interviews
Leaderboard
Progress
Skills
Analytics
Submissions
Account
Settings

Cohorts and retention

Intermediate · 4 min read

In two sentences

A cohort is a group of users who started in the same period, January sign-ups for example; retention is the share of them still active one, two, three periods later. Growth accounting goes one step further and splits each month's active users into new, retained and resurrected, with churned users on the other side.

See it

Monthly activity of four users:

userJanFebMar
a✓✓✓
b✓✓
c✓
d✓

Retention by cohort (month of first activity):

cohortsizemonth 0month 1month 2
Jan2100%50%100%
Feb1100%0%
Mar1100%

Growth accounting for March: active 3 = new 1 (d) + retained 1 (a) + resurrected 1 (b). Churned: 1 (c, active in February, not in March).

A retention grid by cohort, and March's active users split into new, retained and resurrected, with churned below

In SQL

One row per user per active month, each user's cohort, then the grid:

SQL
WITH monthly AS (
  SELECT DISTINCT user_id, date_trunc('month', day) AS month
  FROM activity
),
cohort AS (
  SELECT user_id, min(month) AS cohort FROM monthly GROUP BY user_id
),
size AS (
  SELECT cohort, count(*) AS n FROM cohort GROUP BY cohort
)
SELECT c.cohort,
       date_diff('month', c.cohort, m.month) AS month_n,
       count(*) AS active,
       count(*) * 1.0 / max(size.n) AS retention
FROM monthly m
JOIN cohort c ON c.user_id = m.user_id
JOIN size ON size.cohort = c.cohort
GROUP BY c.cohort, date_diff('month', c.cohort, m.month);

Growth accounting labels each active user-month:

SQL
SELECT month,
       count_if(is_new)                                   AS new,
       count_if(NOT is_new AND active_last_month)         AS retained,
       count_if(NOT is_new AND NOT active_last_month)     AS resurrected
FROM (
  SELECT m.user_id, m.month,
         m.month = (SELECT min(x.month) FROM monthly x WHERE x.user_id = m.user_id) AS is_new,
         EXISTS (SELECT 1 FROM monthly p
                 WHERE p.user_id = m.user_id AND p.month = m.month - INTERVAL '1' MONTH) AS active_last_month
  FROM monthly m
) AS labeled
GROUP BY month;

Churned in a month is everyone active the month before and not this month, so: churned = active(last month) − retained. For March: 2 − 1 = 1.

When to use it

questionmetric
do new users stick?retention by sign-up cohort
is the product getting better at keeping people?compare month-1 retention across cohorts
why did active users grow or shrink?growth accounting: new + resurrected − churned
how healthy is growth?quick ratio: (new + resurrected) / churned; above 1 means growing

Best practices

  • Define "active" once, in words: logged in, or did the key action? Retention moves a lot with that choice.
  • Use the same period everywhere: weekly cohorts with monthly activity give numbers nobody can compare.
  • Exclude cohorts that haven't had time: March can't have a month-2 retention yet. Show it empty, not 0%.
  • Build activity on a spine (see Date spines) when you need inactive months as rows, for example to find resurrected users across gaps.
  • Check the identity: active(month) = new + retained + resurrected, and churned = active(previous) − retained. If it doesn't balance, a label is wrong.

Common mistakes

  • Counting events instead of users. One user with 50 sessions isn't 50 retained users. DISTINCT per user per period first.
  • Retention over the total user base instead of the cohort: new sign-ups inflate the denominator.
  • Today's partial month in the grid. The current month always looks like a drop.
  • Users with activity before tracking started look "new" in the first month of data. Start the analysis one period later, or mark that first cohort as incomplete.

What an interviewer asks next

  • "Retention dropped for the March cohort. What do you check?" Acquisition mix (a campaign bringing different users), product changes that month, then tracking changes.
  • "Monthly active users are flat. Is that fine?" Not necessarily: high new + high churn looks flat. Growth accounting shows it.

Go further

Amplitude's article on growth accounting explains the four categories and the quick ratio, with the same identities as above.

Practise it

Rolling 7-Day Active Users for Every Day, then Monthly Retention Cohorts, then Growth Accounting: New, Retained, Resurrected and Churned Users (hard).