consistency choices in modern distributed systems...modern distributed systems alexey gotsman imdea...

165
Consistency choices in modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain

Upload: others

Post on 31-Aug-2020

16 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Consistency choices in modern distributed systems

Alexey Gotsman

IMDEA Software Institute, Madrid, Spain

Page 2: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple
Page 3: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Data is replicated and partitioned across multiple nodes

Page 4: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Data centres across the world

Disaster-tolerance, minimising latency

Page 5: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Data centres across the world

Disaster-tolerance, minimising latency

Page 6: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Data centres across the world

Disaster-tolerance, minimising latency

Page 7: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

With thousands of machines inside

Load-balancing, fault-tolerance

Page 8: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Replicas on mobile devices

Offline use

Page 9: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

• Strong consistency model: the system behaves as if it processes requests serially on a centralised database - linearizability, serializability

Page 10: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

• Strong consistency model: the system behaves as if it processes requests serially on a centralised database - linearizability, serializability

• Requires synchronisation: contact other replicas when processing a request

Page 11: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

• Expensive: communication increases latency

• Impossible: either strong Consistency or Availability in the presence of network Partitions [CAP theorem]

Page 12: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

• Expensive: communication increases latency

• Impossible: either strong Consistency or Availability in the presence of network Partitions [CAP theorem]

Page 13: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Relaxing synchronisation

Process an update locally, propagate effects to other replicas later

add(100)

Page 14: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Relaxing synchronisation

Process an update locally, propagate effects to other replicas later

add(100)

Better scalability & availability+

- Weakens consistency: deposit seen with a delay

Page 15: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Anomalies

add(100)

notify(done)

Page 16: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Anomalies

add(100)

notify(done)

getNotif() : done

balance() : 0

Page 17: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(100)

notify(done)

getNotif() : done

balance() : 0Causal dependency: one operation is aware of another

Anomalies

Page 18: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(100)

notify(done)

getNotif() : done

balance() : 0Causal consistency model: disallows this anomaly

Anomalies

Page 19: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Weak consistency elsewhere

• Centralised DBs: snapshot isolation, read committed, ...

Page 20: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Weak consistency elsewhere

• Centralised DBs: snapshot isolation, read committed, ...

• Multicore processors: x86, ARM

Page 21: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Weak consistency elsewhere

• Centralised DBs: snapshot isolation, read committed, ...

• Multicore processors: x86, ARM

• Programming languages: C/C++, Java

Page 22: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Programming models

• Replicated data types (aka CRDTs): encapsulate conflict-resolution policies

• Novel forms of transactions

• Varying consistency among operations

Page 23: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Programming models

• Replicated data types (aka CRDTs): encapsulate conflict-resolution policies

• Novel forms of transactions

• Varying consistency among operations

Page 24: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Problem

Poor guidelines on how to use the new programming models: are we weakening consistency too much, too little, just right?

Page 25: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Problem

Poor guidelines on how to use the new programming models: are we weakening consistency too much, too little, just right?

“If no new updates are made to the database, then replicas will eventually reach a consistent state”

Page 26: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Problem

Poor guidelines on how to use the new programming models: are we weakening consistency too much, too little, just right?

“If no new updates are made to the database, then replicas will eventually reach a consistent state”

Page 27: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Problem

Poor guidelines on how to use the new programming models: are we weakening consistency too much, too little, just right?

“If no new updates are made to the database, then replicas will eventually reach a consistent state”

Page 28: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple
Page 29: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple
Page 30: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Pay-off often worth it: geo-distribution, offline access

Theory can help: guidelines and tools for relaxing synchronisation without compromising correctness

Page 31: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Outline

• Replicated data types (CRDTs)

• Specification of consistency models

• Determining the right level of consistency

Page 32: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Outline

• Replicated data types (CRDTs)

• Specification of consistency models

• Determining the right level of consistency

Page 33: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

cart.add(book)

cart = {book}

cart.remove(book)

Conflict resolution

Page 34: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

cart.add(book) Conflict!

Should the remove cancel the concurrent add? Depends on application requirements

cart = {book}

cart.remove(book)

Conflict resolution

Page 35: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Remove wins: cart = ∅

Add wins: cart = {book}

Last writer wins: choose based on operation time-stamps

Conflict!

Conflict resolution

cart = {book}

cart.add(book) cart.remove(book)

Page 36: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Conflict!

Conflict resolution

cart = {book}

cart.add(book) cart.remove(book)

• Most widespread application - collaborative editing: Google Docs, Office Online

• Low latency requires relaxing synchronisation, leads to conflicts

Page 37: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Replicated data types (CRDTs)

• Encapsulate conflict-resolution policies:

