Skip to content
This repository was archived by the owner on May 18, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
# **High Level Design for SplitWise**
## Functional Requirements
~ Users Can be sign up/ sign in to your system<br />
~ Users can add thier contacts in the system by email or phone<br />
~ Users can add Expense in the System with multiple contacts<br />
~ Users can create groups and can add group expense with the group members<br />
~ System has to show balance report of all users<br />
~ System can show balance report of particular User<br />
~ System can show balance report of all and particular group <br />

## Non Functional Requirements<br />
~The system should be highly available.Because if the service is down , no user will be able to access it.<br />

## Extended Requirements<br />
~System can simplyfy debts<br />
~System can show passbook to user.The entries should show all the transactions a user was part of<br />

## Capacity Estimation
Read will be more than writes in this system.Lets assume if each user has 20 contacts . So read vs write ratio will be 20:1.<br />
## Traffic estimates<br />
Lets assume we have 20M new users per month with 20:1 read and write then we can expect 20*20M =>400M read<br />
#### Queries per Second (QPS) will be 20M / (30 days * 24 hours * 3600 sec) ~= 7.71 write/sec<br />
#### Consedering 20:1 read to write request 20 * 7.71 ~= 154.2 read/sec<br />

## Storage Estimates<br />
Lets assume we are saving the expense over the year of 5 years then 20M write request every month, total number of obects we<br />
expect to store will be : 20M * 5years * 30 months ~= 3Billion<br />
if each object stored take 500 Byte . Total storage we need is ~= 3B * 500 ~= 1.5TB<br />

## BandWidth estimates <br />
For Write Request<br />
Since there are 7.7 write request every sec , so total incoming data for our service will be : 7.7 * 500Bytes =~ 3.75 Kb/sec<br />
For Read Request<br />
Since there are 154.2 read request every sec , so total outgoing data for our service will be : 154.2 * 500Bytes =~ 75.29 Kb/sec <br />

## Basic System Design <br />

