Distributed Systems Fall 2022 Lecture 4: Linearizability and CAP Theorem # Herlihy and Wing: Linearizability: A Correctness Condition for Concurrent Objects It is important that you read and understand this paper carefully since linearizability is going to show up frequently as a correctness condition for the protocols we study in class, and most systems designed, built and deployed today have to choose whether or not to trade-off linearizability for performance and fault-tolerance. Linearizability is a correctness property expressed in terms of operations on abstract data types (objects) that provide some atomic operations. The paper uses FIFO queues as a running example, which provide enqueue and dequeue as atomic operations. The paper assumes an environment where several concurrent processes can enqueue and dequeue elements, this might be a distributed system or even just a multi-threaded application, and asks what does it mean for the queue to be **correct**. The paper's criterion is linearizability, which means that (a) there is a linear order in which the operations seem to have occurred; and (b) this linear order is consistent with real-time, i.e., an operation occurs before the queue returns to the caller. These two seemingly simple conditions have several implications about how locality, but also has implications about the fault tolerance and performance of objects providing this guarantee. ## Questions: For the following questions consider a stack (a last-in-first-out data structure) and provide an example of: (a) A linearizable operation history for the stack. (b) An operation history that is not linearizable. (c) Pseudo-code for a (single-machine) implementation of such a stack. # Gilbert and Lynch: Brewer’s Conjecture and the Feasibility of Consistent, Available, Partition-Tolerant Web Services The CAP theorem was informally stated by Eric Brewer in PODC 2000, and reflected his experiences building Inktomi (an early search engine) as a distributed service running on multiple machines. Owing to the informal manner in which it was stated this theorem continues to be fodder for internet debates to this date. The Gilbert and Lynch paper formalizes this notion and talks about how linearizability and availability are at odds, and how the situation is better in a partially synchronous network. The CAP theorem is often cited as a reason why so called NoSQL databases moved away from linearizability, and this paper demonstrates how Herlihy and Wing's correctness criterion can impact system design. ## Questions: (d) State the CAP theorem, as formalized, by Gilbert and Lynch?