Giter Club home page Giter Club logo

Comments (2)

wojtekmach avatar wojtekmach commented on May 25, 2024

Hi!

If I'm understanding this correctly, the balance for each account is kept in memory in OTP. Each time the application launches or a supervisor needs to restart a GenServer, the balance would need to be recalculated from the ledger entries in bank_entries table in the database. When a transaction occurs, the OTP records it to the database and transforms the values in memory.

This is not how it is implemented here. You can look at the supervision tree and notice no such things are happening [1]. Whenever we need account's balance we go to the database and recalculate it. Turns out, it's not a big deal for the database to calculate that number even for hundreds of thousands of entries [2]. What you're suggesting would be a valid way to design it though [3] but it's not a direction I have explored yet. It's probably how Erlangers would approach the problem; I was still very much in the mindset of "sticking everything into the database".

I'm closing this issue as it's not actionable, but feel free to continue discussing this topic. Thanks for bringing this up!

[1] https://github.com/wojtekmach/acme_bank/blob/master/apps/bank/lib/bank/application.ex#L13

[2] if the sheer number of entries becomes very large, a popular solution is to "roll up" all entries before certain date into one entry, so that there's less rows to access each time. The full account history is still available, but perhaps not directly accessible (e.g. older entries are stored in a different table)

[3] (1 GenServer for account, under a supervisor with a :simple_one_for_one restart strategy, which allows dynamic number of child process)

from acme_bank.

cdesch avatar cdesch commented on May 25, 2024

Thank you! This was extremely helpful! I really appreciate you taking the time to write back and I really did enjoy your presentation.

For [2] do you know of any reference code of how this might be implemented? I may try to fork your repo and attempt it, just to have experience with the two working concepts.

from acme_bank.

Related Issues (16)

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.