Implement a transaction deduplication service
Last updated: August 6, 2025
Quick Overview
Build a service that detects and prevents duplicate payment transactions using a combination of idempotency keys and content-based fingerprinting. Handle time windows, cache eviction, and concurrent lookups.
Affirm
August 6, 202510
11
1,654 solved
Build a service that detects and prevents duplicate payment transactions using a combination of idempotency keys and content-based fingerprinting. Handle time windows, cache eviction, and concurrent lookups.
Duplicate transactions are one of the most costly bugs in fintech. Affirm asks this to test your ability to design and implement a critical financial safety mechanism with proper concurrency handling.
What the Interviewer Expects
- Design a fingerprinting scheme that catches both exact and near-duplicate transactions
- Implement time-windowed deduplication with configurable TTL
- Handle concurrent lookups for the same transaction safely
- Use appropriate data structures for O(1) lookup performance
- Distinguish between intentional retries (same idempotency key) and accidental duplicates
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 handle deduplication across multiple service instances?
- What is the memory impact and how would you bound it?
- How would you handle the case where the same consumer makes two legitimate purchases of the same amount at the same merchant within seconds?
- How would you migrate from in-memory to distributed deduplication?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Deduplication Strategy
Two layers of deduplication: **Layer 1 - Idempotency key**: If the request includes an explicit idempotency key, check if this key has been seen befo...
Data Structure and Implementation
Use two dictionaries with TTL-based eviction: 1. `idempotency_store`: maps idempotency_key -> (timestamp, response, status) 2. `fingerprint_store`: m...