Case study · Core

Design Splitwise

Group expense sharing: add an expense, split it (equally / exact / by %), and track who owes whom — then simplify the debts.

Asked atAmazonSplitwiseUberRazorpay
step 1 / 8
1/2Model the domain
members*expenses*howpaidBy
User
- name
- balance
Group
- members
- expenses
+ addExpense()
Expense
- amount
- paidBy
«interface»
SplitStrategy
+ split(amt, n)
EqualSplit
+ split()
BalanceSheet
- owes: Map
+ settle()
Model the domain
1interface SplitStrategy { List<Money> split(Money amt, int n); }
2class EqualSplit implements SplitStrategy { ... } // + Exact, Percent
3 
4class Group { List<User> members; List<Expense> expenses; }
5class Expense { Money amount; User paidBy; SplitStrategy how; }
State
Groupmembers + expenses

A Group aggregates its Users (members) and composes its Expenses. Users exist on their own; expenses belong to the group.