Deduplicate Webhook Events and Report Each Payment Intent's Latest Status
Last updated: November 29, 2026
Quick Overview
Given a table of webhook events your service received (with duplicate deliveries and out-of-order arrival), write SQL that returns one row per payment intent with its latest status according to when Stripe created the event, not when you received it.
Stripe
November 29, 20260
0
0 solved
Given a table of webhook events your service received (with duplicate deliveries and out-of-order arrival), write SQL that returns one row per payment intent with its latest status according to when Stripe created the event, not when you received it.
Stripe delivers webhooks at least once and does not guarantee order, so anyone building on Stripe data must deduplicate and order events correctly, and Stripe SQL screens test this directly. The interviewer checks for ROW_NUMBER-based deduplication, ordering by event time rather than arrival time, and a deliberate tiebreak when two events share a timestamp.
What the Interviewer Expects
- Deduplicates on event_id, keeping one copy per event
- Orders by event creation time, not received_at
- Breaks ties between same-timestamp events deterministically, preferring terminal states
- Uses window functions instead of a correlated subquery
- Explains why naive MAX(received_at) gives wrong answers
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 turn this into an incremental model that processes only new events each hour?
- What if a payment intent legitimately goes from succeeded to refunded later?
- How would you detect payment intents that are stuck in processing for more than a day?
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
webhook_events(event_id, payment_intent_id, status, event_created, received_at). One Stripe event can arrive several times (retries after a timeout), so event_id repeats. Events can also arrive ou...
Approach
- Keep one copy per
event_idwithROW_NUMBER(); which copy does not matter because the payload is identical. - Rank each payment intent's events by
event_created DESC. - On ties, prefer termi...