Toy transaction processing engine.
cargo build --release
cargo run --release -- $INFILE.csv
cargo doc --open
cargo test
- Only Deposits can be disputed. Evaluating sample withdrawal dispute scenarios led to conflicts with other requirements (either available funds increase before chargeback, or clients account ends up being charged twice).
- No checks for duplicate transaction ids - based on the statement that all transaction ids are globally unique, there is no check for deposit with same id. This means that in the event of two deposits with different amounts but same transaction id and same client id, later transaction would overwrite previous.
Each clients balance is managed by a lightweight task. Compared to single loop of read line > parse > apply to state
this approach allows for horizontal scaling, (i.e. opens a possibility for client-specific task to be migrated to a different host).
- Parser: reads csv and handles deserialization
Mermaid for parser
flowchart TD
R(Read line)
D(Deserialize Record)
M(Convert to Message)
S(Send to Processor)
I{More input?}
E(Exit)
R-->D
D-->|Err|I
D-->|Ok|M
M-->|Ok|S
M-->|Err|I
I-->|Yes|R
I-->|No|E
- Processor: reads parsed and validated messages from parser, spawns account tasks for new clients, routes transactions to clients.
Mermaid for Processor
flowchart TD
R(Read Message)
I{More input?}
GH(Get handle for client i)
FM(Forward Message)
S(Start Account task<br/> for client i)
D(Communicate <br/> 'No more work' <br/> to spawned tasks)
E(Exit)
R-->|msg.client = i|GH
GH-->|Not found|S
S-->GH
GH-->|Found|FM
FM-->I
I-->|Yes|R
I-->|No|D
D-->E
- Account task: applies valid messages forwarded by processor to the internal state of the client account.
Mermaid for account task
flowchart TD
R(Read Message)
I{More input?}
A(Apply to state)
D(Report state to Writer)
E(Exit)
R-->A
A-->I
I-->|Yes|R
I-->|No|D
D-->E
- Writer: collects account states from account tasks and writes to stdout as csv.
Mermaid for Writer
flowchart TD
R(Read Message)
I{More input?}
W(Write to stdout)
E(Exit)
R-->W
W-->I
I-->|Yes|R
I-->|No|E