I'm just starting to build a web app using React.js, Next.js, Prisma, & PostgreSQL. In this web app, users can create "projects", which are represented by 10-15 rows in the database. When users make changes to the project on the client-side, what is the best method to synchronize the database?
Here's what I've considered so far:
Live, instant updates - In the future, I want users to be able to collaborate with other users on projects, however, this isn't necessary to achieve in this stage of development. If I were to pursue this, what is the best avenue to take? Websocket, graphql, etc, could all contribute to the solution. I would like it to be a fairly scalable and simple mechanism.
Manual Push - User clicks a save button to push their updates to the database. If I were to go this route, which of the following strategies works best?
- Client receives data from server using GET request. User makes changes to various components and clicks submit. The client-side creates an object containing all of the project data and POST to server. Server takes the received object and overrides the database with the objects values.
- I feel this is redundant, because even if the use only makes a small change and clicks submit, the client will send the entire packet of data to the server. Creating and managing an object/state variable with all the data seems cumbersome & bloated.
- Client receives data from server using GET request. User makes changes, and as they do so, client writes a change log of their modifications. When the user clicks save, the client sends this change log to the server, and it makes only those modifications.
- This feels better, but accurately tracking changes seems difficult. If there are any strategies to maintaining this changelog, please let me know.
This seems like a very common task, but I cannot find what the common pattern/solution is to address it.