8000 GitHub - Lainera/trp
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Lainera/trp

8000

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What

Toy transaction processing engine.

Build

cargo build --release

Run

cargo run --release -- $INFILE.csv

Docs

cargo doc --open

Tests

cargo test

Implementation details

Assumptions made

  • 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).

Components

  1. 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
  1. 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 
  1. 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
  1. 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0