Practice/Amazon/Design an LLD of Splitwise
Object Oriented DesignMust
Design a low-level system for tracking shared expenses among multiple users, similar to expense-sharing applications. The system should allow users to add expenses, split costs in different ways (equally, by exact amounts, or by percentages), track who owes whom, and settle debts between users.
Your implementation should handle the core functionality of managing users, recording expenses with various split strategies, calculating balances, and processing settlements. The system needs to maintain accurate records of all financial transactions and compute net balances efficiently.
User Management: Support adding and managing users in the system
Expense Recording: Allow users to record expenses with a payer and total amount
Split Strategies: Implement three types of expense splitting:
Balance Tracking: Calculate and maintain balances showing who owes money to whom
Debt Settlement: Allow users to settle debts by recording payments between users
Balance Simplification: Compute net balances to minimize the number of transactions needed
Example 1: Equal Split
` Users: Alice, Bob, Charlie Expense: Alice pays $90 for dinner, split equally among all three
Calculation:
Balances:
Example 2: Exact Split
` Users: Alice, Bob, Charlie Expense: Bob pays $100, split as Alice=$20, Bob=$50, Charlie=$30
Calculation:
Balances:
Example 3: Percentage Split
` Users: Alice, Bob, Charlie Expense: Charlie pays $150, split as Alice=50%, Bob=30%, Charlie=20%
Calculation:
Balances:
Example 4: Multiple Expenses
` Users: Alice, Bob Transaction 1: Alice pays $60, split equally
Transaction 2: Bob pays $40, split equally
Net Balances: