惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Webroot Blog
Webroot Blog
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
Y
Y Combinator Blog
F
Fortinet All Blogs
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Check Point Blog
博客园 - 【当耐特】
V
V2EX
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
GbyAI
GbyAI
美团技术团队
Jina AI
Jina AI
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
The GitHub Blog
The GitHub Blog
NISL@THU
NISL@THU
D
Docker
MyScale Blog
MyScale Blog
V
Vulnerabilities – Threatpost
S
SegmentFault 最新的问题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
S
Schneier on Security
K
Kaspersky official blog
AWS News Blog
AWS News Blog
The Hacker News
The Hacker News
Latest news
Latest news
C
CXSECURITY Database RSS Feed - CXSecurity.com
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Know Your Adversary
Know Your Adversary
L
LINUX DO - 热门话题
P
Privacy & Cybersecurity Law Blog
L
Lohrmann on Cybersecurity
C
Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
Cisco Talos Blog
Cisco Talos Blog
N
News and Events Feed by Topic
Google DeepMind News
Google DeepMind News
Help Net Security
Help Net Security
C
Cybersecurity and Infrastructure Security Agency CISA
B
Blog

Arpit Bhayani

Temporal Primer - Building Long-Running Systems What Matters in Production RAG Structure of Every LLM Chat How LLMs Really Work Your Monolith Is Already A Distributed System Databases Were Not Designed For This BM25 JOIN Algorithms Venting at Work Comes at a Reputation Cost Why Half Your Skills Expire Every Few Years Multi-Paxos - Consensus in Distributed Databases MySQL Replication Internals Bloom Filters When You Increase Kafka Partitions Product Quantization The Q, K, V Matrices The Day I Accidentally Deleted Production How LLM Inference Works What are Blocking Queues and Why We Need Them Heartbeats in Distributed Systems How Writes Work in Apache Cassandra Redis Replication Internals How to Handle Arrogant Colleagues at Work How Does a CDN Handle Content Replication You Can't Fix Everything on Day One When Emotions Spill Over at Work Why gRPC Uses HTTP2 Meetings With No Agenda Are a Waste of Time Career Longevity Beats Constant Job Hopping Stay Relevant at Higher Salary Levels Why Do Databases Deadlock and How Do They Resolve It Why and How Cache Locality Can Make Your Code Faster Why Eventual Consistency is Preferred in Distributed Systems Why does DNS use both UDP and TCP Should You Do a Master's My Honest Take Empathy Makes Great Engineers Unstoppable Good Mentors Build People, Not Just Skills Why You Should Always Have Back-Burner Projects Before You Push Back, Know What You're Standing On Be the One They Can Count On How Much Are People Willing to Bet on You How to Get Leadership to Say Yes to Your Project Don't Let Your Best Ideas Die in Silence Be the Person Everyone Wants to Work With The XY Problem and How to Avoid It The Startup Hiring Lie Nobody Talks About You Won't Be Promoted Unless You Ask It's Not Enough to be Right; Learn to be Heard No One Ships Great Software Alone You Don't Win by Proving Others Wrong Appreciate Generously; It Costs Nothing, But Builds Everything Your Soft Skills Aren't Soft at All Before you form an opinion, experience it Why You Need Both Curiosity and Action to Thrive A Daily Worklog Changed Everything How We Handle Mistakes Defines Us Own Your Mistakes Don't Wait. Step Up. Temporary Fixes Are Permanent Why Interviews Are Biased And What Sets You Apart Saying 'This isn't my problem' is actually the problem How to Write Effective OKRs Never Lose a Battle due to Miscommunication When In Doubt, Code It Out How to Follow Up Without Annoying People Lead Projects That Land, Execution Over Everything Abstract Thinking Will Define Your Next Decade We Engineers Suck at Task Estimation Shiny Obect Syndrome in Tech When to Change Jobs - The 3P Framework Comfort and Competition - Know When to Switch Gears Paper Notes - On-demand Container Loading in AWS Lambda Paper Notes - SQL Has Problems. We Can Fix Them Pipe Syntax In SQL Paper Notes - NanoLog - A Nanosecond Scale Logging System Don't Wait, Learn - The Best Resource is Mythical Paper Notes - WTF - The Who to Follow Service at Twitter The Unexpected Benefit of Reading Random Engineering Articles Roadmaps Are Limiting Your Growth Stop Leaving Money on the Table - Negotiate Your Job Offer Never Bad-Mouth Your Past Employers Show You're a Culture Fit Quantify your resume, Know Your Numbers The Importance of Being Likeable in Interviews Questions to Ask Your Interviewer How to Build Trust Through Collaboration Do This, Once You Are Out of the Interview Cycle Stop Pitching Ideas, Start Pitching Projects Read Those Design Docs, Even the Ones That Seem Irrelevant The Best Engineering Lessons Happen During Outages Great Engineers Start Broad LLM Summaries are Ruining Your Learning Turn System Design Interviews into Discussions Title Inflation At Work, Find Your Own Projects 6 Simple Strategies to Cracking Any Tech Interview How to Remain Unblocked Solving the Knapsack Problem with Evolutionary Algorithms Generating Pseudorandom Numbers with LFSR Local vs Global Indexes in Partitioned Databases Partitioning Data - Range, Hash, and When to Use Them
Why Distributed Systems Need Consensus Algorithms Like Raft
Arpit Bhayani · 2025-09-06 · via Arpit Bhayani

