Design Splitwise (expense sharing)
Design an expense-sharing app where friends split bills and can see who owes whom.
Why interviewers ask it
It tests clean modelling of money, validation, and a small algorithm (debt simplification), and it catches people who use floats for money.
Functional requirements
- Users and groups.
- Add an expense paid by one person, split equally, by exact amounts, or by percentage.
- Show balances: who owes whom, and how much.
- Settle up, and simplify the debts in a group.
Non-functional requirements
- Money must be exact: no floating-point errors.
- Splits must always add up to the total.
From version 1 to the final design
- Version 1: equal splits only, stored as pairwise 'A owes B' records.
- Version 2: exact and percentage splits, behind a split strategy that validates them.
- Version 3: one net balance per user, plus debt simplification.
- Version 4: groups, several currencies, history and notifications.
The design, step by step
- Add an expense: validate the split (it sums to the total) → each participant now owes the payer their share.
- Keep one net balance per user: positive means they're owed money, negative means they owe.
- Simplify debts: repeatedly match the biggest debtor with the biggest creditor until everyone is at zero.
Deep dives
- Store money as whole pence (or Decimal), never as float.
- Rounding: £10 split three ways is 334 + 333 + 333 pence; give the extra penny to someone in a fixed, fair way.
- The greedy simplification settles n people in at most n − 1 payments.
Common mistakes
- Storing money as floats: 0.1 + 0.2 is not exactly 0.3, so balances drift. Use whole pence (integers).
- Splits that don't add up to the total.
- Losing the leftover pence when rounding.
Not true: Settling the debts between n people always needs one payment for every pair of people.
In fact: Only the final balances matter. Matching the person who owes the most with the person owed the most settles n people in at most n − 1 payments.
In the interview
Expenses have a payer and a list of splits, created by a split strategy that checks they add up to the total. Each expense updates a net balance per user, stored in whole pence. To settle a group, I greedily match the largest debtor with the largest creditor, which needs at most n − 1 payments.
Part of Unit 7: Low-level design questions in the free System Design course.