Search code examples
javascriptjavadatabasespringmicroservices

How to guarantee database data is always accurately reflected in webpage?


I have come across a very specific instance where data in a web page was modified by two admins on different computers during a User Acceptance Test. The data was unintentionally overwritten by admin #2. How do you guarantee that the data is ALWAYS accurately reflected across all web browsers using this data?

For example:

Admin #1 logs into a web page that has a table with CRUD (create, read, update, delete) functionality at 8:00 AM.

Admin #2 logs into the same web page and pulls the same data at 8:01 AM.

At this moment both web pages have the correct data being shown, as no data has been modified in the last minute.

Lets say at 8:03 AM Admin #1 modifies a record using a CRUD operation.

At this moment, Admin #2's data in the web page is out of date.

At 8:05 AM Admin #2 modifies the same record, but this overwrites Admin #1's change with the old data. Due to the old data being in the web page, a post request was sent with all the data for the row and the entire row was updated with "old data".

At this point, the database will ONLY show Admin #2's specific changes.

As you can see, if I had hundreds of admins all modifying data in a database this situation could occur fairly often.

Does a technology exist where I could "alert" Admin #2 and tell him the data is old?

What if 30 admins are logged in and see this data? Can I alert them all that this data is no longer accurately reflected?

As I am writing my application, I can foresee this being an issue in the future. There are many admins that will be using this web page, and I want to be able to assure them that the data will always be accurate. This data is very important for the business. It must always be accurate, yet easily modifiable for end users who do not know SQL.

I am using Spring Boot, and VueJS for my backend/frontend. Our applications will be deployed using OpenShift and Microsoft Azure DevOps. Our databases are using Oracle.

Have any of you ever come across this issue before? How did you solve this problem?


Solution

  • Add a revision count (or whatever name you want to give to it) to each entry. Pass the current revision count to the admin when he retrieves the data. Send the recision count back when the data should be updated. Compare the revision count with the count in the database, if it missmatches, notify the admin, otherwise update and increase the count. Make sure that check & update is atomic.