{"id":623,"date":"2025-04-07T03:03:54","date_gmt":"2025-04-07T03:03:54","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=623"},"modified":"2025-04-07T03:03:54","modified_gmt":"2025-04-07T03:03:54","slug":"split-brain-scenarios","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=623","title":{"rendered":"Split Brain Scenario Explained For DevOps Engineers"},"content":{"rendered":"<p>In this blog, we\u2019ll explore split-brain scenario with real world practical examples. <\/p>\n<p>We will look at quorum concepts, and a practical example of how <a href=\"https:\/\/devopscube.com\/backup-etcd-restore-kubernetes\/\" rel=\"noreferrer\">etcd<\/a> prevents split brain scenario using the Raft consensus algorithm. <\/p>\n<p>I\u2019ll also share a real-world experience with GlusterFS split-brain and the lessons learned.<\/p>\n<ol>\n<li>Split-Brain Scenario in Distributed Systems<\/li>\n<li>Quorum in Distributed Systems<\/li>\n<li>How etcd avoids split brain scenario (Real World example)<\/li>\n<\/ol>\n<div class=\"kg-card kg-callout-card kg-callout-card-grey\">\n<div class=\"kg-callout-text\">In a project, I faced a&nbsp;<b><strong style=\"white-space: pre-wrap;\">Split Brain Scenario<\/strong><\/b>&nbsp;in a&nbsp;<b><strong style=\"white-space: pre-wrap;\">GlusterFS NFS cluster<\/strong><\/b>, leading to data mismatches and a full restore from backup. It taught me to prioritize solutions that&nbsp;<b><strong style=\"white-space: pre-wrap;\">prevent such issues upfront<\/strong><\/b>.<\/div>\n<\/div>\n<p>Whenever we deploy distributed systems that deal with data, we usually deploy the nodes in&nbsp;<strong>different availability zones<\/strong>&nbsp;or different data centers (for on-prem environments) to ensure high availability.<\/p>\n<p><strong>Example:<\/strong> databases like MongoDB, distributed storage systems like GlusterFS, and consensus-based clusters like etcd.<\/p>\n<p>Let\u2019s consider an example of an etcd cluster.<\/p>\n<p>Assume we have a&nbsp;<strong>5-node etcd cluster<\/strong>. To maintain high availability, three nodes are deployed in Zone 1, while the remaining two are placed in Zone 2.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/blog.techiescamp.com\/content\/images\/2025\/02\/image-4.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"741\" height=\"314\"><\/figure>\n<p>This setup ensures that even if one zone goes down, there are still active nodes in another zone, maintaining service continuity.<\/p>\n<h2 id=\"split-brain-scenario-in-distributed-systems\">Split-Brain Scenario in Distributed Systems<\/h2>\n<p>In distributed systems, a split-brain scenario occurs when a group of nodes loses communication with each other, typically due to network partitioning.<\/p>\n<p>For example, in our 5-node etcd cluster, if network connectivity is lost between Zone 1 and Zone 2, the three nodes in Zone 1 may continue operating, forming a majority quorum.<\/p>\n<p>However, the two nodes in Zone 2 might also assume they should continue functioning independently, creating a second, conflicting cluster.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/blog.techiescamp.com\/content\/images\/2025\/02\/image-5.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"505\" height=\"608\"><\/figure>\n<p>This results in a classic&nbsp;<strong>split-brain problem<\/strong>, where:<\/p>\n<ul>\n<li>Some nodes keep working and accept new data. Other nodes, cut off from the majority, also keep working, but they don\u2019t know what the other side is doing.<\/li>\n<li>Since both sides are writing new data separately, they don\u2019t match anymore.<\/li>\n<li>When the network issue is fixed, these nodes may struggle to catch up, leading to wrong or missing data.<\/li>\n<\/ul>\n<h2 id=\"quorum-in-distributed-systems\">Quorum in Distributed Systems<\/h2>\n<p>To prevent Split-Brain scenarios, distributed systems use&nbsp;<strong>quorum-based decision-making<\/strong>&nbsp;to ensure consistency.<\/p>\n<p>Let us understand the concept of Quorum with examples.<\/p>\n<p>When you deploy database clusters, there are two key patterns:<\/p>\n<ol>\n<li><strong>Single-Primary Node<\/strong>: All writes go to the primary node, which then replicates those changes to secondary nodes.<\/li>\n<li><strong>Multi-Primary Node<\/strong>: In this setup, multiple nodes can accept writes simultaneously. When you write to any primary node, that node coordinates with others to ensure the write is properly replicated.<\/li>\n<\/ol>\n<p>So how do we choose the primary node?<\/p>\n<p>Most distributed databases use a&nbsp;<strong>leader election<\/strong>&nbsp;mechanism to determine the primary node. A classic example is&nbsp;<strong>etcd\u2019s Raft consensus algorithm<\/strong>.<\/p>\n<p>It works like a&nbsp;<strong>voting process<\/strong>: to elect a leader, a candidate node must receive a&nbsp;<strong>majority of votes<\/strong>.<\/p>\n<p>For example, in a&nbsp;<strong>5-node system<\/strong>, at least&nbsp;<strong>3 nodes must agree<\/strong>&nbsp;before any decisions can be made. This majority group is called a&nbsp;<strong>quorum<\/strong>.<\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/blog.techiescamp.com\/content\/images\/2025\/02\/image-6.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"505\" height=\"631\"><\/figure>\n<p>A quorum is typically calculated as (N\/2 + 1) where N is the total number of nodes in your system. This ensures that you always have a majority.<\/p>\n<p>For example:<\/p>\n<ul>\n<li>In a 5-node system, you need 3 nodes to form a quorum (5\/2 + 1 = 3)<\/li>\n<li>In a 7-node system, you need 4 nodes (7\/2 + 1 = 4)<\/li>\n<\/ul>\n<p>Thats why clusters are usually deployed with an&nbsp;<strong>odd number of servers<\/strong>, starting from&nbsp;<strong>3<\/strong>, to ensure that a&nbsp;<strong>majority (quorum) can always be formed<\/strong>.<\/p>\n<h2 id=\"real-world-scenario-etcd\">Real World Scenario (etcd)<\/h2>\n<p>According to the official etcd documentation, split-brain scenarios are&nbsp;<strong>effectively avoided in etcd.<\/strong><\/p>\n<figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/blog.techiescamp.com\/content\/images\/2025\/02\/image-7.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"446\" height=\"466\"><\/figure>\n<p>Here&#8217;s how:<\/p>\n<ol>\n<li>When a network partition occurs, the etcd cluster is divided into two segments: a majority and a minority.<\/li>\n<li>The&nbsp;<strong>majority<\/strong>&nbsp;segment continues to function as the available cluster, while the&nbsp;<strong>minority<\/strong>&nbsp;segment becomes unavailable.<\/li>\n<li>If the leader resides within the majority segment, the system treats the failure as a minority follower failure. The&nbsp;<strong>majority segment remains operational<\/strong>&nbsp;with no impact on consistency.<\/li>\n<li>If the leader is part of the minority segment, it recognizes that it is separated due to the loss of communication with a majority of the nodes in the cluster and it&nbsp;<strong>steps down from its leadership<\/strong>&nbsp;role.<\/li>\n<li>The majority segment then elects a new leader, ensuring&nbsp;<strong>continuous availability<\/strong>&nbsp;and consistency.<\/li>\n<li>Once the network partition is resolved, the minority segment automatically identifies the new leader from the majority segment and synchronizes its state accordingly.<\/li>\n<\/ol>\n<p>This design ensures that etcd maintains strong consistency and prevents split-brain scenarios, even in the face of network issues.<\/p>\n<p>You might ask,&nbsp;<strong>how does etcd determine if a node is in the majority or minority<\/strong>&nbsp;during a network partition?<\/p>\n<p>Each etcd node knows the&nbsp;<strong>total number of nodes<\/strong>&nbsp;in the cluster as part of its configuration. This is stored in the&nbsp;<strong>etcd membership list<\/strong>, which tracks:<\/p>\n<ul>\n<li>Total cluster size (N)<\/li>\n<li>Node IDs and addresses<\/li>\n<li>Current leader (if elected)<\/li>\n<\/ul>\n<p>Nodes regularly send messages (heartbeats) to confirm which nodes are still reachable. After detecting a partition, each node checks how many&nbsp;<strong>other nodes it can still talk to<\/strong>.<\/p>\n<p>It compares this number with the quorum requirement (<code>N\/2 + 1<\/code>).<\/p>\n<p>If a node can still communicate with at least quorum (N\/2 + 1) nodes, it knows it is in the majority.<\/p>\n<p>If it&nbsp;<strong>cannot reach quorum<\/strong>, it realizes it is in the&nbsp;<strong>minority<\/strong>&nbsp;and stops making decisions.<\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>For <a href=\"https:\/\/devopscube.com\/become-devops-engineer\/\" rel=\"noreferrer\">DevOps engineers<\/a>, understanding split-brain scenarios is important for maintaining reliable distributed systems.<\/p>\n<p>Since modern applications rely on distributed databases, storage systems, and consensus-based clusters, handling network partitions and quorum failures effectively is essential.<\/p>\n<p>DevOps teams must proactively implement strategies to prevent split-brain, ensuring data consistency, availability, and overall system resilience.<\/p>\n<p>If you have any doubts about this blog, drop it on the comment!<\/p>\n<p>Want to Stay Ahead in DevOps &amp; Cloud? Join the Free Newsletter Below.<\/p>\n<p><!--kg-card-begin: html--><br \/>\n<iframe loading=\"lazy\" src=\"https:\/\/embeds.beehiiv.com\/2a495ef4-3de7-4600-8a0d-de5dc968b372\" data-test-id=\"beehiiv-embed\" width=\"100%\" height=\"320\" frameborder=\"0\" scrolling=\"no\" style=\"border-radius: 4px; border: 2px solid #e5e7eb; margin: 0; background-color: transparent;\"><\/iframe><br \/>\n<!--kg-card-end: html--><\/p>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/split-brain-scenarios\/\" target=\"_blank\" rel=\"noopener noreferrer\">Split Brain Scenario Explained For DevOps Engineers \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/split-brain-scenarios\/<\/p>\n","protected":false},"author":1,"featured_media":624,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-623","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=623"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/623\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/624"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}