Skip to content

Latest commit

 

History

History
60 lines (38 loc) · 2.29 KB

File metadata and controls

60 lines (38 loc) · 2.29 KB

Data Consistency and Tradeoffs in Distributed Systems

In distributed systems, maintaining data consistency across multiple nodes is challenging, especially when balancing performance and fault tolerance. Here’s a concise overview:


Key Concepts

  1. What is Consistency?

    • Ensures all nodes in a distributed system have the same data at any point in time.
  2. Single Node Problems:

    • Even with one node, failures (e.g., crashes) can lead to inconsistencies in data.

Data Partitioning and Replication

  1. Splitting Data:

    • Data is divided (sharded) across multiple nodes to scale horizontally, leading to consistency challenges.
  2. Data Replication:

    • Data is replicated for availability, but ensuring consistency between replicas requires careful coordination.

Key Challenges

  1. The Two Generals Problem:

    • Distributed nodes must coordinate, but unreliable communication (e.g., network failures) can prevent them from agreeing.
  2. Leader Assignment:

    • A leader node ensures consistent updates across the system. Protocols like Paxos or Raft manage leader elections.

Consistency Trade-offs

  1. CAP Theorem:

    • The CAP Theorem explains the trade-offs between Consistency, Availability, and Partition Tolerance.
    CAP Theorem Consistency Availability
    Consistency Strong Weak
    Available Weak Strong
    Partition-Tolerant Always Always
  2. Two-Phase Commit (2PC):

    • Ensures distributed transaction consistency with a vote mechanism to commit or abort a transaction.
  3. Eventual Consistency:

    • Data may be temporarily inconsistent but will eventually become consistent. This model is used in systems like Amazon DynamoDB.

Summary

  • Consistency ensures all nodes have identical data, but managing this in distributed systems is complex.
  • Trade-offs: Achieving both consistency and availability is challenging (CAP Theorem).
  • Solutions: Use leader election, Two-Phase Commit, and eventual consistency based on system needs.