{"id":"availability-vs-consistency","title":"Availability vs consistency","sections":[{"id":"cap-theorem","title":"CAP theorem","html":"<h3 id=\"cap-theorem\">CAP theorem</h3>\n<p class=\"figure\">\n  <img src=\"/repo/images/bgLMI2u.png\" loading=\"lazy\" decoding=\"async\" alt=\"Diagram\">\n  <br>\n  <i><a href=\"https://robertgreiner.com/cap-theorem-revisited\" target=\"_blank\" rel=\"noopener noreferrer\">Source: CAP theorem revisited</a></i>\n</p>\n<p>In a distributed computer system, you can only support two of the following guarantees:</p>\n<ul>\n<li><strong>Consistency</strong> - Every read receives the most recent write or an error</li>\n<li><strong>Availability</strong> - Every request receives a response, without guarantee that it contains the most recent version of the information</li>\n<li><strong>Partition Tolerance</strong> - The system continues to operate despite arbitrary partitioning due to network failures</li>\n</ul>\n<p><em>Networks aren't reliable, so you'll need to support partition tolerance.  You'll need to make a software tradeoff between consistency and availability.</em></p>\n<h4 id=\"cp---consistency-and-partition-tolerance\">CP - consistency and partition tolerance</h4>\n<p>Waiting for a response from the partitioned node might result in a timeout error.  CP is a good choice if your business needs require atomic reads and writes.</p>\n<h4 id=\"ap---availability-and-partition-tolerance\">AP - availability and partition tolerance</h4>\n<p>Responses return the most readily available version of the data available on any node, which might not be the latest.  Writes might take some time to propagate when the partition is resolved.</p>\n<p>AP is a good choice if the business needs to allow for <a href=\"/learn/consistency-patterns#eventual-consistency\">eventual consistency</a> or when the system needs to continue working despite external errors.</p>\n<h3 id=\"sources-and-further-reading-3\">Source(s) and further reading</h3>\n<ul>\n<li><a href=\"https://robertgreiner.com/cap-theorem-revisited/\" target=\"_blank\" rel=\"noopener noreferrer\">CAP theorem revisited</a></li>\n<li><a href=\"http://ksat.me/a-plain-english-introduction-to-cap-theorem\" target=\"_blank\" rel=\"noopener noreferrer\">A plain english introduction to CAP theorem</a></li>\n<li><a href=\"https://github.com/henryr/cap-faq\" target=\"_blank\" rel=\"noopener noreferrer\">CAP FAQ</a></li>\n<li><a href=\"https://www.youtube.com/watch?v=k-Yaq8AHlFA\" target=\"_blank\" rel=\"noopener noreferrer\">The CAP theorem</a></li>\n</ul>","headings":[{"id":"cap-theorem","title":"CAP theorem","depth":3},{"id":"cp---consistency-and-partition-tolerance","title":"CP - consistency and partition tolerance","depth":4},{"id":"ap---availability-and-partition-tolerance","title":"AP - availability and partition tolerance","depth":4},{"id":"sources-and-further-reading-3","title":"Source(s) and further reading","depth":3}]}],"sourceFiles":[]}