In my app, I have events with items. Each item related to a user and has a price.
I also had the sum of items per user, and a global sum(and average).
Right now, those sums are calculating in firebase functions, and calculate from "scratch" each time. The reason is to avoid race condition when 2 items will be added at the same time and read the same current value.
The problem - it works too slow..
What is the "proper" way to implement this? Is there a way to assure no race conditions?
I though to do a double work. In client side, add/reduce the value of the specific item to the sums/avg, and also calculate from scratch in the "server" to avoing any issues. Is that a good way?