I'm trying to get my head around how to structure data for a real-time firebase database. I read docs and some other questions about finding the following tips:
- data should be as flat as possible.
- be expensive on record to have cheap readings
- avoid data nesting
- data duplication may be ok
With that in mind, let me describe my specific use case. The frist user has the following attributes:
- Firstname
- Lastname
- Profile picture (large)
- Profile picture (small)
The user can create a story consisting of the following attributes:
A visual representation of the story may look like this:

My question is: how would you associate user information (first name, last name, small profile picture) with the story?
What I was thinking about:
enter user_id in the history that contains the alien identifier for a specific user. To load a story, we would have to make two queries to the database, one to get the story and one for the user.
{user_id: "XYZ", text: "foobar", timestamp: ...}
put the first name, last name and a small image in the story. Only one query is required to display history. But we will have to update the history of each user when, for example, the profile image changes.
{user_id: "XYZ", firstname: 'sandra', lastname: 'adams', smallProfilePicutre: '...', text: "foobar", timestamp: ...}
So, when several stories are created, and in most cases there are just reads, approach 1. will be expensive because we pay for two readings to show the story. Approach 2. would be more economical.
Here I would like your thoughts and ideas on this subject.
nosql firebase firebase-database
Lost in owl
source share