NoSQL Data Modeling

Queries I Found Useful in My First Adventures with Firestore

Colin Wren
Firebase Developers
6 min readMay 16, 2021

--

Photo by Bastien Hervé on Unsplash

After a pretty successful time building a prototype of Reciprocal.dev we decided to start building a beta that added user accounts and the ability for users to create their own user journey maps with the tool.

I decided to go with Firebase for both the authentication and data storage solution as the interoperability of both solutions made it ideal for performing asynchronous actions on changes to both documents in Firestore and user accounts in Firebase Authentication.

Moving to Firestore meant formalising the structure of the data that we had hacked together for the prototype to make it more scalable and make sure it plays well with the limits Firestore has around document sizes and nested objects.

To do this, I opted to build a number of sub-collections nested at the appropriate level for the data we stored in the prototype and to use an array of objects that had just enough data to be useful for rendering lists, but contained the ID of a document to link to for the full document.

To render the left screen I denormalised my data model to provide the features list with the ‘just enough’ data (name & description) to render the list in one document. The user would then open the feature and see the right screen which fetches the actual document for that feature to render more information about it

--

--

Colin Wren
Firebase Developers

Currently building reciprocal.dev. Interested in building shared understanding, Automated Testing, Dev practises, Metal, Chiptune. All views my own.