---
# System prepended metadata

title: System Design

---

# System Design 

Design a wallet system where users can: 
1. Check account balance
2. Check transaction history
3. Transfer money to each other (internal)

![](https://i.imgur.com/88fBBSY.png)


3.  Transfer money to each other
    POST /transfer payloan from:a, to: b id ammount: 2000
    check balance a
        if balace a < amount && balance < 0 
        throw unsuficience balance
        
    new balance balance - ammount
        put transaction to transactions db table bellow
    
    balace b = balanceb + amount
    

| wallet| amount | type |transaction id|balace|
| -------- | -------- | -------- |
|    a  | -2000     | debet     |a1|98000
| b  |  2000 | credit | a1|5200

        
    
    
    
2. Check transaction history
    GET transaction/walletid 
    
    select * from transactions where wallet == walletId
    
    return result
    
    
    
1. GET wallet/id
    sum amount where wallet = id
    
    
3. POST /transfer payloan from:a, to: b id ammount: 2000, transactionid = transactionid
    if amount < 0 throw error
    select * from transactions where transactionid = transactionid
    if transaction > 0 throw error transaction already process
    produce.transactions
    return no content
    consumer.transactions
        balance = sum amount where wallet = from
        
        if balance < ammount
            prouce.trasansaction done status failed messange unsufucience balance
        
        put transactions table as example table above
            prouce.trasansaction done status success messange success
