nobt-io / api

Main-Backend of nobt.io.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Move balance calculation from the frontend to the backend

thomaseizinger opened this issue · comments

Currently, we return bills and debts to the frontend. However, in addition to the debts, the frontend also shows the balances of each participant. This information is not present in the API response and hence, the frontend needs to calculate it by itself.

This is:

  1. error prone: the frontend is written in JS and has barely and tests
  2. inconsistent in terms of responsibilities: the frontend should focus on design and UX, not on doing math

In addition, we recently introduced property-based tests into the backend to have more thorough tests and better guarantees that our optimization algorithms actually behave correctly.
For these tests, we already calculate the balances of each participant because no matter how we optimize the debts, the balances always need to stay the same: they are the perfect metric to check on whether an optimization algorithm is correct.
However, at the moment, all this logic is part of the test suite and not the production code.
If we return balances in the API we can:

  1. Move this code to the production code and thereby support it properly (this will clean up the tests quite a bit)
  2. Remove some math from the frontend

@duffleit what do you think?
I remember that you disliked the idea of removing logic from the frontend at some point (because you had plans to actually move all the logic to the frontend). What is your current take on this?