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
Coding & Algorithms
Software Engineer
Affirm
August 6, 2025
Software Engineer
Onsite Coding Round
Coding & Algorithms
Medium

10

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
Idempotency key management
Content-based hashing and fingerprinting
TTL-based cache eviction
Thread-safe data structures
False positive vs false negative tradeoffs
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample Answer
Problem Analysis

The problem requires detecting and preventing duplicate payment transactions in a fintech environment. The key elements here are managing idempotency keys and using content-based fingerprinting to ide...

Approach
  1. Fingerprinting Scheme: First, we will create a hashing function that generates a unique fingerprint for each transaction based on its content (amount, timestamp, payer ID, etc.). This will help...

Submit Your Answer
Markdown supported

Related Questions