Everything we interact with today is a “distributed system”. From microservices to cloud-native applications, from databases to message queues. We are constantly building systems that span multiple machines. But there comes a fundamental challenge - how do we ensure that all independent nodes agree on shared state?

This is where consensus algorithms like Raft come in. While I talk about Raft in some other write-up, in this one, let me help you understand why there is a need for consensus and why it is a tough nut to crack.

Why Agreement is Hard

It Does Seem Simple

At first glance, getting multiple machines to agree seems straightforward. Can’t we just have one machine make decisions and tell the others? Or use timestamps to order operations? Unfortunately, distributed systems introduce complexities that make these naive approaches fail catastrophically.

Things That Can Go Wrong

Distributed systems face several simultaneous challenges; here are some of them.

Network Partitions: Networks can split, leaving groups of nodes unable to communicate. Unlike a simple “network down” scenario, partitions create islands of nodes that continue operating independently.

Node Failures: Machines crash, sometimes permanently, sometimes temporarily. They might restart with partial memory loss or a corrupted state.

Asynchronous Communication: Message delivery times are unpredictable. A message sent first might arrive second, or might never arrive at all.

Clock Skew: Different machines have different notions of time, making timestamp-based ordering unreliable.

Majority Vote: Sounds simple, but what happens during network partitions? You might have multiple groups, each thinking they’re the majority.

The Bank Account Problem

Imagine a distributed banking system with account data replicated across three servers in different data centers. A customer has 1000andtriestowithdraw1000 and tries to withdraw 800. Simultaneously, their spouse tries to withdraw $500 from a different location.

Without proper consensus:

  • Server A processes the 800withdrawal:balancebecomes800 withdrawal: balance becomes 200
  • Server B processes the 500withdrawal:balancebecomes500 withdrawal: balance becomes 500
  • Server C might see both operations in different orders

You can consider these servers A, B, and C are geographically distributed database nodes, and all of them are capable of accepting and handling writes.

Now you can see why consensus is a legitimate real-world problem.

What Consensus Algorithms Actually Solve

The Core Guarantee: Safety and Liveness

Consensus algorithms (like Paxos or Raft) provide two fundamental guarantees

Safety: Nothing bad ever happens. In practical terms:

  • All nodes that decide on a value decide on the same value
  • No conflicting decisions are made
  • The system maintains consistency even during failures

Liveness: Something good eventually happens. In practical terms:

  • The system continues to make progress
  • Decisions are eventually reached
  • The system doesn’t get permanently stuck

The Consensus Problem Formally

Given a set of nodes in a distributed system, consensus algorithms solve the problem of getting all non-faulty nodes to agree on a single value, even in the presence of failures and network issues.

The algorithm must satisfy:

  1. Agreement: All correct nodes decide on the same value
  2. Validity: If all nodes propose the same value, that value is decided
  3. Termination: All correct nodes eventually decide

Real-World Scenarios: Where Consensus is Critical

Distributed Databases

Leader Election for Primary-Replica Systems

Databases like PostgreSQL with streaming replication need to elect a primary after the current primary fails. Without consensus, you might end up with split-brain scenarios where multiple nodes think they’re the primary.

Distributed Transactions

When a transaction spans multiple database shards, all participants must agree on whether to commit or abort. The two-phase commit protocol is essentially a consensus algorithm.

Configuration Management

Systems like Apache Kafka use consensus (via Zookeeper or KRaft) to manage broker membership, partition assignments, and configuration changes.

Microservices and Service Discovery

Service Registration

When services start up, they need to register with a service discovery system. Multiple discovery nodes must agree on the current set of healthy services.

Configuration Distribution

Changing application configuration across a fleet of microservices requires consensus to ensure all services get the same configuration version.

Container Orchestration

Scheduler Decisions

Kubernetes etcd stores cluster state and scheduling decisions. Multiple master nodes must agree on pod placements and resource allocations.

Node Membership

The cluster must agree on which nodes are healthy and available for scheduling workloads.

Consensus algorithms like Raft are the foundation of reliable distributed systems.

The next time you are building a system that needs to keep state in sync across services or data centers, remember that Raft and similar algorithms have already solved the hardest problems. Your task is to know when and how to use them effectively.

Also, knowing them helps you understand why and how distributed systems are both a beauty and a beast.