After years of RDBMS I am coming to terms with NoSQL's advantages and caveats, and Firebase is making it a much easier and enjoyable process. I am stuck, however, with handling duplicate data due to denormalization, and was hoping I could get insight into possible solutions.
As an contrived example, I have two entities, Users and Groups, with data existing for each under the root paths users and groups respectively.
When a user joins a group, I store the following data:
- A mapped ID reference to the group within that users path (/users/{user_id_1}/group/{group_id_1} = true)
- A mapped ID reference to the user within the group path (/groups/{group_id_1}/users/{user_id_1} = true)
- If they are the group administrator, an entry referencing this (/group_admin/{group_id_1}/{user_id_1} = true)
- A list array summarizing the group administrator's names (/groups/{group_id_1}/admins = [0: John Smith, 1: Jane Doe])
What is the best practice to guarantee that all this data is maintained during CRUD operations? My current ideas, with concerns:
- To maintain the processing and checking of this within each client app I develop that affects this data
Concern: Issues if the latest app version processes more relations but the client is using a dated app version
- Build a cron worker that runs on a regular interval to verify relation integrity, with potential efficiently by indexing my main 'models' with updated timestamps to only process changes since the last cron
Concern: A delay in building these relations for the users
Any help is appreciated.
Loving Firebase and the security/rules are amazing, which makes me think maybe my requirements could have a similar solution.