GithubHelp home page GithubHelp logo

toy_marketplace's Introduction

Toy marketplace challenge

See project specification for more details

Arch decisions

Mutative vs immutable functional design:

Usually I strongly lean toward a more functional approach. Usually I would create a struct which tracks holds the current state of all clients/transactions and have the handle transaction function recursively move through this list, and ultimately return a final version of this state. However, for performance and lifetime reasons, I opted for a mutating-in-place strategy.

To async, or not to async

Try as I might, I could not find a good way to process this list more asynchronously, without running a first pass that groups all related transactions together. This felt silly.

Not storing meta transactions

I made a distinction between standard transactions (e.g deposit, withdrawl) and meta transactions (e.g dispute, chargeback, resolve).

This is primarily because meta transactions didn't have a meaningful transaction_id, and instead, use their transaction_id field to reference another transaction, so I would either have to store the transactions in a Vec and cause every transaction lookup to happen in O(n), or I could store just the standard transactions in a HashMap associated to their id.

I tried the former first, but the later turned out to make more sense when meta transactions can change the state of an existing transaction (i.e dispute them).

I don't love that transactions are mutable in this design. I'd rather they be completely immutable in an append only list, but keeping track of disputes would have added a bunch of complexity (probably in the form of an entire other data structure for the meta transactions).

This is main decision I'd reevaluate if I had more time.

If I had more time

Test coverage

Right now the test coverage is fairly spartan, and I'd like to shore it up more, especially with some larger integration tests.

Remove nearly all expects

There are a few truly impossible states in this app, and in some of these states (especially None values when retrieving from lists) I opted for simply expecting or unwrapping these values. But other times there are states that are only possible through function misuse, and these I should be bubbling up.

toy_marketplace's People

Contributors

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