I have 2 Firestore collections I am worried about. Named Posts and Chats.
POSTS
The setup -- In Posts, each document has a field named Comments (an array of objects). Every time a comment is made on a Post document, the comment obj is added to Comments array, and every time a comment is updated, the comments array is overridden with new set of comments that include the updated comment object.
The issue -- Firestore docs warn against updating documents more than once per second to avoid contention and other errors (which I have witnessed in the Chats collection). How do I avoid this problem? As post comments are expected to update very frequently.
CHATS
The setup -- In Chats, each document has a field named Mesages (array of objects) and each object has a property named received. Messages field works very similar to Comments field. Also in each document is a field named UsersTyping (array of userId strings) which updates every time a users text input changes from empty to not empty and vice versa.
The Issue -- Just like Posts, updates to a document should not happen more than once per second. But because of app requirements, updates to userTyping and message.received need to take place, meaning a lot of updates to the document could happen within a second. How do I avoid this problem?
Tech Stack == React Native, Expo managed workflow, Firebase,
Thank you in advance for your suggestions.