Design an expense sharing app
medium 80 minDivide bills between friends without losing a cent, keep one balance for each person that always adds up to zero, and settle with at most n - 1 payments.
Watch lesson4:24
Where it shows up
The same pattern appears across everyday software.
Splitwise: Simplify Debts
Its help page says that the feature restructures who owes whom in a group to reduce the number of payments, that balances are simplified again with each new expense or payment, and it recommends to look at the total balance.
Splitwise API
Each user in an expense has `paid_share`, `owed_share` and `net_balance`. A group carries both `original_debts` and `simplified_debts`, with a flag `simplify_by_default`.
Cospend for Nextcloud
Each member of a project has a balance computed from the bills, described as relative information: who has spent more for the group than the group for them. A settlement plan lists the payments that reset the balances.
Spliit
An open source web app. Its feature list has group balances, uneven splits, and reimbursement expenses: paying back is stored as a kind of expense.
I Hate Money
A shared budget web application in Python. It keeps track of who bought what, when and for whom, and helps to settle the bills.
Money for PHP
`allocate` rounds everybody's share down and gives the rest one by one, to the one who lost most by rounding first. The same rule as here. Its manual warns that the order of the targets matters.
go-money
`Split` divides and gives the leftover pennies round-robin, so parties listed first get more. Its readme advises against floats and keeps the smallest unit of a currency.
Dinero.js
`allocate` takes ratios, skips zero ratios when it hands out the remainder, and asks for scaled integers in place of fractional ratios: 50.5 becomes amount 505 with scale 1.
Stripe amounts
All API requests take amounts in the minor unit: 1000 for 10 USD, but 10 for 10 JPY, because the yen has no smaller unit.