I'm working on an event planning app using a NoSQL database that follows a denormalization strategy to avoid expensive joins. However, I'm facing a potential issue when updating denormalized data.
Scenario
I have two functions that interact with the database:
- updateVenue(venueId, newName, newLocation) Updates the venue name and location. Finds all invitations referencing this venue and updates them with the new venue details.
- inviteGuest(guestName, venueId) Creates an invitation document containing the venue's name and location at the time of creation.
updateVenue starts execution and retrieves all invitations referencing the venue. Before updateVenue finishes updating invitations, inviteGuest is called. Since inviteGuest reads the venue before updateVenue commits, the newly created invitation contains outdated venue data.