Deduplicate Retried Payment Webhooks Before Daily Revenue Totals

Last updated: November 29, 2026

Quick Overview

A webhook_events table receives duplicate deliveries because senders retry until they get a 200. Write a query that keeps one row per payment and event type, then reports daily captured, refunded and net amounts.

PayPal
Data Manipulation (SQL/Python)
Data Engineer
PayPal
November 29, 2026
Data Engineer
Phone Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


A webhook_events table receives duplicate deliveries because senders retry until they get a 200. Write a query that keeps one row per payment and event type, then reports daily captured, refunded and net amounts.

PayPal's webhooks are delivered at least once, so any analytics built on raw deliveries double counts. This SQL screen checks whether you identify the natural dedup key, use ROW_NUMBER deterministically, and filter event types before aggregating.

What the Interviewer Expects
  • Identify (payment_id, event_type) as the logical dedup key, not event_id
  • Use ROW_NUMBER with a deterministic ORDER BY
  • Filter to relevant event types before deduplicating
  • Aggregate captures and refunds separately, then net
  • Keep amounts in integer minor units
Key Topics to Cover
ROW_NUMBER
deduplication
at-least-once delivery
conditional aggregation
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
  • What if a legitimate second partial capture exists for the same payment?
  • How would you make this incremental for a daily pipeline with late-arriving events?
  • Which timestamp should define the reporting day, received_at or the event's own create_time?
  • How would you alert when the duplicate rate spikes?
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

webhook_events(event_id, payment_id, event_type, amount_cents, received_at). Each delivery attempt gets a new event_id, so event_id is not the dedup key. Assume one capture and at most one full ...

Approach

Rank deliveries within each (payment_id, event_type) by arrival time, keep rank 1, then conditionally sum by day. Ordering by received_at, event_id breaks ties deterministically so reruns produce ...


Submit Your Answer
Markdown supported