Sliding Window Velocity Rule for Card Authorizations
Last updated: November 29, 2026
Quick Overview
Implement a streaming check that approves or declines card authorizations so that, per card, no more than K approvals and no more than L cents of approved spend occur in any trailing window of W seconds. Events arrive in time order and only approved authorizations count toward the limits.
American Express
November 29, 20260
0
0 solved
Implement a streaming check that approves or declines card authorizations so that, per card, no more than K approvals and no more than L cents of approved spend occur in any trailing window of W seconds. Events arrive in time order and only approved authorizations count toward the limits.
Velocity rules sit alongside ML fraud scores in the American Express authorization path to stop card testing and rapid cash-out bursts. The interviewer checks a correct O(1) amortized sliding window, exact window boundaries, and awareness of what happens when this runs across many servers.
What the Interviewer Expects
- Keeps a per-card deque of approved events and a running sum
- Evicts expired events before deciding
- Counts only approved transactions
- Defines the window boundary precisely (half-open interval)
- Discusses memory growth and distributed state
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you run this across a fleet of authorization servers with a shared store?
- How would you also limit distinct merchants per card in the window?
- What changes if events can arrive slightly out of order?
- How do you clean up state for cards that go quiet?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: a stream of (ts, card, amount_cents) with non-decreasing ts. Output per event: APPROVE or DECLINE with a reason. The window for an event at ts is (ts - W, ts]. An event is declined ...
High-Level Design
Per card, store a deque of (ts, amount) for approved events in the window and an integer total. On each event: evict from the left while the oldest timestamp is <= ts - W, then test count and amou...