AlgoMaster Logo

Design Splitwise

Ashish

Ashish Pratap Singh

medium

Splitwise is a popular expense-sharing application that helps groups of people such as roommates, friends, coworkers, or travelers split bills and keep track of who owes whom.

Splitwise

Rather than requiring users to settle up after every expense, Splitwise allows them to log payments as they happen. It maintains a running balance for each user, tracking how much they owe or are owed.

In this chapter, we will explore the low-level design of a splitwise like service in detail.

Lets start by clarifying the requirements:

1. Clarifying Requirements

Before starting the design, it's important to ask thoughtful questions to uncover hidden assumptions and better define the scope of the system.

Here is an example of how a discussion between the candidate and the interviewer might unfold:

1.1 Functional Requirements

  • Support creation of both one-to-one and group expenses
  • Allow expenses to be split using different methods, such as equal split and exact amount
  • Track how much each user owes and is owed, across individuals and groups
  • Maintain a history of all expenses, payments, and settlements
  • Support partial settlements and update balances accordingly
  • Allow users to view outstanding balances per user and per group
  • Implement a debt simplification feature to minimize the number of transactions required to settle up

1.2 Non-Functional Requirements

  • Modularity: The design should be modular and follow object-oriented principles for easy maintenance and extension
  • Consistency: Expense updates and settlements should reflect accurately and immediately in the balance calculations
  • Extensibility: The system should be flexible enough to support additional split types (e.g., percentage-based) and multiple currencies
  • Thread-Safety: Multiple users might add expenses concurrently. Balance updates should be thread-safe to avoid race conditions.

After the requirements are clear, lets identify the core entities/objects we will have in our system.

2. Identifying Core Entities

Premium Content

This content is for premium members only.