{"id":21457,"date":"2024-12-17T14:16:44","date_gmt":"2024-12-17T20:16:44","guid":{"rendered":"http:\/\/www.designandexecute.com\/designs\/?p=21457"},"modified":"2024-12-17T14:16:45","modified_gmt":"2024-12-17T20:16:45","slug":"cap-theorem","status":"publish","type":"post","link":"https:\/\/www.designandexecute.com\/designs\/cap-theorem\/","title":{"rendered":"CAP Theorem"},"content":{"rendered":"\n<p><strong>CAP Theorem<\/strong> (also known as Brewer&#8217;s Theorem) states that in a distributed system, it is impossible to simultaneously guarantee <strong>Consistency<\/strong>, <strong>Availability<\/strong>, and <strong>Partition Tolerance<\/strong>. You can only achieve two of these three properties at the same time.<\/p>\n\n\n\n<p>Here is a breakdown of the three components:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\n<strong>Consistency (C):<\/strong><br>\nEvery read receives the most recent write. All nodes in the system return the same, up-to-date data.\n<\/li><li>\n<strong>Availability (A):<\/strong><br>\nEvery request (read or write) receives a response, even if some nodes are down.\n<\/li><li>\n<strong>Partition Tolerance (P):<\/strong><br>\nThe system continues to operate even if there is a network partition (communication failure between nodes).\n<\/li><\/ol>\n\n\n\n<p>Since network partitions (P) are unavoidable in distributed systems, the CAP theorem effectively forces a trade-off between <strong>Consistency (C)<\/strong> and <strong>Availability (A)<\/strong>. Based on this, distributed databases are classified into two main types:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>CP (Consistency + Partition Tolerance):<\/strong> Prioritizes consistency over availability.<\/li><li><strong>AP (Availability + Partition Tolerance):<\/strong> Prioritizes availability over consistency.<\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Databases Supporting CAP Combinations<\/h3>\n\n\n\n<table class=\"wp-block-table\"><thead><tr><th><strong>CAP Property<\/strong><\/th><th><strong>Database Type<\/strong><\/th><th><strong>Examples<\/strong><\/th><th><strong>Explanation<\/strong><\/th><\/tr><\/thead><tbody><tr><td><strong>CP<\/strong> (Consistency + Partition Tolerance)<\/td><td>Strongly Consistent Databases<\/td><td>&#8211; MongoDB (in strong consistency mode)  &#8211; HBase  &#8211; Redis (Single-node) &#8211; Zookeeper<\/td><td>These systems prioritize consistency over availability when a partition occurs. They ensure all nodes agree on the latest data, but might sacrifice availability.<\/td><\/tr><tr><td><strong>AP<\/strong> (Availability + Partition Tolerance)<\/td><td>Highly Available Databases<\/td><td>&#8211; DynamoDB  &#8211; Cassandra  &#8211; CouchDB  &#8211; Riak<\/td><td>These systems prioritize availability over consistency during network partitions. They ensure the system remains available, but the data may not be up-to-date (eventual consistency).<\/td><\/tr><tr><td><strong>CA<\/strong> (Consistency + Availability)<\/td><td>Not possible in partition-tolerant systems<\/td><td>&#8211; Traditional Relational Databases (single node): PostgreSQL, MySQL<\/td><td>CA systems are achievable only if there are no network partitions. This is generally possible on a single-node database, where partitions don&#8217;t occur.<\/td><\/tr><\/tbody><\/table>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Why is CA Not Possible in Distributed Systems?<\/h3>\n\n\n\n<p>In a distributed environment, network partitions (P) are given because systems can fail or experience delays. Therefore, the CA combination cannot exist in a distributed database because maintaining consistency and availability simultaneously during a partition is impossible.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Summary of CAP Trade-offs<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>CP:<\/strong> Strong consistency, but the system may become unavailable during partitions. <ul><li>Example: HBase, Zookeeper, etc. <\/li><\/ul><\/li><li><strong>AP:<\/strong> High availability but eventual consistency. <ul><li>Example: DynamoDB, Cassandra, CouchDB. <\/li><\/ul><\/li><li><strong>CA:<\/strong> Only achievable in non-distributed systems (no network partitions). <ul><li>Example: Single-node PostgreSQL or MySQL. <\/li><\/ul><\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>CAP Theorem (also known as Brewer&#8217;s Theorem) states that in a distributed system, it is impossible to simultaneously guarantee Consistency, Availability, and Partition Tolerance. You can only achieve two of these three properties at the same time. Here is a breakdown of the three components: Consistency (C): Every read receives the most recent write. All [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":21461,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"class_list":["post-21457","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bi-data-warehouse"],"jetpack_featured_media_url":"https:\/\/www.designandexecute.com\/designs\/wp-content\/uploads\/2024\/12\/cap_theorem-1123744566.png","_links":{"self":[{"href":"https:\/\/www.designandexecute.com\/designs\/wp-json\/wp\/v2\/posts\/21457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.designandexecute.com\/designs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.designandexecute.com\/designs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.designandexecute.com\/designs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.designandexecute.com\/designs\/wp-json\/wp\/v2\/comments?post=21457"}],"version-history":[{"count":2,"href":"https:\/\/www.designandexecute.com\/designs\/wp-json\/wp\/v2\/posts\/21457\/revisions"}],"predecessor-version":[{"id":21460,"href":"https:\/\/www.designandexecute.com\/designs\/wp-json\/wp\/v2\/posts\/21457\/revisions\/21460"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.designandexecute.com\/designs\/wp-json\/wp\/v2\/media\/21461"}],"wp:attachment":[{"href":"https:\/\/www.designandexecute.com\/designs\/wp-json\/wp\/v2\/media?parent=21457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.designandexecute.com\/designs\/wp-json\/wp\/v2\/categories?post=21457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.designandexecute.com\/designs\/wp-json\/wp\/v2\/tags?post=21457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}