KatInterview

Design a Dispute Record Ingestion and Daily Batch Export System

System DesignModel answer
EasyModel answerSystem Designdistributed-systemsdata-pipelineidempotency

Last updated

Design a system that reliably ingests high-volume dispute events from external networks and exports a daily batch file to a downstream accounting system.

Context

You work on the platform team at a payments company. External card networks notify your system whenever a cardholder disputes a transaction — these are called dispute events. Your job is to build the backend infrastructure that accepts those events and feeds them into the company's internal accounting system on a daily basis.

What the system must do

Ingestion External networks push events to your service over HTTPS. Each event contains a transaction ID, dispute amount, currency code, merchant ID, and a timestamp. Your endpoint must respond quickly and hand off work asynchronously — it cannot block waiting for downstream processing.

No data loss Every event must be durably captured, even if your database is temporarily unavailable or a downstream service is slow. The system must also survive network timeouts without losing data.

Duplicate prevention External networks frequently retry events that didn't receive a timely acknowledgment. Your system must recognize and ignore duplicates without producing extra records.

Daily export Once every 24 hours, produce a CSV file containing all dispute records from the previous day and deliver it to the internal accounting system via SFTP.

Audit trail Each record should carry a status reflecting where it is in the pipeline — for example: received, queued, staged, and exported.

Scale

  • Roughly 50,000 events per day under normal conditions
  • Up to 5× that volume during high-traffic periods (major shopping events, holidays)
  • Any cardholder-identifying data must be encrypted at rest

What your answer should cover

  1. A component-level architecture — a diagram or a clearly labeled list of services and how they connect
  2. A database schema covering both dispute records and export batches
  3. How you handle retries for failed incoming events and failed SFTP uploads
  4. How you keep the daily export consistent when new events are arriving at the same time the file is being generated

Hints

Hint 1

Before designing anything, size the problem. 50,000 events/day is under 1 event/second on average, even at 5× peak you're only around 3/s sustained. This is a correctness and reliability problem, not a throughput one — let that guide your architecture choices.

Hint 2

Think carefully about what makes a good idempotency key. A transaction ID alone isn't safe — one transaction can generate multiple partial disputes. The combination of network name and the network's own event ID is the right dedupe key.

Hint 3

Separate the generation of the export file from the act of uploading it. If you store the CSV in object storage first and upload from there, retrying a failed upload is trivially safe — you just resend the same bytes without regenerating anything.