Object ➔ Type ➔ Conflict resolution policy

[Shapiro et al., SSS'11]

• Not just read-write registers

• Examples: counter, register, set

Page 38: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ

Replica states: σ ∈ State

Replicated data types

Page 39: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ

⟦op⟧val

Replica states: σ ∈ State

op

Return value: ⟦op⟧val ∈ State ➞ Value

Replicated data types

Page 40: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ

σʹ

⟦op⟧eff(σ)(σʹ)

⟦op⟧eff(σ)⟦op⟧val

Effector: ⟦op⟧eff ∈ State ➞ (State ➞ State)

Replica states: σ ∈ State

op

Return value: ⟦op⟧val ∈ State ➞ Value

Replicated data types

Page 41: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ

σʹ

⟦op⟧eff(σ)(σʹ)

⟦op⟧eff(σ)⟦op⟧val

Effector: ⟦op⟧eff ∈ State ➞ (State ➞ State)

Replica states: σ ∈ State

op

Return value: ⟦op⟧val ∈ State ➞ Value

Replicated data types

Page 42: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ

σʹ

⟦op⟧eff(σ)(σʹ)

⟦op⟧eff(σ)⟦op⟧val

Effector: ⟦op⟧eff ∈ State ➞ (State ➞ State)

Replica states: σ ∈ State

op

Return value: ⟦op⟧val ∈ State ➞ Value

Effector

Replicated data types

Page 43: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ

σʹ

⟦op⟧eff(σ)(σʹ)

⟦op⟧eff(σ)⟦op⟧val

Effector: ⟦op⟧eff ∈ State ➞ (State ➞ State)

Replica states: σ ∈ State

op

Return value: ⟦op⟧val ∈ State ➞ Value

Effector

Replicated data types

Page 44: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ

σʹ

⟦op⟧eff(σ)(σʹ)

⟦op⟧eff(σ)⟦op⟧val

⟦read()⟧eff(σ) = λσ. σ

State = Z

op

⟦read()⟧val(σ) = σ

Counter

Page 45: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ

σʹ

⟦op⟧eff(σ)(σʹ)

⟦op⟧eff(σ)⟦op⟧val

⟦add(100)⟧eff(σ) = λσʹ. (σʹ + 100)

op

Counter

Page 46: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ

50

⟦op⟧eff(σ)(σʹ)

⟦op⟧eff(σ)⟦op⟧val

⟦add(100)⟧eff(σ) = λσʹ. (σʹ + 100)

op

Counter

Page 47: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ

50

150

⟦op⟧eff(σ)⟦op⟧val

⟦add(100)⟧eff(σ) = λσʹ. (σʹ + 100)

op

Counter

Page 48: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ

50

150

⟦op⟧eff(σ)⟦op⟧val

op

⟦add(100)⟧eff(σ) = λσʹ. (σ + 100)

Counter

Page 49: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

⟦add(100)⟧eff(σ) = λσʹ. (σ + 100)

count = 0

add(100)

count = 0

add(200)

Page 50: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

⟦add(100)⟧eff(σ) = λσʹ. (σ + 100)

count = 0

add(100)

count = 0

count = 200count = 100

λσʹ. 100add(200)

λσʹ. 200

Page 51: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

⟦add(100)⟧eff(σ) = λσʹ. (σ + 100)

count = 0

add(100)

count = 0

count = 200

count = 100

count = 100

λσʹ. 100

count = 200

add(200)λσʹ. 200

Eventual consistency violated!

Page 52: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

• Effectors have to commute:

• Eventual consistency: replicas receiving the same messages in different orders end up in the same state

∀op1, op2, σ1, σ2. ⟦op1⟧eff(σ1) ; ⟦op2⟧eff(σ2) = ⟦op2⟧eff(σ2) ; ⟦op1⟧eff(σ1)

Ensuring eventual consistency

Page 53: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Last-writer-wins register

write(1) write(2)

• Conflict arbitrated using timestamps

• Link to shared-memory consistency models

Page 54: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Last-writer-wins register

write(1) write(2)

State = Value × Timestamp

⟦read()⟧val(v, t) = v

Page 55: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Last-writer-wins register

write(1) write(2)

⟦write(vnew)⟧eff(v, t) =

let tnew = newTS() in

λ(vʹ, tʹ). if tnew > tʹ then (vnew, tnew) else (v, t)

Page 56: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Last-writer-wins register

write(1) write(2)

⟦write(vnew)⟧eff(v, t) =

let tnew = newTS() in

λ(vʹ, tʹ). if tnew > tʹ then (vnew, tnew) else (v, t)

t1 t2

t1 < t2

Page 57: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Last-writer-wins register

write(1) write(2)

⟦write(vnew)⟧eff(v, t) =

let tnew = newTS() in

λ(vʹ, tʹ). if tnew > tʹ then (vnew, tnew) else (v, t)

t1 t2

t1 < t2

Page 58: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Last-writer-wins register

write(1) write(2)

⟦write(vnew)⟧eff(v, t) =

let tnew = newTS() in

λ(vʹ, tʹ). if tnew > tʹ then (vnew, tnew) else (v, t)

t1 t2

t1 < t2

Page 59: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Last-writer-wins register

write(1) write(2)

⟦write(vnew)⟧eff(v, t) =

let tnew = newTS() in

λ(vʹ, tʹ). if tnew > tʹ then (vnew, tnew) else (v, t)

t1 t2

t1 < t2

read(): 2

Page 60: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Last-writer-wins register

write(1) write(2)

⟦write(vnew)⟧eff(v, t) =

let tnew = newTS() in

λ(vʹ, tʹ). if tnew > tʹ then (vnew, tnew) else (v, t)

t1 t2

t1 < t2

read(): 2 read(): 2

Page 61: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Last-writer-wins register

write(1) write(2)

⟦write(vnew)⟧eff(v, t) =

let tnew = newTS() in

λ(vʹ, tʹ). if tnew > tʹ then (vnew, tnew) else (v, t)

t1 t2

t1 < t2

read(): 2 read(): 2

Page 62: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Add-wins set

cart = {book}

cart.add(book) cart.remove(book)

cart = {book}

Page 63: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Add-wins set

cart = {book}

cart.add(book) cart.remove(book)

• remove() acts differently wrt add() depending on whether it's concurrent or not

• Each addition creates a new instance: State = set of pairs (element, unique id)

cart = {book}

Page 64: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(book)

{(book,1)}

⟦add(x)⟧eff(σ) = λσʹ. (σʹ ∪ {(x, uniqueid()})

Each add() creates a new element instance:

Page 65: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(book)

{(book,1)}

{(book,1), (book,2)}

⟦add(x)⟧eff(σ) = λσʹ. (σʹ ∪ {(x, uniqueid()})

Each add() creates a new element instance:

λσʹ. σʹ ∪ {(book, 2)}

Page 66: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(book)

{(book,1)}

{(book,1), (book,2)}

Page 67: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(book)

{(book,1)}

{(book,1), (book,2)}

read() : {book}

⟦read()⟧val(σ) = {x | {∃ id. (x, id)} ∈ σ)

Instance ids ignored when reading the set:

Page 68: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(book)

{(book,1)}

remove(book)

{(book,1)}

{(book,1), (book,2)}

Page 69: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(book)

{(book,1)}

remove(book)

remove(x) removes all currently present instances of x:

{(book,1)}

{(book,1), (book,2)}

⟦remove(x)⟧eff(σ) = λσʹ. (σʹ \ {(x, id) ∈ σ})

Page 70: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(book)

{(book,1)}

remove(book)

remove(x) removes all currently present instances of x:

{(book,1)}

{(book,1), (book,2)}

⟦remove(x)⟧eff(σ) = λσʹ. (σʹ \ {(x, id) ∈ σ})

λσʹ. σʹ \ {(book, 1)}

Page 71: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(book)

{(book,1)}

remove(book)

remove(x) removes all currently present instances of x:

{(book,1)}

{(book,1), (book,2)}

⟦remove(x)⟧eff(σ) = λσʹ. (σʹ \ {(x, id) ∈ σ})

{(book,2)}

λσʹ. σʹ \ {(book, 1)}

Page 72: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(book)

{(book,1)}

remove(book)

{(book,1)}

{(book,1), (book,2)}

{(book,2)}

Page 73: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(book)

{(book,1)}

remove(book)

{(book,1)}

{(book,1), (book,2)}

{(book,2)} {(book,2)}

Effectors commutative ➔ replicas converge

λσʹ. σʹ ∪ {(book, 2)}

Page 74: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Outline

• Replicated data types (CRDTs)

• Specification of consistency models

• Determining the right level of consistency

Page 75: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Specification rationale

• Abstracts from implementation details

• Allows obtaining theoretical results: impossibility, inherent complexity

• Axiomatic style: connects to weak shared-memory models

Conflict-resolution policies + anomalies

Page 76: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Sequential data type semantics

Strong consistency ➔ operations are totally ordered:

set.read() : ∅

set.add(book)

set.remove(book)

Compute the result by applying operations in sequence

Page 77: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

set.add(book)

set.read() : ?

Delivered?

Replicated data type semantics

Only updates that have been delivered to the replica performing the operation are important

Page 78: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

set.add(book)Delivered?

Replicated data type semantics

Abstract by the visibility relation on operations (acyclic, ...)

Visible?set.read() : ?

Page 79: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

set.add(book)Delivered?

Replicated data type semantics

Abstract by the visibility relation on operations (acyclic, ...)

Visible?

vis

read() : ?

set.add(book) set.remove(book)

vis➔

set.read() : ?

set.add(book)

set.remove(book)

set.read() : ?

Page 80: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

set.remove(book)

vis

set.add(book)

vis

set.add(book)

vis

set.read() : ?

vis

F: context(op) → return value(op)

Context: all updates visible to the operation and the visibility relation between them + one more thing

Replicated data type specification

Page 81: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

set.remove(book)

vis

set.add(book)

vis

set.add(book)

vis

set.read() : ?

vis

F: context(op) → return value(op)

Context: all updates visible to the operation and the visibility relation between them + one more thing

Replicated data type specification

Page 82: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

set.remove(book)

vis

set.add(book)

vis

set.add(book)

vis

set.read() : ?

vis

F: context(op) → return value(op)

Context: all updates visible to the operation and the visibility relation between them + one more thing

Replicated data type specification

Page 83: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

set.remove(book)

vis

set.add(book)

vis

set.add(book)

vis

vis

F: context(op) → return value(op)

Context: all updates visible to the operation and the visibility relation between them + one more thing

Add-wins set

set.read() : ?

Page 84: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

set.remove(book)

vis

set.add(book)

vis

set.add(book)

vis

vis

F: context(op) → return value(op)

Context: all updates visible to the operation and the visibility relation between them + one more thing

Add-wins set

set.read() : ?

Page 85: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

set.remove(book)

vis

set.add(book)

vis

set.add(book)

vis

vis

F: context(op) → return value(op)

Context: all updates visible to the operation and the visibility relation between them + one more thing

Add-wins set

set.read() : ?

Page 86: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

set.remove(book)

vis

set.add(book)

vis

set.add(book)

vis

set.read() : {book}

vis

F: context(op) → return value(op)

Context: all updates visible to the operation and the visibility relation between them + one more thing

Add-wins set

Page 87: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

F: cancel all adds seen by a remove

set.remove(book)

vis

set.add(book)

vis

set.add(book)

vis

set.read() : {book}

vis

F: context(op) → return value(op)

Context: all updates visible to the operation and the visibility relation between them + one more thing

Add-wins set

Page 88: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

vis

set.remove(book)

vis

set.add(book)

vis

set.add(book)

vis

set.read() : ∅

F: context(op) → return value(op)

Context: all updates visible to the operation and the visibility relation between them + one more thing

vis

Add-wins set

F: cancel all adds seen by a remove

Page 89: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Last-writer-wins register

write(1) write(2)t1 t2

t1 < t2

read(): 2 read(): 2

Page 90: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Last-writer-wins register

write(1) write(2)t1 t2

t1 < t2

read(): 2 read(): 2

Arbitrated before

Arbitration specifies extra information used to determine the outcome uniquely

Page 91: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

reg.write(3)

vis

reg.write(1)

vis

reg.write(2)

vis

reg.read() : 3

F: return the value of the last write in ar

ar ar

F: context of op → return value of op

Context: all updates visible to the operation and the visibility and arbitration relations between them

Last-writer-wins register

Page 92: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Almost arbitrary: e.g., little control over when updates are visible to other replicas

set.add(book) ?

Where do vis & ar come from?

Page 93: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Almost arbitrary: e.g., little control over when updates are visible to other replicas

set.add(book)

But may guarantee that they don’t change unpredictably in the same session ➜ disallow anomalies

?

set.read()

session order vis

: {book}

Where do vis & ar come from?

Page 94: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Almost arbitrary: e.g., little control over when updates are visible to other replicas

set.add(book)

But may guarantee that they don’t change unpredictably in the same session ➜ disallow anomalies

?

set.read()

session order vis

: {book}

Where do vis & ar come from?

Consistency axioms

Page 95: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Causal consistency

counter.add(100)

set.add(notification)

set.read() ∋ notification

counter.read() : 0

Page 96: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Disallowed by causal consistency

Causal consistency

counter.add(100)

set.add(notification)

set.read() ∋ notification

counter.read() : 0

Page 97: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

vis

Abstract execution: (E, so, vis, ar)

counter.add(100)

set.add(notification)

set.read() ∋ notification

counter.read() : 0

session order

session order

Generalises operation contexts

Page 98: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Object Op Parameter Return value

All events that happened on the interface client/database & relations between them

vis

Abstract execution: (E, so, vis, ar)

counter.add(100)

set.add(notification)

set.read() ∋ notification

counter.read() : 0

session order

session order

Generalises operation contexts

Page 99: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Abstract execution: (E, so, vis, ar)

Operations grouped by clients and arranged in session order

Client 1 Client 2

viscounter.add(100)

set.add(notification)

set.read() ∋ notification

counter.read() : 0

session order

session order

Page 100: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Determines the context of every operation

Context(op) = projection onto events visible to op

return value(op) = F(Context(op))

Abstract execution: (E, so, vis, ar)

viscounter.add(100)

set.add(notification)

set.read() ∋ notification

counter.read() : 0

session order

session order

Page 101: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

viscounter.add(100)

set.add(notification)

set.read() ∋ notification

counter.read() : 100

session order

session order

vis

Context(op) = projection onto events visible to op

return value(op) = F(Context(op))

Determines the context of every operation

Abstract execution: (E, so, vis, ar)

Page 102: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

viscounter.add(100)

set.add(notification)

set.read() ∋ notification

counter.read() : 100

session order

session order

vis

Context(op) = projection onto events visible to op

return value(op) = F(Context(op))

Determines the context of every operation

Abstract execution: (E, so, vis, ar)

Page 103: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Consistency axioms

Consistency axioms disallow anomalies by constraining executions

viscounter.add(100)

set.add(notification)

set.read() ∋ notification

counter.read() : 0

session order

session order

Page 104: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Causal consistency:

Consistency axioms

Consistency axioms disallow anomalies by constraining executions

viscounter.add(100)

set.add(notification)

set.read() ∋ notification

counter.read() : 0

session order

session order

(𝗌𝗈 ∪ 𝗏𝗂𝗌 ∪ 𝖺𝗋) is acyclic

(𝗌𝗈 ∪ 𝗏𝗂𝗌)+ ⊆ 𝗏𝗂𝗌

Page 105: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Causal consistency:

Consistency axioms

Consistency axioms disallow anomalies by constraining executions

viscounter.add(100)

set.add(notification)

set.read() ∋ notification

counter.read() : 0

session order

session order

vis

(𝗌𝗈 ∪ 𝗏𝗂𝗌 ∪ 𝖺𝗋) is acyclic

(𝗌𝗈 ∪ 𝗏𝗂𝗌)+ ⊆ 𝗏𝗂𝗌

Page 106: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Causal consistency:

Consistency axioms

viscounter.add(100)

set.add(notification)

set.read() ∋ notification

counter.read() : 0

session order

session order

(𝗌𝗈 ∪ 𝗏𝗂𝗌)+ ⊆ 𝗏𝗂𝗌

(𝗌𝗈 ∪ 𝗏𝗂𝗌 ∪ 𝖺𝗋) is acyclic

Principle: strengthen consistency by mandating that more edges be included into vis and ar

vis

Page 107: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Basic eventual consistency

Session guarantees

Per-object causal consistency

Causal consistency

Strong consistency

Page 108: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Basic eventual consistency

Session guarantees

Per-object causal consistency

Causal consistency

Strong consistency

≈ C/C++ relaxed

≈ C/C++ release/acquire

• Processors and languages don’t provide strong consistency: weak memory models

• Our specifications similar to weak memory model definitions

• Consistency axioms for registers ≈ C/C++ memory model

Page 109: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Conflict resolution policies ➔ Data type spec

Anomalies ➔ Consistency axioms

Putting it all together

(E, so, vis, ar)

Page 110: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

request1

response1

request2

response2...

request1

response1

request2

response2...

Conflict resolution policies ➔ Data type spec

Anomalies ➔ Consistency axioms

Putting it all together

(E, so, vis, ar)

Page 111: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

request1

response1

request2

response2...

Events (E, so) allowed iff

∃ execution (E, so, vis, ar)

satisfying data type specs and axioms

Putting it all togetherConflict resolution policies ➔ Data type spec

Anomalies ➔ Consistency axioms

➔ (E, so, vis, ar)

request1

response1

request2

response2...

Page 112: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

request1

response1

request2

response2...

Events (E, so) allowed iff

∃ execution (E, so, vis, ar)

satisfying data type specs and axioms

Putting it all togetherConflict resolution policies ➔ Data type spec

Anomalies ➔ Consistency axioms

➔ (E, so, vis, ar)

request1

response1

request2

response2...

[POPL’14]

Page 113: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Theoretical results

• Causal consistency is the strongest model that provides availability under network partitions [Attiya et al., PODC'15]

Terms and conditions apply

Page 114: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Theoretical results

• Causal consistency is the strongest model that provides availability under network partitions [Attiya et al., PODC'15]

• Some replicated data types have an inherently high metadata overhead: can't discard a character when deleting it from a Google Docs document! [Attiya et al., PODC'16]

Terms and conditions apply

Page 115: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Outline

• Replicated data types (CRDTs)

• Specification of consistency models

• Determining the right level of consistency

Page 116: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Application correctness

• Does weakening consistency preserve application correctness?

Integrity invariants: account balance is non-negative, only registered students are enrolled into a course

• Vanilla weak consistency often too weak to preserve correctness

• Need to strengthen consistency in parts of the application

Page 117: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Application correctness

• Does weakening consistency preserve application correctness?

Integrity invariants: account balance is non-negative, only registered students are enrolled into a course

• Vanilla weak consistency often too weak to preserve correctness

• Need to strengthen consistency in parts of the application

Page 118: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ

σʹ

⟦op⟧eff(σ)(σʹ)

⟦op⟧eff(σ)⟦op⟧val

⟦add(100)⟧eff(σ) = λσʹ. (σʹ + 100)

op

Deposits

Page 119: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ⟦op⟧eff(σ)

⟦op⟧val

op

if σ ≥ 100 then (λσʹ. σʹ - 100) else (λσʹ. σʹ)⟦withdraw(100)⟧eff(σ) =

σʹ

⟦op⟧eff(σ)(σʹ)

Withdrawals

Page 120: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ⟦op⟧eff(σ)

⟦op⟧val

op

if σ ≥ 100 then (λσʹ. σʹ - 100) else (λσʹ. σʹ)⟦withdraw(100)⟧eff(σ) =

σʹ

⟦op⟧eff(σ)(σʹ)

Withdrawals

Page 121: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ⟦op⟧eff(σ)

⟦op⟧val

op

if σ ≥ 100 then (λσʹ. σʹ - 100) else (λσʹ. σʹ)⟦withdraw(100)⟧eff(σ) =

σʹ

⟦op⟧eff(σ)(σʹ)

Withdrawals

Page 122: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σ⟦op⟧eff(σ)

⟦op⟧val

op

if σ ≥ 100 then (λσʹ. σʹ - 100) else (λσʹ. σʹ)⟦withdraw(100)⟧eff(σ) =

σʹ

⟦op⟧eff(σ)(σʹ)

Withdrawals

Page 123: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

balance = 100

withdraw(100) : ✔

balance = 100

withdraw(100) : ✔

if σ ≥ 100 then (λσʹ. σʹ - 100) else (λσʹ. σʹ)⟦withdraw(100)⟧eff(σ) =

Page 124: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

balance = 100

withdraw(100) : ✔

balance = 100

withdraw(100) : ✔

balance = 0balance = 0

λσʹ. σʹ - 100

if σ ≥ 100 then (λσʹ. σʹ - 100) else (λσʹ. σʹ)⟦withdraw(100)⟧eff(σ) =

Page 125: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

balance = 100

withdraw(100) : ✔

balance = 100

withdraw(100) : ✔

balance = 0

balance = -100

balance = 0

λσʹ. σʹ - 100

if σ ≥ 100 then (λσʹ. σʹ - 100) else (λσʹ. σʹ)⟦withdraw(100)⟧eff(σ) =

Page 126: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

balance = 100

withdraw(100) : ✔

balance = 100

withdraw(100) : ✔

balance = 0

balance = -100

balance = 0

λσʹ. σʹ - 100

balance = 100

add(100) : ✔

Page 127: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

balance = 100

withdraw(100) : ✔

balance = 100

withdraw(100) : ✔

balance = 0

balance = -100

balance = 0

λσʹ. σʹ - 100

balance = 100

add(100) : ✔• Withdrawals strongly consistent

• Deposits eventually consistent

Tune consistency:

Page 128: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Consistency choices

• Databases with multiple consistency levels:

‣ Commercial: Amazon DynamoDB, Microsoft DocumentDB

‣ Research: Li+ OSDI’12; Terry+ SOSP’13; Balegas+ EuroSys’15; Li+ USENIX ATC’18

• Pay for stronger semantics with latency, possible unavailability and money

• Hard to figure out the minimum consistency necessary to maintain correctness

• Verification method and tool

Page 129: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(100)

withdraw(100) : ✔ set.withdraw(100) : ✔

vis

Strengthening consistency

vis

• Baseline model: causal consistency

• Problem: withdrawals are causally independent

Page 130: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(100)

withdraw(100) : ✔ set.withdraw(100) : ✔

vis

Strengthening consistency

vis

• Symmetric conflict relation on ops: ⋈ ⊆ Op × Op, e.g., withdraw ⋈ withdraw

• Conflicting operations cannot be causally independent

Page 131: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(100)

withdraw(100) : ✔ set.withdraw(100) : ✘

vis

Strengthening consistency

vis

• Symmetric conflict relation on ops: ⋈ ⊆ Op × Op, e.g., withdraw ⋈ withdraw

• Conflicting operations cannot be causally independent

Page 132: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(100)

withdraw(100) : ✔ set.withdraw(100) : ✘

vis

Strengthening consistency

vis

vis

• Symmetric conflict relation on ops: ⋈ ⊆ Op × Op, e.g., withdraw ⋈ withdraw

• Conflicting operations cannot be causally independent

Page 133: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(100)

withdraw(100) : ✔ set.withdraw(100) : ✘

vis

Strengthening consistency

vis

vis

• Symmetric conflict relation on ops: ⋈ ⊆ Op × Op, e.g., withdraw ⋈ withdraw

• Conflicting operations cannot be causally independent

• Implemented using consensus

• add() doesn't need synchronisation

Page 134: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

add(100)

withdraw(100) : ✔ set.withdraw(100) : ✘

vis

Strengthening consistency

vis

vis

Do we always have I = (balance ≥ 0)?

Page 135: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Check it’s preserved after executing op

σ ∈ Iop

Assume invariant holds

Page 136: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ

⟦op⟧eff(σ)(σʹ) ∈ I ?

⟦op⟧eff(σ)

σ ∈ Iop

Effect applied in a different state!

Page 137: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ

⟦op⟧eff(σ)(σʹ) ∈ I ?

⟦op⟧eff(σ)

σ ∈ Iop

if σ ≥ 100 then (λσʹ. σʹ - 100) else (λσʹ. σʹ)⟦withdraw(100)⟧eff(σ) =

⟦op⟧eff(σ) = if P(σ) then f(σ) else if...

Page 138: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ

⟦op⟧eff(σ)(σʹ) ∈ I ?

⟦op⟧eff(σ)

σ ∈ Iop

⟦op⟧eff(σ) = if P(σ) then f(σ) else if...

1. Effector safety: f(σ) preserves I when executed in any state satisfying P: {I ∧ P} f(σ) {I}

Page 139: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ

⟦op⟧eff(σ)(σʹ) ∈ I ?

⟦op⟧eff(σ)

σ ∈ Iop

⟦op⟧eff(σ) = if P(σ) then f(σ) else if...

{bal ≥ 0 ∧ bal ≥ 100} bal := bal-100 {bal ≥ 0}

1. Effector safety: f(σ) preserves I when executed in any state satisfying P: {I ∧ P} f(σ) {I}

Page 140: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ

⟦op⟧eff(σ)(σʹ) ∈ I ?

⟦op⟧eff(σ)

σ ∈ Iop

⟦op⟧eff(σ) = if P(σ) then f(σ) else if...

{bal ≥ 0 ∧ bal ≥ 100} bal := bal-100 {bal ≥ 0}

1. Effector safety: f(σ) preserves I when executed in any state satisfying P: {I ∧ P} f(σ) {I}

Page 141: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ

⟦op⟧eff(σ)(σʹ) ∈ I ?

⟦op⟧eff(σ)

σ ∈ Iop

⟦op⟧eff(σ) = if P(σ) then f(σ) else if...

{bal ≥ 0 ∧ bal ≥ 100} bal := bal-100 {bal ≥ 0}

1. Effector safety: f(σ) preserves I when executed in any state satisfying P: {I ∧ P} f(σ) {I}

Page 142: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ

⟦op⟧eff(σ)(σʹ) ∈ I ?

⟦op⟧eff(σ)

σ ∈ Iop

⟦op⟧eff(σ) = if P(σ) then f(σ) else if...

{bal ≥ 0 ∧ bal ≥ 100} bal := bal-100 {bal ≥ 0}

1. Effector safety: f(σ) preserves I when executed in any state satisfying P: {I ∧ P} f(σ) {I}

Page 143: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ

⟦op⟧eff(σ)(σʹ) ∈ I ?

⟦op⟧eff(σ)

σ ∈ Iop

⟦op⟧eff(σ) = if P(σ) then f(σ) else if...

{bal ≥ 0 ∧ bal ≥ 100} bal := bal-100 {bal ≥ 0}

1. Effector safety: f(σ) preserves I when executed in any state satisfying P: {I ∧ P} f(σ) {I}

Page 144: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

⟦op⟧eff(σ) = if P(σ) then f(σ) else if...

⟦op⟧eff(σ)(σʹ) ∈ I ✔

{bal ≥ 0 ∧ bal ≥ 100} bal := bal-100 {bal ≥ 0}

1. Effector safety: f(σ) preserves I when executed in any state satisfying P: {I ∧ P} f(σ) {I}

Page 145: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

⟦op⟧eff(σ) = if P(σ) then f(σ) else if...

⟦op⟧eff(σ)(σʹ) ∈ I ✔

P(σʹ)?

{bal ≥ 0 ∧ bal ≥ 100} bal := bal-100 {bal ≥ 0}

1. Effector safety: f(σ) preserves I when executed in any state satisfying P: {I ∧ P} f(σ) {I}

Page 146: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

⟦op⟧eff(σ) = if P(σ) then f(σ) else if...

P(σʹ)?

1. Effector safety: f(σ) preserves I when executed in any state satisfying P: {I ∧ P} f(σ) {I}

2. Precondition stability: P will hold when f(σ) is applied at any replica

Page 147: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

Page 148: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

Page 149: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

• Causal consistency ➜ receive op’s causal dependencies before receiving op

Page 150: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

f g

• But can have additional effectors of operations concurrent with op: f, g, ...

• Effectors commute, so σʹ = (f; g; ...)(σ)

• Causal consistency ➜ receive op’s causal dependencies before receiving op

Page 151: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

f g

• But can have additional effectors of operations concurrent with op: f, g, ...

• Effectors commute, so σʹ = (f; g; ...)(σ)

• Causal consistency ➜ receive op’s causal dependencies before receiving op

P(σ) ✔

Page 152: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

f g

Precondition stability: P is preserved by any effector f of any operation: {P} f {P}

P(σ) ✔

Page 153: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

add

{bal ≥ 100} bal := bal+100 {bal ≥ 100}

P(σ) ✔

Precondition stability: P is preserved by any effector f of any operation: {P} f {P}

Page 154: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

add

{bal ≥ 100} bal := bal+100 {bal ≥ 100}

P(σ) ✔

Precondition stability: P is preserved by any effector f of any operation: {P} f {P}

Page 155: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

{bal ≥ 100} bal := bal+100 {bal ≥ 100} ✔

add

P(σ) ✔

Precondition stability: P is preserved by any effector f of any operation: {P} f {P}

Page 156: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

{bal ≥ 100} bal := bal-100 {bal ≥ 100}

withdraw

{bal ≥ 100} bal := bal+100 {bal ≥ 100} ✔

P(σ) ✔

Precondition stability: P is preserved by any effector f of any operation: {P} f {P}

Page 157: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

{bal ≥ 100} bal := bal-100 {bal ≥ 100}

withdraw

{bal ≥ 100} bal := bal+100 {bal ≥ 100} ✔

P(σ) ✔

Precondition stability: P is preserved by any effector f of any operation: {P} f {P}

Page 158: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

{bal ≥ 100} bal := bal-100 {bal ≥ 100}

withdraw

{bal ≥ 100} bal := bal+100 {bal ≥ 100} ✔

P(σ) ✔

Precondition stability: P is preserved by any effector f of any operation: {P} f {P}

Page 159: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

withdraw

P(σ) ✔

Precondition stability: P is preserved by any effector f of any non-conflicting operation: {P} f {P}

Page 160: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

withdraw

P(σ) ✔

Precondition stability: P is preserved by any effector f of any non-conflicting operation: {P} f {P}

withdraw ⋈ withdraw; ¬(add ⋈ withdraw) ✔

Page 161: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

withdraw

P(σ) ✔

withdraw is a causal dependency of op

withdraw ⋈ withdraw; ¬(add ⋈ withdraw) ✔

Precondition stability: P is preserved by any effector f of any non-conflicting operation: {P} f {P}

Page 162: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

withdraw

P(σ) ✔

withdraw delivered before op: causality violated

withdraw ⋈ withdraw; ¬(add ⋈ withdraw) ✔

Precondition stability: P is preserved by any effector f of any non-conflicting operation: {P} f {P}

Page 163: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

σʹ⟦op⟧eff(σ)

σ ∈ Iop

P(σʹ)?

op’s causal dependencies

withdraw

P(σ) ✔

withdraw ⋈ withdraw; ¬(add ⋈ withdraw)

Precondition stability: P is preserved by any effector f of any non-conflicting operation: {P} f {P}

Page 164: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

CEC tool: Correct Eventual Consistency

• Automates the proof rule

• Discharges verification conditions using SMT

• Automatically suggests tokens

• Developed by Sreeja Nair (UPMC, Paris)

[POPL'16], https://github.com/LightKone/correct-eventual-consistency-tool

Page 165: Consistency choices in modern distributed systems...modern distributed systems Alexey Gotsman IMDEA Software Institute, Madrid, Spain Data is replicated and partitioned across multiple

Conclusion

• Programming models for weak consistency are more advanced: replicated data types, transactions

• Axiomatic specifications can define a wide range of consistency models and replicated data types

• Basis for theoretical results about implementability and its cost

• Verification methods enable weakening consistency without compromising correctness