Thirty Day Recovery Rate For First Time Payment Declines

Last updated: November 29, 2026

Quick Overview

Given payment_attempts(attempt_id, bill_id, attempted_at, status), find bills whose first attempt was declined and report what share were recovered by a successful attempt within 30 days of that first decline, broken out by the week of the first decline.

Patreon
Data Manipulation (SQL/Python)
Data Engineer
Patreon
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given payment_attempts(attempt_id, bill_id, attempted_at, status), find bills whose first attempt was declined and report what share were recovered by a successful attempt within 30 days of that first decline, broken out by the week of the first decline.

Involuntary churn from declined cards is a large share of lost creator income, and Patreon's payments team tunes retries and card updater flows against recovery rate. The interviewer checks window functions, correct anchoring on the first attempt, and time-bounded joins.

What the Interviewer Expects
  • Identifies the first attempt per bill with ROW_NUMBER and a deterministic tie-break
  • Keeps only bills whose first attempt declined
  • Bounds recovery to successes strictly after the decline and within 30 days
  • Uses a LEFT JOIN so unrecovered bills stay in the denominator
  • Groups by week with a stable truncation function
  • Avoids counting a bill twice when several later attempts succeed
Key Topics to Cover
window functions
time-bounded joins
decline recovery
cohorting by week
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 attribute recovery to the retry engine versus the fan updating their card?
  • Recent weeks have not had 30 days to recover yet. How do you present them?
  • How would you build this as an incremental daily table instead of a full scan?
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

One row per attempt to charge a bill (a membership period). status is succeeded or declined. Attempts can share a timestamp, so tie-break on attempt_id. A bill should not succeed twice, but us...

Approach
  1. Rank attempts per bill by time. 2. Keep bills where rank 1 is a decline, anchored at first_decline_at. 3. Find the earliest success after the anchor and within 30 days. 4. LEFT JOIN back and aggr...

Submit Your Answer
Markdown supported

Related Questions