Bird
0
0

In a system where transactions can arrive out of order, how should the balance calculation algorithm be adapted?

hard📝 Trade-off Q9 of 15
LLD - Design — Splitwise (Expense Sharing)
In a system where transactions can arrive out of order, how should the balance calculation algorithm be adapted?
AProcess only the latest transaction received
BIgnore transaction order and sum all amounts
CUse timestamps to order transactions before applying them
DReset balance after each transaction
Step-by-Step Solution
Solution:
  1. Step 1: Recognize out-of-order arrival problem

    Transactions arriving out of order can cause incorrect balances if processed as received.
  2. Step 2: Use timestamps to order

    Ordering by timestamps ensures transactions are applied in correct sequence.
  3. Final Answer:

    Use timestamps to order transactions before applying them -> Option C
  4. Quick Check:

    Out-of-order fix = Timestamp ordering [OK]
Quick Trick: Sort transactions by time before processing [OK]
Common Mistakes:
  • Ignoring order causing wrong balances
  • Processing only latest transaction
  • Resetting balance unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes