0

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?

Paul
  • 1,349
  • 1
  • 14
  • 26

1 Answers1

1

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).
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Wouldn't it be convenient for the firebase customer to have such a more "general" distributed counter? Or is this too specific? – Paul Aug 04 '22 at 19:25
  • I'm not sure I understand, so two answers there: 1) --- If you want to suggest that an extension for this use-case be built, it's probably better to [file a feature request](https://firebase.google.com/support/troubleshooter/report) through our support team. 2) --- If you want to build such an extension yourself and share it with the community, you'll want to join the Firebase [alpha program](https://firebase.google.com/alpha) and see if it's something that would fit with these [experimental extensions](https://github.com/FirebaseExtended/experimental-extensions). – Frank van Puffelen Aug 04 '22 at 19:33
  • I'll keep both options in mind. Thanks. – Paul Aug 04 '22 at 19:57