1

In NoSQL (Firestore in my case) data duplication is a normal thing, right? So for example, you would store a user's data in multiple places (wherever you need it).

My question is, how do you manage CRUD calls on these duplicated items? If you update a document, does your code need to know exactly where the document is duplicated, and update each of those duplications a well? The same idea with PUT, POST and DELETE.

Paul Kruger
  • 2,094
  • 7
  • 22
  • 49

1 Answers1

2

There is no single answer for this, but I typically indeed hard-code the logic of where the fanned out/denormalized/duplicated data is written. As long as you have a single point of definition for the data (so you know which document is the truth for each entity), this is usually not a big deal. You just look up the places to duplicate, and then update them all.

For a general description of handling updates to duplicated/denormalized data, see my answer here: How to write denormalized data in Firebase. It was written for the Firebase Realtime Database, but the same basic approaches can also be applied to Cloud Firestore.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807