Made by Firebase
Records event counters at scale to accommodate high-velocity writes to Cloud Firestore.
How this extension works
Use this extension to add a highly scalable counter service to your app. This is ideal for applications that count viral actions or any very high-velocity action such as views, likes, or shares.
Since Cloud Firestore has a limit of one sustained write per second, per document, this extension instead shards your writes across documents in a
subcollection. Each client only increments their own unique shard while the background workers (provided by this extension) monitor and aggregate these shards into a main document.
Here are some features of this extension:
- Scales from 0 updates per second to a maximum of 10,000 per second.
- Supports an arbitrary number of counters in your app.
- Works offline and provides latency compensation for the main counter.
We also provide a Node.js admin sample implementation
Before installing this extension, make sure that you've set up a Cloud Firestore database in your Firebase project.
After installing this extension, you'll need to:
- Update your database security rules.
- Use the provided client sample , the provided Node.js admin sample or your own client code to specify your document path and increment values.
Detailed information for these post-installation tasks are provided after you install this extension.
To install an extension, your project must be on the Blaze (pay as you go) plan
- You will be charged a small amount (typically around $0.01/month) for the Firebase resources required by this extension (even if it is not used).
- This extension uses other Firebase and Google Cloud Platform services, which have associated charges if you exceed the service’s free tier:
- Cloud Firestore
- Cloud Functions (Node.js 10+ runtime. See FAQs )
What you can configure
- Cloud Functions location
- Document path for internal state
- Frequency for controllerCore function to be run
Description: This scheduled function either aggregates shards itself, or it schedules and monitors workers to aggregate shards.
Description: Listens for changes on counter shards that may need aggregating. This function is limited to max 1 instance.
Description: Monitors a range of shards and aggregates them, as needed. There may be 0 or more worker functions running at any point in time. The controllerCore function is responsible for scheduling and monitoring these workers.
How to install this extension
Using the Firebase console
To install and manage extensions, you can use the Firebase console.Install using console
Using the Firebase CLI
To install and manage extensions, you can also use the Firebase CLI:
Step 1: Run the following npm command to install the CLI or update to the latest CLI version.
npm install -g firebase-toolsDoesn't work? Take a look at the Firebase CLI reference or change your npm permissions.
Step 2: Set up a new Firebase project directory or navigate to an existing one
Step 3: Add this extension to your extension manifest by running
firebase ext:install firebase/firestore-counter --local --project=projectId_or_alias
Step 4 (Optional): Test this extension locally with the Firebase Emulator Suite
Step 5: Deploy the extensions in your manifest to your project
firebase deploy --only extensions --project=projectId_or_alias