Suppose a chat app has 10 million Firebase users, and hundreds of millions of messages.
I have a Firestore collection containing messages represented as documents in
Although many months later, for any future users, it does seem like the first attempt would likely work the best.
Using a single static field for timestamp and a single static field for recipients means index will remain negligible and you won't have to think about them.
To find all messages for a user, which seems as though it's your goal here:
For example, if I want to know all messages for user 8293413 after 3:00 PM today, I could do it like this:
This would simply look like this in pseudocode:
firestore.collection('messages').where('recipient', 'array_contains', userId).where('time', '>', '3pm today'.get()
This should be easy enough on performance, Firebase is optimized for the operators it provides, e.g. '==', '>=', 'array_contains'