My application is a form-based application, where users can raise a request, an ID will be assigned to that request, the user will fill out some details, and then submit it through different stages. The issue that multiple users can be a part of one request, so there might be a case where user A and user B is looking at the form at the same time. User A may submit first, and then user B submits, which would cause the request to only show the info submitted by user B. To solve this, I've come up with two solutions:
-Before we submit the data to the DB, we make a get call to see if the data is already submitted (we uses statuses in our app. So we would check for the status of "Stage # Pending").
-We implement a Redis Cache for some other services. I could add something like
public submitRequest() {
RMap<String, int> requestLockMap = redissonClient.getMap("requestLock");
if(requestLockMap.get('request_ID') == 0) {
requestLockMap.put('request_ID', 1);
...continue submitting request...
}
}
This is essentially adding in a racing condition with the Redis Cache. However, I don't know if either is a good practice for this sort of thing. Are there any better alternatives? I am using Spring as our Java framework, so if there are any solutions to that, I'm open to hearing them.