L8/9 - Consistency Flashcards

1
Q

Why are consistency guarantees needed in distributed systems?

A

When data is replicated, inconsistencies can occur due to network delays, failures, and concurrency.
Most systems provide eventual consistency, meaning replicas eventually converge to the same value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When do the edge cases of eventual consistency become apparent?

A

Under system failures or high concurrency.
Example: A client may read stale data if updates haven’t yet propagated.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between transaction isolation levels and distributed consistency?

A

Transaction Isolation (ACID focus): Ensures transactions execute without race conditions.

Serializable (Strongest)
Repeatable Read
Read Committed
Read Uncommitted (Weakest)

Distributed Consistency (Replication focus): Ensures replicas are synchronized correctly.

Strict Consistency
Linearizability
Causal Consistency
Monotonic Reads/Writes
Read-Your-Writes Consistency
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does ACID consistency mean?

A

The database transforms from one consistent state to another, preserving application-specific constraints.
Example: A course must have at least one lecturer if students are enrolled.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does read-after-write consistency differ?

A

Ensures a client reads its own updates immediately.
Example: If a user uploads a profile picture, it should appear immediately upon refresh.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the Atomic Commitment Problem in distributed transactions?

A

If a transaction updates multiple nodes, either all nodes must commit, or all must abort.
If any node crashes, the transaction must abort to maintain consistency.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How is atomic commit different from consensus?

A

Consensus: Nodes propose values, and one value is chosen.
Atomic Commit: Nodes vote to commit or abort, and all must agree on the decision.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Two-Phase Commit (2PC)?

A

Prepare Phase – Coordinator asks participants if they can commit.
Commit Phase – If all vote yes, commit; if any vote no, abort.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What happens if the coordinator crashes before sending the commit message?

A

The system blocks until the coordinator recovers and resends the decision.
Solution: Use Paxos Commit to ensure total order broadcast.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is linearizability?

A

Ensures that all operations appear to take effect atomically between their start and end time.
All replicas behave as if there is only one copy of the data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are real-world use cases for linearizability?

A

Leader Election (ZooKeeper, etcd) – Ensures only one leader exists at a time.
Unique Constraints – E.g., preventing duplicate usernames.
Cross-Channel Dependencies – Coordinating distributed messaging systems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How does serializability differ from linearizability?

A

Serializability: Ensures transactions execute in a serial order.
Linearizability: Ensures individual operations execute in an up-to-date order.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Can a system provide both linearizability and serializability?

A

Yes! This is called Strict Serializability (1SR).
Example: Systems using Two-Phase Locking (2PL).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why is quorum-based consistency not always linearizable?

A

If some replicas receive updates before others, clients may read stale data.
Example:

Replica A gets 𝑣1, but Replicas B and C still see 𝑣0.
A client reading from B or C may get 𝑣0, violating linearizability.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How can quorum reads/writes be made linearizable?

A

ABD Algorithm (Attiya et al., 1995):

Reads must fetch from all replicas.
If newer values exist, clients must write them back to stale replicas (read-repair).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is eventual consistency?

A

Guarantees that if no new updates occur, all replicas will eventually converge.
Example: DNS servers take time to update but will eventually show the same records.

17
Q

What does the CAP Theorem state?

A

A system cannot be both:

Consistent (Linearizable)
Available
Partition-Tolerant

In case of a network partition, the system must choose between consistency or availability.

18
Q

What is causal consistency?

A

Ensures that cause-and-effect relationships are preserved.
Example: If Alice sends a message before Bob replies, Bob’s message must appear after Alice’s.

19
Q

How does causal consistency differ from linearizability?

A

Linearizability: Total order – every operation has a global order.
Causality: Partial order – only related events must be ordered.

20
Q

Why is causal consistency more scalable?

A

Unlike linearizability, causal consistency does not require coordination across all nodes.
More efficient for distributed databases (e.g., Facebook’s TAO).

21
Q

What are the challenges in collaborative applications (e.g., Google Docs)?

A

Users make concurrent changes.
The system must merge updates without conflicts.

22
Q

What are CRDTs (Conflict-Free Replicated Data Types)?

A

A family of algorithms ensuring conflict resolution without coordination.
Examples: Counters, sets, lists, maps, trees.

23
Q

How do state-based and operation-based CRDTs differ?

A

State-Based: Nodes merge their states periodically.
Operation-Based: Nodes broadcast every operation reliably.

24
Q

Where are CRDTs used in practice?

A

Google Docs (Operational Transformations).
Apple Notes (State-based CRDTs).
Redis, Riak, Microsoft Fluid, RiotGames (League of Legends).