Home > Software engineering >  Synchronizing a countdown timer through Firestore
Synchronizing a countdown timer through Firestore

Time:02-10

Creating an app in Javascript in which I'm creating a timer that updates at every second and so, I want to store that timers time in firebase firestore at every update in timer so I could retrieve it with Onsnapshot on another page for displaying what would be an efficient way to do this because I don't think updating DOC every second will be a good approach

CodePudding user response:

Synchronizing each tick across the database is indeed not very efficient. But time has the nice trait that it passes (for the purpose of a use-case such as this) at the same rate on all clients. So what you'll want to do instead is store the start time and the interval of the timer in the database, and then have each client run its own local countdown based on that.

I wrote an example of this using the Firebase Realtime Database, so I recommend checking that out as a starting point: How to implement a distributed countdown timer in Firebase

  • Related