![SplitWise_HLD](https://user-images.githubusercontent.com/8611287/84053046-00810000-a9cf-11ea-8a05-3c6676b1373b.png)


# mock-machine-coding-2
Welcome to the 2nd Mock Machine Coding Round by [workat.tech](http://workat.tech).

Expand Down
Binary file added SplitWise_low_level_uml.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
234 changes: 234 additions & 0 deletions Splitwise.uml
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
<?xml version="1.0" encoding="UTF-8"?>
<Diagram>
<ID>JAVA</ID>
<OriginalElement>com.splitwise.driver</OriginalElement>
<nodes>
<node x="998.7444444444445" y="0.0">com.splitwise.model.User</node>
<node x="364.0" y="789.5">com.splitwise.splitStrategy.impl.SplitByExact</node>
<node x="772.0" y="789.5">com.splitwise.splitStrategy.impl.SplitByEqual</node>
<node x="1179.0833333333333" y="624.0">com.splitwise.model.UserRegistry</node>
<node x="717.9944444444446" y="388.0">com.splitwise.model.ExpenseTransactionInfo</node>
<node x="891.0" y="940.0">com.splitwise.transactionFactory.ExpenseTransaction</node>
<node x="1850.1666666666665" y="1167.0">com.splitwise.process.TransactionProcesser</node>
<node x="1840.1666666666665" y="988.5">com.splitwise.transactionFactory.BalanceTransaction</node>
<node x="1719.0833333333333" y="777.5">com.splitwise.transactionFactory.Transaction</node>
<node x="1969.6683618233617" y="624.0">com.splitwise.io.InputTxtReader</node>
<node x="1440.0833333333333" y="765.0">com.splitwise.driver.SplitwiseDriver</node>
<node x="1596.4166666666665" y="412.0">com.splitwise.model.Expense</node>
<node x="0.0" y="789.5">com.splitwise.splitStrategy.impl.SplitByPercent</node>
<node x="546.5" y="636.5">com.splitwise.splitStrategy.SplitStartegy</node>
</nodes>
<notes />
<edges>
<edge source="com.splitwise.transactionFactory.BalanceTransaction" target="com.splitwise.driver.SplitwiseDriver">
<point x="-92.66666666666669" y="-40.0" />
<point x="1886.4999999999998" y="910.0" />
<point x="1634.3333333333333" y="910.0" />
<point x="64.75" y="52.5" />
</edge>
<edge source="com.splitwise.splitStrategy.impl.SplitByEqual" target="com.splitwise.splitStrategy.SplitStartegy">
<point x="-114.66666666666674" y="-28.0" />
<point x="829.3333333333333" y="745.0" />
<point x="847.5" y="745.0" />
<point x="129.0" y="28.0" />
</edge>
<edge source="com.splitwise.model.UserRegistry" target="com.splitwise.model.User">
<point x="-95.0" y="-40.5" />
<point x="1274.0833333333333" y="604.0" />
<point x="1353.2444444444445" y="604.0" />
<point x="1353.2444444444445" y="368.0" />
<point x="1182.7829059829062" y="368.0" />
<point x="24.538461538461547" y="149.0" />
</edge>
<edge source="com.splitwise.model.ExpenseTransactionInfo" target="com.splitwise.model.User">
<point x="-74.66666666666674" y="-88.0" />
<point x="755.3277777777779" y="348.0" />
<point x="1060.0905982905983" y="348.0" />
<point x="-98.15384615384619" y="149.0" />
</edge>
<edge source="com.splitwise.splitStrategy.impl.SplitByExact" target="com.splitwise.splitStrategy.SplitStartegy">
<point x="114.66666666666674" y="-28.0" />
<point x="650.6666666666667" y="745.0" />
<point x="675.5" y="745.0" />
<point x="-43.0" y="28.0" />
</edge>
<edge source="com.splitwise.transactionFactory.ExpenseTransaction" target="com.splitwise.transactionFactory.Transaction">
<point x="209.33333333333326" y="-88.5" />
<point x="1335.8333333333333" y="920.0" />
<point x="1765.4166666666665" y="920.0" />
<point x="-92.66666666666667" y="40.0" />
</edge>
<edge source="com.splitwise.process.TransactionProcesser" target="com.splitwise.transactionFactory.BalanceTransaction">
<point x="0.0" y="-52.5" />
<point x="0.0" y="40.0" />
</edge>
<edge source="com.splitwise.transactionFactory.ExpenseTransaction" target="com.splitwise.splitStrategy.impl.SplitByEqual">
<point x="-52.333333333333485" y="-88.5" />
<point x="1074.1666666666665" y="890.0" />
<point x="944.0" y="890.0" />
<point x="0.0" y="28.0" />
</edge>
<edge source="com.splitwise.process.TransactionProcesser" target="com.splitwise.transactionFactory.ExpenseTransaction">
<point x="-103.19999999999999" y="-52.5" />
<point x="1875.9666666666665" y="1147.0" />
<point x="1126.5" y="1147.0" />
<point x="0.0" y="88.5" />
</edge>
<edge source="com.splitwise.transactionFactory.BalanceTransaction" target="com.splitwise.transactionFactory.Transaction">
<point x="0.0" y="-40.0" />
<point x="1979.1666666666665" y="920.0" />
<point x="1950.75" y="920.0" />
<point x="92.66666666666669" y="40.0" />
</edge>
<edge source="com.splitwise.transactionFactory.ExpenseTransaction" target="com.splitwise.splitStrategy.impl.SplitByExact">
<point x="-157.0" y="-88.5" />
<point x="969.5" y="910.0" />
<point x="536.0" y="910.0" />
<point x="0.0" y="28.0" />
</edge>
<edge source="com.splitwise.splitStrategy.impl.SplitByPercent" target="com.splitwise.splitStrategy.SplitStartegy">
<point x="114.66666666666674" y="-28.0" />
<point x="286.66666666666674" y="745.0" />
<point x="589.5" y="745.0" />
<point x="-129.0" y="28.0" />
</edge>
<edge source="com.splitwise.transactionFactory.ExpenseTransaction" target="com.splitwise.model.User">
<point x="104.66666666666674" y="-88.5" />
<point x="1231.1666666666667" y="910.0" />
<point x="1168.5833333333333" y="910.0" />
<point x="1168.5833333333333" y="358.0" />
<point x="1158.2444444444445" y="358.0" />
<point x="0.0" y="149.0" />
</edge>
<edge source="com.splitwise.splitStrategy.impl.SplitByEqual" target="com.splitwise.model.ExpenseTransactionInfo">
<point x="0.0" y="-28.0" />
<point x="944.0" y="604.0" />
<point x="848.6611111111114" y="604.0" />
<point x="18.666666666666742" y="88.0" />
</edge>
<edge source="com.splitwise.io.InputTxtReader" target="com.splitwise.process.TransactionProcesser">
<point x="100.5" y="40.5" />
<point x="2204.168361823362" y="745.0" />
<point x="2148.168361823362" y="745.0" />
<point x="2148.168361823362" y="1147.0" />
<point x="2082.366666666667" y="1147.0" />
<point x="103.20000000000005" y="-52.5" />
</edge>
<edge source="com.splitwise.splitStrategy.impl.SplitByExact" target="com.splitwise.model.ExpenseTransactionInfo">
<point x="0.0" y="-28.0" />
<point x="536.0" y="594.0" />
<point x="773.9944444444446" y="594.0" />
<point x="-56.0" y="88.0" />
</edge>
<edge source="com.splitwise.driver.SplitwiseDriver" target="com.splitwise.io.InputTxtReader">
<point x="74.0" y="-52.5" />
<point x="1643.5833333333333" y="735.0" />
<point x="2003.1683618233617" y="735.0" />
<point x="-100.5" y="40.5" />
</edge>
<edge source="com.splitwise.splitStrategy.impl.SplitByEqual" target="com.splitwise.model.User">
<point x="114.66666666666674" y="-28.0" />
<point x="1058.6666666666667" y="745.0" />
<point x="1157.5833333333333" y="745.0" />
<point x="1157.5833333333333" y="368.0" />
<point x="1133.705982905983" y="368.0" />
<point x="-24.538461538461547" y="149.0" />
</edge>
<edge source="com.splitwise.splitStrategy.impl.SplitByPercent" target="com.splitwise.model.ExpenseTransactionInfo">
<point x="0.0" y="-28.0" />
<point x="172.0" y="584.0" />
<point x="736.6611111111114" y="584.0" />
<point x="-93.33333333333326" y="88.0" />
</edge>
<edge source="com.splitwise.transactionFactory.ExpenseTransaction" target="com.splitwise.model.ExpenseTransactionInfo">
<point x="0.0" y="-88.5" />
<point x="1126.5" y="594.0" />
<point x="885.9944444444446" y="594.0" />
<point x="56.0" y="88.0" />
</edge>
<edge source="com.splitwise.transactionFactory.ExpenseTransaction" target="com.splitwise.driver.SplitwiseDriver">
<point x="157.0" y="-88.5" />
<point x="1283.5" y="910.0" />
<point x="1504.8333333333333" y="910.0" />
<point x="-64.75" y="52.5" />
</edge>
<edge source="com.splitwise.splitStrategy.SplitStartegy" target="com.splitwise.model.ExpenseTransactionInfo">
<point x="0.0" y="-28.0" />
<point x="718.5" y="604.0" />
<point x="811.3277777777779" y="604.0" />
<point x="-18.666666666666742" y="88.0" />
</edge>
<edge source="com.splitwise.model.Expense" target="com.splitwise.model.User">
<point x="0.0" y="-64.0" />
<point x="1717.9166666666665" y="338.0" />
<point x="1256.3982905982907" y="338.0" />
<point x="98.15384615384619" y="149.0" />
</edge>
<edge source="com.splitwise.driver.SplitwiseDriver" target="com.splitwise.model.User">
<point x="0.0" y="-52.5" />
<point x="1569.5833333333333" y="348.0" />
<point x="1231.8598290598293" y="348.0" />
<point x="73.61538461538464" y="149.0" />
</edge>
<edge source="com.splitwise.transactionFactory.ExpenseTransaction" target="com.splitwise.splitStrategy.impl.SplitByPercent">
<point x="-209.33333333333348" y="-88.5" />
<point x="917.1666666666665" y="920.0" />
<point x="172.0" y="920.0" />
<point x="0.0" y="28.0" />
</edge>
<edge source="com.splitwise.splitStrategy.impl.SplitByPercent" target="com.splitwise.model.User">
<point x="-114.66666666666674" y="-28.0" />
<point x="57.33333333333326" y="745.0" />
<point x="140.91666666666652" y="745.0" />
<point x="140.91666666666652" y="328.0" />
<point x="1011.0136752136755" y="328.0" />
<point x="-147.23076923076917" y="149.0" />
</edge>
<edge source="com.splitwise.driver.SplitwiseDriver" target="com.splitwise.model.UserRegistry">
<point x="-37.0" y="-52.5" />
<point x="1532.5833333333333" y="725.0" />
<point x="1495.75" y="725.0" />
<point x="126.66666666666674" y="40.5" />
</edge>
<edge source="com.splitwise.splitStrategy.impl.SplitByExact" target="com.splitwise.model.User">
<point x="-114.66666666666674" y="-28.0" />
<point x="421.33333333333326" y="735.0" />
<point x="151.91666666666652" y="735.0" />
<point x="151.91666666666652" y="338.0" />
<point x="1035.552136752137" y="338.0" />
<point x="-122.69230769230774" y="149.0" />
</edge>
<edge source="com.splitwise.transactionFactory.ExpenseTransaction" target="com.splitwise.splitStrategy.SplitStartegy">
<point x="-104.66666666666674" y="-88.5" />
<point x="1021.8333333333333" y="900.0" />
<point x="761.5" y="900.0" />
<point x="43.0" y="28.0" />
</edge>
<edge source="com.splitwise.process.TransactionProcesser" target="com.splitwise.transactionFactory.Transaction">
<point x="-51.60000000000002" y="-52.5" />
<point x="1927.5666666666666" y="1137.0" />
<point x="1829.6666666666665" y="1137.0" />
<point x="1829.6666666666665" y="920.0" />
<point x="1858.0833333333333" y="920.0" />
<point x="0.0" y="40.0" />
</edge>
<edge source="com.splitwise.transactionFactory.BalanceTransaction" target="com.splitwise.model.User">
<point x="92.66666666666674" y="-40.0" />
<point x="2071.833333333333" y="920.0" />
<point x="2248.168361823362" y="920.0" />
<point x="2248.168361823362" y="318.0" />
<point x="1305.475213675214" y="318.0" />
<point x="147.2307692307694" y="149.0" />
</edge>
</edges>
<settings layout="Hierarchic Group" zoom="0.40000000000000013" x="1158.4999999999995" y="664.2499999999998" />
<SelectedNodes />
<Categories>
<Category>Fields</Category>
<Category>Methods</Category>
<Category>Properties</Category>
</Categories>
<SCOPE>All</SCOPE>
<VISIBILITY>private</VISIBILITY>
</Diagram>

8 changes: 8 additions & 0 deletions input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
EXPENSE u1 1000 4 u1 u2 u3 u4 EQUAL
SHOW u4
SHOW u1
EXPENSE u1 1250 2 u2 u3 EXACT 370 880
SHOW
EXPENSE u4 1200 4 u1 u2 u3 u4 PERCENT 40 20 20 20
SHOW u1
SHOW
34 changes: 34 additions & 0 deletions src/main/java/com/splitwise/driver/SplitwiseDriver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.splitwise.driver;


import com.splitwise.io.InputTxtReader;
import com.splitwise.model.User;
import com.splitwise.model.UserRegistry;

public class SplitwiseDriver{
private static UserRegistry userRegistry;

public static UserRegistry getUserRegistry(){
return userRegistry;
}
public static void main(String[] args) {
User u1 = new User("u1","88888888881","u1@abc.com");
User u2 = new User("u2","88888888882","u3@abc.com");
User u3 = new User("u3","88888888883","u2@abc.com");
User u4 = new User("u4","88888888884","u4@abc.com");
User u5 = new User("u5","88888888885","u5@abc.com");


userRegistry = new UserRegistry();
userRegistry.getUserRegistry().add(u1);
userRegistry.getUserRegistry().add(u2);
userRegistry.getUserRegistry().add(u3);
userRegistry.getUserRegistry().add(u4);
userRegistry.getUserRegistry().add(u5);

InputTxtReader reader = new InputTxtReader();
reader.readInputTxtFile("input.txt");


}
}
32 changes: 32 additions & 0 deletions src/main/java/com/splitwise/io/InputTxtReader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.splitwise.io;


import com.splitwise.process.TransactionProcesser;

import java.io.*;

public class InputTxtReader {
TransactionProcesser processor;
public InputTxtReader(){
processor = new TransactionProcesser();
}
public void readInputTxtFile(String fileName) {
if(fileName==null && fileName.isEmpty()){
System.err.println("FileName is empty or Null . Aborting!!!");
return;
}
try {
File file = new File(fileName);
BufferedReader br = new BufferedReader(new FileReader(file));
String st;
while ((st = br.readLine()) != null) {
//System.out.println(st);
processor.process(st);
}
}catch(Exception e){
System.err.println("Exception while reading a file"+e);
}
}

}

12 changes: 12 additions & 0 deletions src/main/java/com/splitwise/model/Expense.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.splitwise.model;

import java.util.List;

public class Expense {

private User paidByUser;
private int amount;
private int noOfPeopleInExpense;
List<String> usersInExpense;

}
Loading