KatInterview

Building a Transaction Dispute Resolution System

System DesignModel answer
MediumModel answerSystem Designdistributed-systemsfinancial-systemsstate-machines

Last updated

Design a backend system to manage the complete lifecycle of payment disputes in an e-commerce marketplace, including evidence handling, deadline management, and financial settlements.

Problem Context

You're building a backend system for an e-commerce marketplace where buyers can formally challenge transactions when problems arise—items never delivered, significant mismatches with descriptions, or charges they didn't authorize. After informal attempts to resolve issues fail, buyers need a structured process to submit disputes, provide supporting materials, and reach resolution.

Your Task

Design the backend architecture for a transaction dispute resolution system that handles the complete dispute workflow from creation through final settlement.

System Requirements

Functional Capabilities

  1. Dispute Initiation & Validation: Check whether a transaction qualifies for dispute based on purchase timing, current order state, and platform policies before allowing dispute creation.

  2. Supporting Materials Management: Enable both parties to submit documents and written statements within time-bound windows (example: sellers get 5 business days to respond).

  3. Lifecycle Management & Time Enforcement: Track disputes through defined stages (OPEN, AWAITING_SELLER_RESPONSE, PLATFORM_REVIEW, RESOLVED_FOR_BUYER, RESOLVED_FOR_SELLER, CLOSED). Automatically progress or close cases when response periods expire.

  4. Temporary Funds Handling & Final Settlement: Issue temporary credits to buyers or freeze seller funds as needed, then execute final money movement based on resolution outcome. All financial operations must be idempotent.

  5. Payment Gateway Integration: Communicate dispute information with external payment processors (credit card networks, third-party payment services) using reliable, retry-safe interfaces.

  6. Change Tracking & Notifications: Record every action and state change in an immutable log while sending asynchronous updates to participants at important milestones.

Scale & Performance Targets

  • User base: 50 million marketplace users
  • Dispute volume: 200,000 new cases monthly (~5,000 daily)
  • File uploads: Up to 15 MB per file for evidence submission
  • Consistency requirement: Financial operations and state transitions must prevent duplicate refunds or credits
  • Security requirement: Uploaded files must be screened for threats; customer information must have strict access controls

Expected Design Elements

Your solution should address:

  • API Interface: Key endpoints for creating disputes, submitting evidence, checking status, and resolving cases
  • Data Schema & State Tracking: Database design for disputes, evidence metadata, deadlines, and state progression
  • Component Architecture: System diagram showing request handling, background processing, storage, and external service integration
  • Failure Scenarios: How to handle gateway timeouts, simultaneous file uploads, state transition conflicts, and malicious file uploads

Hints

Hint 1

The challenge is correctness, not scale—200K disputes per month is manageable with a single database. Focus on preventing duplicate financial operations and ensuring state transitions are atomic.

Hint 2

Use optimistic concurrency control (version numbers) to handle concurrent state updates safely. A conditional UPDATE that checks current state and version will naturally serialize competing transitions.

Hint 3

Separate side effects (notifications, gateway calls) from state changes using the transactional outbox pattern—write an event row in the same transaction as the state change, then process it asynchronously.