I'd like some clarification about Cloud Firestore's read pricing with relation to Reference
types. In my current scenario, I have a chat room that displays a list of messages in a conversation. A message looks like this...
{
"id": "...",
"text": "Hello World",
"createdBy": Reference(/users/userID)
}
When rendering the message I have access to the text
, but I also need access to the createdBy
user. Currently, I'm passing the createdBy
reference to another component (in React) and then fetching that document there to display the user's avatar and username.
This is working well enough but I'm concerned that this results in a read to the database for every message in the conversation, which could add up very quickly. I'm almost certain that this will result in additional reads per message, but is Firebase intelligent enough to cache the users?
In other words, if I have 5 messages created by /users/userA
will each message count as a read to the database, or would it just be one read for each user in the conversation?
If Firebase isn't able to cache this, it would seem I need to denormalize the data and duplicate the username and avatar on the message document rather than just relying on the reference itself. This seems to kind of limit the benefit of References, though.