Coder Social home page Coder Social logo

payments-engine's Introduction

Payment Engine

a rust program that processes varying types of transactions for clients

๐Ÿ‘‹ Getting Started

  • build: cargo build
  • run the unit tests: cargo test
  • run the program: cargo run -- transactions.csv > accounts.csv

Assumptions

all assumptions from the specification pdf were adopted along with the following...

Transaction Ids

Assuming that the first transaction which appears for a client is their actual first transaction and the rest will appear in the right order with respect to the client

If this assumption is inaccurate, then that means an incoming transaction could have a lower id than the last transaction processed for the client. In that case, the account state needs to be recompiled starting from that new earlier transaction. Otherwise, if tx_id is higher than the last transaction, the program can continue without issue.

Chargebacks & Resolutions

I assume that both chargeback and resolve are only meant for deposit transactions... It is unclear to me how chargebacks/resolutions could revert withdraw transactions...

for instance,

  • both chargeback and resolve move funds from available -> held; this makes sense if we were undoing a deposit transaction, but to undo a withdraw transaction, I wouldn't expect funds to be moved from the available account at all
  • when a chargeback is complete, the funds are removed from held and not moved back into available; again, this makes sense if we were undoing a deposit transaction, but this doesn't make sense if the tx_id is pointing to a withdraw transaction to be reversed

Improvements

As mentioned in the challenge specifications, in a real environment, the transactions are coming from thousands of concurrent TCP streams. In that case, there are two major objectives to be completed:

  1. a database must be implemented for storing transaction history and account states
    • remove the InMemoryDatabase implementation and replace it with a real database
    • relevant crates: rocksdb, prisma-client, sled, redb
    • databases should have their own internal locking to avoid data race conditions
    • schema would be very similar to the structs found in the services folder
  2. make the program asynchronous, multi-threaded, and receive buffered data
    • one or more threads for receiving transactions and writing those to the database
    • one or more threads that listen for new transactions and update account states accordingly
    • relevant functions should be made asynchronous (crates: tokio)

payments-engine's People

Contributors

isaacadams avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.