jeudi 4 août 2016

Firebase/NoSQL Database: Update stats realtime or compute them?

Is it better to store a counter and update it transactionally in realtime every time it is changed or compute it from each possible data source?

For example: I am building an app that tracks "checkins", similar to FourSquare. When the user "checks in" to a location I need to track the stats for the individual AND the total for the location over all users. (This is a simplified version of the app for brevity purposes, the real app tracks much more information).

For example Joe checks into Coffee Place:

  • Joe/CoffeePlace/+1

Now Fred, Tom and Lisa also check into the Coffee Place:

  • Fred/CoffeePlace/+1
  • Tom/CoffeePlace/+1
  • Lisa/CoffeePlace/+1

The above is necessary to track for the individuals but the best practice for tracking total number of check-ins at Coffee Place is unclear to me.

Which is the right approach?

  1. Gather data from each user node and then compute all checkins -> display total check ins
  2. Create a file for Coffee Place that updates at each check in like: CoffeePlace/+1+1+1+1

I would imagine for very large datasets that computationally would be time consuming (not because of the computation but because of gathering the data from each node). What is best practice here?

Aucun commentaire:

Enregistrer un commentaire