KatInterview

Build a Royalty Settlement System for Music Streaming

System DesignModel answer
MediumModel answerSystem Designdistributed-systemsfinancial-transactionsidempotency

Last updated

Design infrastructure to compute artist earnings from streaming activity, close monthly accounting windows, and execute payments with idempotency guarantees.

You're building a backend for a music streaming platform. Every month, artists earn money based on how many times their tracks were played. Your job is to design the system that ingests play events, determines which ones qualify for payment, groups them by artist, computes what each artist is owed, and sends that money through a third-party payment API.

The payment API requires an idempotency key with every request—if you retry with the same key, it won't send duplicate funds. Your system must be auditable: finance and legal teams need to trace every dollar from raw plays to completed transfers.

What You Need to Address

  1. Event ingestion and validity: How do you receive play events? What makes a play "valid" for payment? How do you handle duplicates or fraud flags that arrive days later?

  2. Monthly boundary handling: When does a month officially close? Can corrections or late events affect a closed month, and if so, how?

  3. Payout calculation and storage: How do you store the amount owed to each artist? What data model ensures you can recalculate or audit any month's numbers?

  4. Idempotency and retry safety: How do you generate idempotency keys? What happens if your payment request times out—how do you know whether the money was sent?

  5. Reconciliation: The payment provider sends webhooks and offers a reconciliation API. How do you confirm that what you think you paid matches what actually left your account?

  6. Late adjustments: A rights dispute is resolved two months after the original period. How do you handle the correction without reopening closed books?

Start by stating your assumptions (validity rules, payout rates, provider SLAs), then walk through the architecture and data models that satisfy these requirements.

Hints

Hint 1

Think about separating the 'obligation to pay' from the 'act of paying'—these are two different concerns with different consistency needs.

Hint 2

Use versioned aggregates or snapshots so you can recompute without mutating history.

Hint 3

Design your idempotency keys to be deterministic and include everything that makes a payment unique: who, when, and which version of the data.