title: How to handle mutually exclusive actions in RESTful services?
body: <p>I'm working right now in two WebApi projects and in both of them we encountered the same problem: we have some set of actions <code>Actions</code> that cannot be performed if an action <code>A</code> is being performed, and vice-versa. So, for example, if any of those <code>Actions</code> are running right now and the user sends a request to action <code>A</code>, action <code>A</code> must wait those other actions to finish before running.</p>
  
  <p>Coming from a stateful services background, our first thought was to use locks, although with much resistance. We created a singleton service that simply stores <code>object</code>s mapped to user Id's, which can in turn be used as locks. </p>
  
  <p>Now, of course this poses some really tough problems, like:</p>
  
  <p>(1) We'll have to force users to always talk to only one server instance, even when their requests are coming from different devices in different parts of the world, since locks aren't going to automagically span from one instance to another.</p>
  
  <p>(2) Then we'll have to build our own [sub-optimal] load balancer. Our plan was to use Azure's built-in one.</p>
  
  <p>So my question is: how do you elegantly handle this problem in a way that <strong>doesn't hurt horizontal scalability</strong> and, preferably, doesn't need a custom load balancing policy?</p>