Re: [Firebase] Firestore 500 Writes Per Second Limit to Collection Group

128 views
Skip to first unread message

John Rodkey

unread,
Dec 10, 2020, 1:37:23 PM12/10/20
to fireba...@googlegroups.com
If you are not using the timestamp to query simply remove the autoindex and you'll be fine.  If you need the timestamp for queries, i suggest either a sharded timestamp or a composite index using as example post_id and createdAt together.

On Thu, Dec 10, 2020 at 12:25 PM Joon Cho <joonh...@gmail.com> wrote:

Firestore has a limit of 500 wps per collection if a collection indexes sequential data field such as createdAt.

Consider a vote collection:

Vote { userId: string postId: string vote: 1 | 0 | -1 createdAt: Timestamp }

Without any write limits, I can simply make vote collection a top level collection: /vote/{voteId}

However, this will limit my app to be able to handle only 500 votes per seconds across the entire app.

Which means it will not scale to the size of reddit or instagram where there are many many posts and votes happening all over those posts and comments.

To work around the limit, I am making vote collection a subcollection of post: /post/{postId}/vote/{voteId}

Now 500 wps limit only applies to each individual vote collection for each post, not across the app.

Is this assumption correct?

Now, I want to query votes by user who casted the vote.

For example, a user may want to see his/her previous votes.

I can make a collection group index on vote.userId (NOT in composite with vote.createdAt) field to do that.

How will this collection group index affect 500 wps limit now?

Will it bring it down to 500 wps across the app?

What if I make a collection group composite index on vote.userId and vote.createdAt?

How would you structure your collections for this common voting pattern if you want to scale it to the level of reddit in the future without migrating away from firestore?


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/380ee10e-90a3-4e72-93c7-5d1a8ecc52e4n%40googlegroups.com.

Kato Richardson

unread,
Dec 10, 2020, 1:42:20 PM12/10/20
to Firebase Google Group
Also asked on cloud-firestore-discuss here.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Reply all
Reply to author
Forward
0 new messages