Deduplicate Meta Pay Charges by Idempotency Key and Final Status
Last updated: November 29, 2026
Quick Overview
Meta Pay retries charge requests with the same idempotency key, producing several rows with statuses like pending, failed, and succeeded. Produce one row per idempotency key with its final status and compute daily successful charge volume without double counting.
Meta
November 29, 20260
0
0 solved
Meta Pay retries charge requests with the same idempotency key, producing several rows with statuses like pending, failed, and succeeded. Produce one row per idempotency key with its final status and compute daily successful charge volume without double counting.
Payment correctness at Meta Pay depends on treating retries as one logical charge. The interviewer checks a precedence-aware dedupe (success beats failure beats pending) and how you join back to merchant info without duplication.
What the Interviewer Expects
- Groups by idempotency key rather than request id
- Applies a status precedence instead of latest timestamp alone
- Keeps amount and timestamp from the chosen row with a window function
- Flags keys with more than one success as a separate anomaly
- Joins the merchant dimension after dedupe
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
- What if two retries with the same key have different amounts?
- Why not just take the latest row per key?
- How would you surface double charges to the on-call?
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
charge_attempts(attempt_id, idem_key, merchant_id, amount_usd, status, created_at) with status in ('pending', 'failed', 'succeeded'). Retries share idem_key. A late 'failed' log can arrive after a...
Approach
Rank attempts per key by status precedence (succeeded 1, failed 2, pending 3), then by created_at so the earliest success is kept. That row is the logical charge. Separately count successes per key:...