Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 3

Replication Architectures: Leaders and Beyond

Recommended resources

In our last lesson, we explored the logical clocks—Lamport timestamps and vector clocks—that allow us to reason about causality in distributed systems. You learned how vector clocks, in particular, enable systems to definitively identify concurrent events, a capability that is fundamental for handling data conflicts.

This lesson builds directly on that foundation. We will now examine the high-level architectures that use (or circumvent the need for) these ordering mechanisms to replicate data. Our goal is to compare single-leader, multi-leader, and leaderless replication, analyzing their distinct approaches to managing writes, ensuring fault tolerance, and providing specific consistency guarantees. Mastering these trade-offs is a core competency for senior backend engineers, as the choice of replication model dictates a system's fundamental characteristics regarding performance, availability, and correctness.

1. Single-Leader Replication: Simplicity and Strong Consistency

The most common replication model is single-leader replication. It's conceptually straightforward and is the foundation for many well-known systems, including traditional relational databases like PostgreSQL and message brokers like Kafka, which you've used in your projects.

In this model, all write requests are funneled to a single designated node: the leader. The leader processes the writes in a specific order and then forwards a log of these changes to its follower nodes. Read requests can be served by any of the followers (or the leader), which allows for read scaling.

Single Leader Replication - how it works | Systems Design 0 to 1 with Ex-Google SWE

To start, let's watch a clear explanation of how single-leader replication works and its primary benefits.

Please watch the first part of the video, from the introduction. Pay attention to the flow of writes and reads, and the two main advantages the speaker highlights: increased durability and read throughput.

The key advantage of this design is its simplicity regarding writes. Since all writes go through a single node, the system avoids write conflicts entirely. The leader establishes a single, unambiguous ordering of all data modifications, which makes it much easier to provide strong consistency guarantees like linearizability (if replication is synchronous).

However, this simplicity comes with significant trade-offs, particularly when the leader fails.

Single Leader Replication - how it works | Systems Design 0 to 1 with Ex-Google SWE

The same video provides an excellent breakdown of the challenges that arise when a leader fails. This is the most critical aspect to understand for interviews.

Now, watch the segment covering leader failure scenarios. Focus on the three major problems discussed: Incorrectly detecting a leader failure. Potential for data loss if the leader fails before replicating writes. The "split-brain" problem, where two nodes believe they are the leader.

These failure scenarios highlight the core challenge: ensuring correctness in an automated failover process is notoriously difficult and requires a robust consensus algorithm, a topic we will explore in a future module.

DDIA Chapter 5. Repliation - Thomas Wang

For a more detailed technical summary, let's turn to this article based on Martin Kleppmann's "Designing Data-Intensive Applications".

Please read the section under the heading Leaders and Followers, up to the end of the "Failover Process" subsection. This text reinforces the concepts of synchronous vs. asynchronous replication and the complex steps involved in handling node outages, especially leader failover.

In summary, single-leader replication is ideal for:

  • Systems where write conflicts are difficult to resolve and strong consistency is a priority.
  • Workloads that are read-heavy, as you can scale out by adding more followers.

Its main limitations are:

  • Write throughput is bottlenecked by the single leader.
  • If users are geographically distributed, all writes must incur a round-trip latency to the leader's data center.
  • Leader failure is a complex event that can compromise availability and data integrity if not handled carefully.

2. Multi-Leader Replication: Performance for Geo-Distribution

To overcome the limitations of a single leader, especially write latency in globally distributed applications, you can use a multi-leader (or master-master) architecture. In this setup, more than one node can accept writes. Each leader acts as a leader for writes in its own domain (e.g., its data center) and as a follower to the other leaders, replicating changes between them.

This is a powerful pattern for improving the performance and availability of write-intensive, geographically distributed services.

MultiLeader and LeaderLess Replication in Distributed Databases

This video explains the motivation for multi-leader replication and dives straight into its central challenge: write conflicts.

Please watch from the introduction to multi-leader. Focus on: Why it's used for multi-geography applications. How concurrent writes can lead to conflicts that are only detected during replication. The different strategies for conflict resolution (e.g., timestamp-based LWW, merging values). The different replication topologies (circular, star, all-to-all) and their trade-offs.

As the video makes clear, the primary cost of allowing multiple nodes to accept writes is the introduction of write conflicts. Since writes can occur concurrently on different leaders, the system must have a robust mechanism to detect these conflicts and converge on a consistent state. This is where concepts like vector clocks, which we discussed in the last lesson, become critical for detecting concurrency. Resolving the conflict itself often requires business logic (e.g., merging shopping cart items) or a simple policy like Last-Write-Wins (LWW).

DDIA Chapter 5. Repliation - Thomas Wang

Let's refer back to the DDIA summary for a concise overview of multi-leader use cases and conflict handling.

