0

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?

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
roi
  • 21
  • 2
  • Possible duplicate of [get CollectionReference count](https://stackoverflow.com/questions/48534676/get-collectionreference-count) – Alex Mamo May 08 '18 at 15:58
  • Please check the duplicate to see a proper way to implement this. – Alex Mamo May 08 '18 at 15:59
  • Not exactly duplicate, but it seems to answer. I will need to use transaction from client side. – roi May 08 '18 at 16:32

0 Answers0