title: Apache ZooKeeper: How do writes work
body: <p>Apache ZooKeeper is a kind of high available data-store for small objects.  A ZooKeeper cluster consists of some nodes which all keep the whole dataset in their memory.  The dataset is called "always-consistent", so every node has the same data at every time.</p>
  
  <p>According to the documentation and <a href="http://www.cloudera.com/blog/2009/12/observers-making-zookeeper-scale-even-further/" rel="noreferrer">blog posts</a>, every node in the cluster can answer reads and accept writes.</p>
  
  <ul>
  <li>Reads are always answered locally by the node, so no communication with the cluster is involved.</li>
  <li>Writes are forwarded to a designated "Leader" node, which forwards the write-request to all nodes and waits for their replies.  If at least half of the nodes answers, the write is considered successful.</li>
  </ul>
  
  <p>Question: Why is it enough for the leader to wait for half of the nodes to reply?  If somebody connects to one of the nodes which didn't receive the update, he gets an outdated result (only local read to local value).</p>