I am Trying to do DDD for splitwise. Use cases are

  1. ability to add, remove, edit transaction with
  2. we should be able to create a group as well as one-one expenditures.
  3. We should be able to show simplified balance so that number of money exchanges are minimised.

Here is what i have come so farenter image description here User: Individual User

TransactionGroup: Group against which transaction can be added (1-1 transactions are also modelled as group with only 2 participants.)

GroupMemebers: Mapping of users in a group.

Transaction: Record of expenditure. example 1: User1 paid 200 split equally among User1, User2. example 2: User1 paid 100, User2 paid 200 split in 40:60. While adding a transaction I will create ledger entries as well.

Ledger: Every transaction is broken into multiple ledger entries telling the effective money lending has happened in a transaction. This table is mainly to calculate Group Account balance. instead of iterating through all the Transactions, I can just use sql queries on ledger table.

Question 1: But I am unsure of how to model simplified view.

Option A: First add transaction, ledger entries then calculate simplified view using ledger entries? This will make simplified view eventually consistent.

Option B: Get existing ledger entries merge it with new transaction and update TransactionGroup, Transaction, Ledger by a lock on TransactionGroup.

Question 2: How to model data archival?

If one group has been active for a very long time. It will accumulate lots of entries and calculating balance using ledger will take a long time. So we just want to carry roll over from transactions older than 1 year. I am planning to get all transaction older than one year. calculate simplifiedView, persist as a transaction. But i am not sure how to model for deletion of older transaction. In the same transaction. Are there better ways to do rollover than What I am thinking of?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.