InterviewHubPRO
Section Overview
Q4

Question 4 of 50

Part 1: Foundational Distributed Systems Concepts & Trade-offs (1 - 10)

8%
System Design (50 Qs)•Part 1: Foundational Distributed Systems Concepts & Trade-offs (1 - 10)

Distributed Consistency Models: Strong, Eventual, Causal, and Read-Your-Writes.

In Simple Words: Consistency models define the contract between a distributed storage system and its applications regarding the order and freshness of observed data across multiple nodes:

  • Strong (Linearizable) Consistency: Once a write completes, all subsequent reads across all nodes immediately return that value or newer. Requires synchronous replication and consensus (Raft/Paxos).
  • Eventual Consistency: If no new updates are made to a key, all replicas will eventually converge to the same value. Lowest latency and highest availability.
  • Read-Your-Writes (Monotonic Read) Consistency: A user is guaranteed to always see their own recent updates immediately, even if other users experience a brief replication delay.
  • Causal Consistency: Operations that are causally related are observed in the same order by all nodes; concurrent operations without causality can be observed in different order.
Architecture Flowchart
sequenceDiagram
    autonumber
    actor User as Client
    participant LB as API Gateway
    participant Primary as Primary DB (Leader)
    participant Replica as Read Replica (Follower)

    Note over User,Replica: Read-Your-Writes Architecture (Session Token Pinning)
    User->>LB: POST /comments (Create new comment)
    LB->>Primary: INSERT comment (Commit LSN: 45012)
    Primary-->>LB: Success (Return LSN: 45012)
    LB-->>User: 201 Created (Set-Cookie: min_lsn=45012)

    User->>LB: GET /comments (Fetch user feed)
    Note over LB: Check min_lsn vs Replica Current LSN
    alt Replica LSN >= 45012
        LB->>Replica: Read from Replica (Catch-up complete)
    else Replica LSN < 45012
        LB->>Primary: Route to Primary (Prevent stale read)
    end