Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent concurrency in web service API?

We have three web services (/a, /b, /c) where each service maps to a method (go()) in a separate Java class (ClassA, ClassB, ClassC).

Only one service should run at the same time (ie: /b cannot run while /a is running). However as this is a REST API there is nothing to prevent clients from requesting the services run concurrently.

What is the best and most simple method on the server to enforce that the services don't run concurrently?


Update: This is an internal app, we will not have a large load and will just have a single app server.

Update: This is a subjective question as you can make different arguments on the general application design which affects the final answer. Accepted overthink's answer as I found that most interesting and helpful.

like image 982
Marcus Leon Avatar asked Nov 22 '09 02:11

Marcus Leon


1 Answers

Your design is flawed. The services should be idempotent. If the classes you have don't support that, redesign them until they do. Sounds like each of the three methods should be the basis for the services, not the classes.

like image 184
duffymo Avatar answered Sep 28 '22 17:09

duffymo