Home > Enterprise >  Distributed Counter as general data type updater
Distributed Counter as general data type updater

Time:08-05

The Distributed Counter is a great extension for firebase for integers, such as for likes, followers, shares etc. I am wondering if you could use the same architecture to generally process writes in all different data types at a high frequency.

In my case, I would like to append the user id to a list each time the user "downloads" a document.

How could I use the Distributed Counter extension to do this, while ensuring that this procedure can happen at a very high frequency and not reach the limitations of firestore writes?

CodePudding user response:

You can't use the counter extension for maintaining a different type of data, but you could indeed take the same approach of writing data to multiple shards to increase the throughput.

A few things to keep in mind when implementing this:

  • If you want to store UIDs, you'd likely want a stable mapping from the UID to the document where it is stored, so base the document ID off of the UID itself - like using the last characters of the UID.
  • Ideally you'll want to use an atomic write operation, like the array-union operator. If that's not possible, you may need to use a transaction, but that will have lower throughput (so may need more shards).
  • Related