Read the section titled Multi-Leader Replication, focusing on the "Use Cases" and the introduction to "Handling Write Conflicts." This connects the architecture to practical applications like offline-capable clients and collaborative editing.

Multi-leader replication is a good fit when:

  • You need low-latency writes for users in multiple geographic regions.
  • You require higher write availability; if one data center goes down, others can still accept writes.
  • The application domain allows for automated conflict resolution or can tolerate manual intervention.

It is challenging because:

  • Conflict resolution logic can be complex to implement correctly.
  • Subtle issues with replication topologies and network delays can violate causal consistency (as seen in the video's all-to-all example), requiring mechanisms like version vectors.

3. Leaderless Replication: Maximizing Availability

Finally, we arrive at leaderless replication, a model popularized by Amazon's DynamoDB, with which you have experience. This architecture discards the concept of a leader entirely to achieve maximum fault tolerance and availability. Any replica can accept write and read requests directly from a client.

To maintain consistency in the absence of a leader, these systems rely on quorums. A client sends its request to multiple replicas in parallel.

  • For a write, the client waits for acknowledgements from at least W replicas to consider it successful.
  • For a read, it waits for responses from at least R replicas.

The values of N (total replicas), W, and R are configurable. The diagram below illustrates this client-driven coordination.

A client sends a request to three replicas (N=3). In this example, it might need two successful write acknowledgements (W=2) to proceed. During a read, it might query all three nodes. If it receives conflicting versions (v1 and v2), it must perform "Read Repair" to resolve the inconsistency, often by returning the latest version to the client and asynchronously updating the stale replica.

This quorum-based approach provides a probabilistic guarantee of reading the latest data. If W + R > N, a read quorum and a write quorum are guaranteed to overlap on at least one node, ensuring a client will get the most recent value. We will explore this formula in detail in the next lesson.

Leaderless systems excel at availability. If a replica is down, the client can simply ignore it and still achieve a quorum as long as enough nodes are available. Stale replicas are updated later through mechanisms like read repair (the client detects a stale value and writes the newer one back) and anti-entropy (a background process that syncs replicas).

DDIA Chapter 5. Repliation - Thomas Wang

The DDIA summary provides an excellent deep dive into the Dynamo-style leaderless model.

Please read the entire section on Leaderless Replication. Pay close attention to: The concepts of read repair and anti-entropy. The role of quorums (w + r > n). The use of version vectors to detect concurrent writes, which connects back to our previous lesson.

Leaderless replication is best suited for:

  • Services that require extremely high availability and partition tolerance (the 'AP' in CAP theorem).
  • Applications where eventual consistency is acceptable and occasional stale reads are not critical.
  • Workloads with very high write throughput, as the load is distributed across many nodes.

The main drawbacks are:

  • Weaker consistency guarantees out-of-the-box compared to single-leader models.
  • The complexity of conflict detection and repair is pushed to the read path or the client side.
  • Reasoning about data staleness can be more difficult than in leader-based systems.

4. A Framework for Choosing

You now have a solid overview of the three main replication architectures. In a system design interview, the crucial skill is not just describing them, but articulating when and why you would choose one over the others. The choice always comes down to the specific requirements of the application.

This table provides a high-level summary of the trade-offs, outlining when each replication model is appropriate and when it should be avoided based on system requirements like consistency, availability, and latency.

To crystallize this decision framework, the following article offers a superb, direct comparison.

Pros and cons of multi-leader vs leaderless replication in databases?

This article frames the choice between replication models in terms of what your application needs to optimize for.

Please read the article from the start to the end of the "Decision Heuristics" section. It provides a clear, interview-focused perspective on the trade-offs, operational complexities, and guiding principles for selecting an architecture.


Conclusion

In this lesson, we compared the three fundamental data replication architectures. You are now equipped to analyze and discuss the deep trade-offs each one presents.

Key Takeaways:

  • Single-Leader Replication: Prioritizes strong consistency and simplicity for writes by funneling them through one node. Its weaknesses are write latency for distributed users and the complexity of leader failover.
  • Multi-Leader Replication: Optimizes for low-latency writes in geographically distributed systems. Its primary cost is the added complexity of detecting and resolving write conflicts.
  • Leaderless Replication: Maximizes write availability and fault tolerance by removing the leader bottleneck. It relies on quorums and client-side coordination, generally offering weaker consistency guarantees.
  • The choice is not about which is "best," but which best fits the application's non-functional requirements for consistency, availability, and performance.

In our next lesson, we will delve deeper into two key mechanisms introduced today. We will analyze how quorum configurations (W + R > N) are used to tune the trade-off between consistency and availability in leaderless systems. We will also formally compare conflict resolution strategies, such as Last-Write-Wins and version vectors, which are essential in both multi-leader and leaderless architectures.