We have a spring mvc web application that will serve many users in their actions. Our data source is a mySQL DB.
The web app is located on a cluster of tomcat server.
Users do not have a session while interacting with the web application.
The protocol is a simple REST API between users and the web app.
We would like to ignore users requests if another request handling is still in progress. for example:
user1 requests for action1...
action1 handling begins in webapp.
user1 requests for action1 again (before the handling is completed)
server declines the 2nd request since action1 handling is still in progress..
action1 handling completed.
result for action1 is returned to user1's client.
(now further actions is accepted by the web app)
How is it possible to achieve this? if we used a single node of web app we could manage it simply in memory, but since we use a cluster and no shared memory\cache it wont work.
Another alternative we thought about is using a locking in the DB, for example create a constraint for the userID in a dedicated table (called userLock) and before each handling we simply insert into this table, and finalizing by removing the entry from it, now if an illegal request is made, a constraint exception is thrown and not handled)
are there any other alternatives to this "semaphore" behavior?