Detect Bursts of Five Failed Payment Attempts Within Ten Minutes
Last updated: November 29, 2026
Quick Overview
From a payment attempts table, flag customers who had five or more failed payment attempts within any ten-minute window, and return when their first such burst started.
Amazon
November 29, 20260
0
0 solved
From a payment attempts table, flag customers who had five or more failed payment attempts within any ten-minute window, and return when their first such burst started.
A risk analytics query in the style of Amazon payments and fraud prevention, where rapid repeated card failures are a classic card-testing signal. The interviewer checks a sliding time window over events, an efficient formulation, and clear behavior at the window boundary.
What the Interviewer Expects
- Filter to failed attempts before ordering
- Use LAG with an offset of four to test five events in ten minutes
- Explain why this equals a sliding window count
- Return the first burst start per customer
- Discuss boundary inclusivity and performance compared to a self-join
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 count failures across different customers sharing one card?
- How would you do this in a streaming system with event-time windows?
- How would you separate fraud bursts from a customer retrying after a bank outage?
- How would you write it with RANGE BETWEEN INTERVAL where supported?
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
Table payment_attempts(customer_id, attempt_ts, result, card_fingerprint) with result in SUCCESS or FAILED. Rule: five failed attempts with the first and fifth no more than ten minutes apart, ...
Approach
The direct approach is a self-join: for each failure, count failures in the following ten minutes. It is O(n times k) and gets expensive for heavy users.
A neater approach: order a customer's failure...