Design Splitwise

Intermediate · 26 min read · Low-Level Design, Case Studies: Advanced

Expenses, split strategies, balances and debt simplification.

Splitwise is one of the most common machine-coding problems in Indian product-company interviews. It looks simple, but tests money handling (rounding!), the Strategy pattern for split types, a clean balance model, and — as a classic follow-up — debt simplification.

What the interviewer expects

The full design in this lesson is longer than anything you'd write in one round. It's there so you understand the edge cases and can answer follow-up questions. In the round itself, aim for this:

1. Requirements

2. Money and rounding

Splitting ₹100 three ways gives ₹33.33… per person. Rules:

3. Class design

4. Implementation

largestRemainder allocates amount × weight / totalWeight (floored) to each participant, then hands out the leftover paise to those with the largest fractional remainders — so parts always sum exactly to the total:

5. Debt simplification

Given net balances, minimise the number of payments. Example: A owes B ₹100, B owes C ₹100 → simplified: A pays C ₹100 (one transaction instead of two).

6. Patterns used

7. Extensions

Interview questions

  • How do you split ₹100 among three people without losing a paisa?
  • How would you minimise the number of transactions needed to settle a group?
  • Why use the Strategy pattern for split types?

Further reading

Key takeaways

  • Use integer paise and distribute remainders so splits sum exactly.
  • Each split type is a strategy with its own validation.
  • Keep a netted pairwise ledger; derive net balances from it.
  • Greedy simplification uses at most N − 1 payments; the true minimum is NP-hard.

Previous: Design a Key-Value Store with Transactions · Next: Design a Movie Ticket Booking System