title: Self organizing applications
body: <p>I have the following requirements for an application that many people will be using in the office - no Server component.  All instances of client apps should somehow negotiate between themselves to decide which client will take on the server role.  And the clients should communicate between themselves via IP.</p>
  
  <p>If and when the client app goes down, another client must take over in a seamless manner.  I understand that having a server would be much, much simpler.  But because the app must be very resilient, the powers that be do not want to risk server going down (or even its backup) and rather rely on this hybrid mesh connectivity, where the server role hops from client to client.  </p>
  
  <p>I think I got the app connectivity down.  Basically, when the app starts, it announces itself via UDP (either to a predefined IP address that everything listens to or via UDP broadcast).  From there on, the communication proceeds in a similar manner.</p>
  
  <p>The part I am having problems with is how to negotiate/self-organize between the clients to pick one with a server role.  And how to reliably detect that a client has gone down and then a new negotiation must take place.  The final difficulty is replicating data that's been accumulated by the client with a server role.  </p>
  
  <p>I created a prototype in c# that communicates and tries to replicate data, but the negotiation part (particularly coupled with an client failure).  </p>
  
  <p>Initially I thought that's what ZeroConf (aka Bonjour) did.  But that just announces available network services.  </p>
  
  <p>Anyway, I do not want to reinvent and I can't be the first person to want to do this.  So my questions:</p>
  
  <ul>
  <li>Is there a pattern that already implements what I described above?</li>
  <li>If so, is there an available .NET (or even native) library for this?</li>
  <li>What are good ways to negotiate server role among the clients?</li>
  </ul>