just-right consistency: closing the cap gap

157
Just-Right Consistency Closing the CAP Gap Christopher S. Meiklejohn (@cmeik), Peter Lash LIGHT ONE

Upload: j-on-the-beach

Post on 21-Jan-2018

89 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Just-Right Consistency: Closing The CAP Gap

Just-Right ConsistencyClosing the CAP GapChristopher S. Meiklejohn (@cmeik),Peter Lash

LIGHT ONE

Page 2: Just-Right Consistency: Closing The CAP Gap

Outline: Closing the CAP Gap

• Just-Right ConsistencyAvailable as possible, and consistent when necessary

2

Page 3: Just-Right Consistency: Closing The CAP Gap

Outline: Closing the CAP Gap

• Just-Right ConsistencyAvailable as possible, and consistent when necessary

• AntidoteDBThe first database that provides transactions with strong semantics, targeted at the JRC approach

2

Page 4: Just-Right Consistency: Closing The CAP Gap

Outline: Closing the CAP Gap

• Just-Right ConsistencyAvailable as possible, and consistent when necessary

• AntidoteDBThe first database that provides transactions with strong semantics, targeted at the JRC approach

• Moving forwardAntidote’s path forward from research to company and product

2

Page 5: Just-Right Consistency: Closing The CAP Gap

Motivation Cloud Databases

3

Page 6: Just-Right Consistency: Closing The CAP Gap

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 7: Just-Right Consistency: Closing The CAP Gap

A

Centralized database.

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 8: Just-Right Consistency: Closing The CAP Gap

A

Clients read and write against the primary copy.

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 9: Just-Right Consistency: Closing The CAP Gap

A

B

C

Geo-replicated for both fault-tolerance and high-availability.

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 10: Just-Right Consistency: Closing The CAP Gap

A

B

C

Clients read and write locally for low-latency.

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 11: Just-Right Consistency: Closing The CAP Gap

A

B

C

What happens if C can’t communicate with other replicas?

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 12: Just-Right Consistency: Closing The CAP Gap

A

B

C

Choice 1: Consistent-Under-Partition (CP)• Synchronize each operation

Maintains “single system image”

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 13: Just-Right Consistency: Closing The CAP Gap

A

B

C

Choice 1: Consistent-Under-Partition (CP)• Synchronize each operation

Maintains “single system image”

• Spanner/F1, serializability modelCoordination is expensive; Spanner typically has to wait 100ms to commit an update transaction

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 14: Just-Right Consistency: Closing The CAP Gap

A

B

C

Choice 1: Consistent-Under-Partition (CP)• Synchronize each operation

Maintains “single system image”

• Spanner/F1, serializability modelCoordination is expensive; Spanner typically has to wait 100ms to commit an update transaction

Over-conservative,but easy to program!

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 15: Just-Right Consistency: Closing The CAP Gap

A

B

C

Choice 2: Available-Under-Partition (AP)• Riak, Cassandra, Dynamo

Operations issued against local copy, and across the cluster in parallel

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 16: Just-Right Consistency: Closing The CAP Gap

A

B

C

Choice 2: Available-Under-Partition (AP)• Riak, Cassandra, Dynamo

Operations issued against local copy, and across the cluster in parallel

• Local operation only, asynchronous propagationStale reads and write conflicts will occur without synchronization

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 17: Just-Right Consistency: Closing The CAP Gap

A

B

C

Choice 2: Available-Under-Partition (AP)• Riak, Cassandra, Dynamo

Operations issued against local copy, and across the cluster in parallel

• Local operation only, asynchronous propagationStale reads and write conflicts will occur without synchronization

Available,but difficult to program!

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 18: Just-Right Consistency: Closing The CAP Gap

A

B

C

CAP TheoremCP AP

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 19: Just-Right Consistency: Closing The CAP Gap

A

B

C

CAP Theorem

High cost

CP AP

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 20: Just-Right Consistency: Closing The CAP Gap

A

B

C

CAP Theorem

High cost

Low availability

CP AP

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 21: Just-Right Consistency: Closing The CAP Gap

A

B

C

CAP Theorem

High cost

Low availability

Synchronization

CP AP

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 22: Just-Right Consistency: Closing The CAP Gap

A

B

C

CAP Theorem

High cost

Low availability

Synchronization

Low cost

CP AP

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 23: Just-Right Consistency: Closing The CAP Gap

A

B

C

CAP Theorem

High cost

Low availability

Synchronization

Low cost

High availability

CP AP

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 24: Just-Right Consistency: Closing The CAP Gap

A

B

C

CAP Theorem

High cost

Low availability

Synchronization

Low cost

High availability

Anomalies

CP AP

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 25: Just-Right Consistency: Closing The CAP Gap

A

B

C

CAP Theorem

High cost

Low availability

Synchronization

Low cost

High availability

Anomalies

CP AP

False dichotomy!

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

Page 26: Just-Right Consistency: Closing The CAP Gap

A

B

C

CAP Theorem

High cost

Low availability

Synchronization

Low cost

High availability

Anomalies

CP AP

False dichotomy!

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

• No “one-size-fits-all” consistency modelChoosing either model will either be over-conservative or risk anomalies

Page 27: Just-Right Consistency: Closing The CAP Gap

A

B

C

CAP Theorem

High cost

Low availability

Synchronization

Low cost

High availability

Anomalies

CP AP

False dichotomy!

[Photo: http://vignette3.wikia.nocookie.net/the-titans-rp-and-information/images/f/f5/Blank-World-map2.gif/revision/latest/scale-to-width-down/1280?cb=20141016203452]

• No “one-size-fits-all” consistency modelChoosing either model will either be over-conservative or risk anomalies

• Application-level invariantsInstead, tailor consistency choices based on application-level invariants for each operation

Page 28: Just-Right Consistency: Closing The CAP Gap

Just Right Consistency• Preserve sequential patterns

Applications written sequentially that are correct should maintain correctness under concurrency

13

Page 29: Just-Right Consistency: Closing The CAP Gap

Just Right Consistency• Preserve sequential patterns

Applications written sequentially that are correct should maintain correctness under concurrency

• AP-compatible invariantsStrongest AP model; invariants that only require “one way” communications

13

Page 30: Just-Right Consistency: Closing The CAP Gap

Just Right Consistency• Preserve sequential patterns

Applications written sequentially that are correct should maintain correctness under concurrency

• AP-compatible invariantsStrongest AP model; invariants that only require “one way” communications

• CAP-sensitive invariantsTransactions that require coordination; “two way” communication invariants

13

Page 31: Just-Right Consistency: Closing The CAP Gap

Just Right Consistency• Preserve sequential patterns

Applications written sequentially that are correct should maintain correctness under concurrency

• AP-compatible invariantsStrongest AP model; invariants that only require “one way” communications

• CAP-sensitive invariantsTransactions that require coordination; “two way” communication invariants

• Tools for analysis and verificationIdentify and verify application has sufficient synchronization to ensure application invariants

13

Page 32: Just-Right Consistency: Closing The CAP Gap

Example Fælles Medicinkort

14

Page 33: Just-Right Consistency: Closing The CAP Gap

Fælles Medicinkort• FMK [production] / FMKe [synthetic workload]

Danish National Joint Medicine Card; operating 24x7 since 2013 for 6 million Danish citizens

15

Page 34: Just-Right Consistency: Closing The CAP Gap

Fælles Medicinkort• FMK [production] / FMKe [synthetic workload]

Danish National Joint Medicine Card; operating 24x7 since 2013 for 6 million Danish citizens

• Lifecycle management for prescriptionsInvolves patient, pharmacy, and doctor management around active prescriptions in Denmark

15

Page 35: Just-Right Consistency: Closing The CAP Gap

Fælles Medicinkort• FMK [production] / FMKe [synthetic workload]

Danish National Joint Medicine Card; operating 24x7 since 2013 for 6 million Danish citizens

• Lifecycle management for prescriptionsInvolves patient, pharmacy, and doctor management around active prescriptions in Denmark

• Assumed correct in isolation “Correct-Individually”, C in ACID, each operation ensures application-level invariants

15

Page 36: Just-Right Consistency: Closing The CAP Gap

Fælles Medicinkort• FMK [production] / FMKe [synthetic workload]

Danish National Joint Medicine Card; operating 24x7 since 2013 for 6 million Danish citizens

• Lifecycle management for prescriptionsInvolves patient, pharmacy, and doctor management around active prescriptions in Denmark

• Assumed correct in isolation “Correct-Individually”, C in ACID, each operation ensures application-level invariants

15

• create-prescriptionCreate prescription for patient, doctor, pharmacy

• update-prescription-medicationAdd or increase medication to prescription

• process-prescriptionDeliver a medication by a pharmacy

• get-*-prescriptionsQuery functions to return information about prescriptions

Page 37: Just-Right Consistency: Closing The CAP Gap

FMKe Invariants• Relative order [referential integrity]

Create a prescription and reference it by a patient

16

Page 38: Just-Right Consistency: Closing The CAP Gap

FMKe Invariants• Relative order [referential integrity]

Create a prescription and reference it by a patient

• Joint update [atomicity]Create prescription, then update doctor, patient, and pharmacy

16

Page 39: Just-Right Consistency: Closing The CAP Gap

FMKe Invariants• Relative order [referential integrity]

Create a prescription and reference it by a patient

• Joint update [atomicity]Create prescription, then update doctor, patient, and pharmacy

• Precondition check [if, then]Medication should not be over delivered

16

Page 40: Just-Right Consistency: Closing The CAP Gap

Invariants AP-compatible

17

Page 41: Just-Right Consistency: Closing The CAP Gap

AP-compatible• No synchronization

Updates occur locally without blocking, no synchronization in the critical path

18

Page 42: Just-Right Consistency: Closing The CAP Gap

AP-compatible• No synchronization

Updates occur locally without blocking, no synchronization in the critical path

• Asynchronous operationUpdates are fast, available, and exploit concurrency

18

Page 43: Just-Right Consistency: Closing The CAP Gap

AP-compatible• No synchronization

Updates occur locally without blocking, no synchronization in the critical path

• Asynchronous operationUpdates are fast, available, and exploit concurrency

• Compatible invariantsRelative order and joint update invariants can be preserved

18

Page 44: Just-Right Consistency: Closing The CAP Gap

AP-compatibe Data Model

19

Page 45: Just-Right Consistency: Closing The CAP Gap

RA

RB

Page 46: Just-Right Consistency: Closing The CAP Gap

RA

RB

1

set(1)

Page 47: Just-Right Consistency: Closing The CAP Gap

RA

RB

1

set(1)

3

2

set(2)

set(3)

Page 48: Just-Right Consistency: Closing The CAP Gap

RA

RB

1

set(1)

3

2

set(2)

set(3)

2

3

Concurrent assignmentsdon’t commute!

Page 49: Just-Right Consistency: Closing The CAP Gap

RA

RB

1

set(1)

3

2

set(2)

set(3)

2

3

Concurrent assignmentsdon’t commute!

Assignment requires CP.

Page 50: Just-Right Consistency: Closing The CAP Gap

24

Can we find a suitable data model for AP systems?

Page 51: Just-Right Consistency: Closing The CAP Gap

Can we make non-commutative updates commutative?

24

Can we find a suitable data model for AP systems?

Page 52: Just-Right Consistency: Closing The CAP Gap

RA

RB

1

set(1)

3

2

set(2)

set(3)

?

?

How do we deterministically pick a value to keep?

Page 53: Just-Right Consistency: Closing The CAP Gap

RA

RB

1

set(1)

3

2

set(2)

set(3)

?

?

How do we deterministically pick a value to keep?

Do we use a timestamp?(like Cassandra, and drop a value?)

Page 54: Just-Right Consistency: Closing The CAP Gap

RA

RB

1

set(1)

3

2

set(2)

set(3)

?

?

How do we deterministically pick a value to keep?

Do we use a timestamp?(like Cassandra, and drop a value?)

Timestamps make concurrent operations commute

but fail to capture intent.

Page 55: Just-Right Consistency: Closing The CAP Gap

Can we be smarter about the merge function?

26

Page 56: Just-Right Consistency: Closing The CAP Gap

RA

RB

1

set(1)

3

2

set(2)

set(3)

3

3

max(2,3)

max(2,3)

Deterministic conflict resolution

function.

Page 57: Just-Right Consistency: Closing The CAP Gap

RA

RB

1

set(1)

3

2

set(2)

set(3)

3

3

max(2,3)

max(2,3)

Deterministic conflict resolution

function.

CRDTs generalize

this framework.

Page 58: Just-Right Consistency: Closing The CAP Gap

Conflict-Free Replicated Data Types

• Replicated abstract data types Extension of sequential data type that encapsulates deterministic merge function

28

Page 59: Just-Right Consistency: Closing The CAP Gap

Conflict-Free Replicated Data Types

• Replicated abstract data types Extension of sequential data type that encapsulates deterministic merge function

• Many existing designsSets, counters, registers, flags, maps

28

Page 60: Just-Right Consistency: Closing The CAP Gap

AP-compatibe Relative Order

29

Page 61: Just-Right Consistency: Closing The CAP Gap

RA

RB

Page 62: Just-Right Consistency: Closing The CAP Gap

RA

RB

Maintain program order implication invariant.

Page 63: Just-Right Consistency: Closing The CAP Gap

RA

RB

Maintain program order implication invariant.

For instance, P => Q.

Page 64: Just-Right Consistency: Closing The CAP Gap

RA

RB

Q

true(Q)

Make Q true.

Page 65: Just-Right Consistency: Closing The CAP Gap

RA

RB

Q

true(Q)

P

true(P)

Make P true.

Page 66: Just-Right Consistency: Closing The CAP Gap

RA

RB

Q

true(Q)

P

true(P)

Program order implies ordering relationship.

Page 67: Just-Right Consistency: Closing The CAP Gap

RA

RB

Q

true(Q)

P

true(P)

Ordering is respected at other replicas.

Page 68: Just-Right Consistency: Closing The CAP Gap

RA

RB

Q

true(Q)

P

true(P)

Out of order propagation violates invariant!

Page 69: Just-Right Consistency: Closing The CAP Gap

RA

RB

Q

true(Q)

P

true(P)

P is true, Q is NOT true!

Page 70: Just-Right Consistency: Closing The CAP Gap

Let’s look at a concrete example.

37

Page 71: Just-Right Consistency: Closing The CAP Gap

RA

RB

Page 72: Just-Right Consistency: Closing The CAP Gap

RA

RB

Q

true(Q)

Change default administrator password.

Page 73: Just-Right Consistency: Closing The CAP Gap

RA

RB

Q

true(Q)

P

true(P)

Enable administrator login.

Page 74: Just-Right Consistency: Closing The CAP Gap

RA

RB

Q

true(Q)

P

true(P)

Replica A is secure.

Page 75: Just-Right Consistency: Closing The CAP Gap

RA

RB

Q

true(Q)

P

true(P)

Replica B is secure.

Page 76: Just-Right Consistency: Closing The CAP Gap

RA

RB

Q

true(Q)

P

true(P)

Reordering allows default password to be used to login!

Page 77: Just-Right Consistency: Closing The CAP Gap

Causal Consistency• Respect causality

Ensure updates are delivered in the causal order [Lamport 78]

44

Page 78: Just-Right Consistency: Closing The CAP Gap

Causal Consistency• Respect causality

Ensure updates are delivered in the causal order [Lamport 78]

• Strongest available modelAlways able to return some compatible version for an object

44

Page 79: Just-Right Consistency: Closing The CAP Gap

Causal Consistency• Respect causality

Ensure updates are delivered in the causal order [Lamport 78]

• Strongest available modelAlways able to return some compatible version for an object

• Referential integrityCausal consistency is sufficient for providing referential integrity in an AP database

44

Page 80: Just-Right Consistency: Closing The CAP Gap

…relative order invariants are preserved transparently!

45

Causal consistency means…

Page 81: Just-Right Consistency: Closing The CAP Gap

AP-compatibe Joint Update

46

Page 82: Just-Right Consistency: Closing The CAP Gap

RA

RB

C1

Client performing reads.

Page 83: Just-Right Consistency: Closing The CAP Gap

RA

RB

C1

Rx

create Rx

Create prescription.

Page 84: Just-Right Consistency: Closing The CAP Gap

RA

RB

C1

Rx

create Rx

Dr

update Dr(Rx)

Add reference in doctor record.

Page 85: Just-Right Consistency: Closing The CAP Gap

RA

RB

C1

Rx

create Rx

Dr

update Dr(Rx)

Pt

update Pt(Rx)

Add reference in patient record.

Page 86: Just-Right Consistency: Closing The CAP Gap

RA

RB

C1

Rx

create Rx

Dr

update Dr(Rx)

Pt

update Pt(Rx)

Ph

update Ph(Rx)

Add reference in pharmacy record.

Page 87: Just-Right Consistency: Closing The CAP Gap

RA

RB

C1

Rx

create Rx

Dr

update Dr(Rx)

Pt

update Pt(Rx)

Ph

update Ph(Rx)

Updates are causally consistent.

Page 88: Just-Right Consistency: Closing The CAP Gap

RA

RB

C1

Rx

create Rx

Dr

update Dr(Rx)

Pt

update Pt(Rx)

Ph

update Ph(Rx)

Client can read inconsistent state.

Page 89: Just-Right Consistency: Closing The CAP Gap

RA

RB

C1

Rx

create Rx

Dr

update Dr(Rx)

Pt

update Pt(Rx)

Ph

update Ph(Rx)

Client is missing update to pharmacy.

Page 90: Just-Right Consistency: Closing The CAP Gap

Can we ensure updates are All-or-Nothing?

55

Page 91: Just-Right Consistency: Closing The CAP Gap

RA

RB

C1

T1

create Rxupdate Dr(Rx)update Pt(Rx)update Ph(Rx)

Group updates into an atomic transaction.

Page 92: Just-Right Consistency: Closing The CAP Gap

RA

RB

C1

T1

create Rxupdate Dr(Rx)update Pt(Rx)update Ph(Rx)

Updates reflect “All-Or-Nothing” property through snapshots.

Page 93: Just-Right Consistency: Closing The CAP Gap

RA

RB

C1

T1

create Rxupdate Dr(Rx)update Pt(Rx)update Ph(Rx)

T2

Transactions are delivered in causal order.

Page 94: Just-Right Consistency: Closing The CAP Gap

RA

RB

C1

T1

create Rxupdate Dr(Rx)update Pt(Rx)update Ph(Rx)

T2

Therefore, snapshots are causally consistent.

Page 95: Just-Right Consistency: Closing The CAP Gap

AP-compatible transactions provide the “A” in ACID

60

Page 96: Just-Right Consistency: Closing The CAP Gap

Transactional Causal Consistency

61

Strongest model that is available (AP)

Page 97: Just-Right Consistency: Closing The CAP Gap

Invariants CAP-sensitive

62

Page 98: Just-Right Consistency: Closing The CAP Gap

What about preventing over delivery of prescriptions?

63

Page 99: Just-Right Consistency: Closing The CAP Gap

RA(2)

RB(2) ?

?

RC(2) ?

Three replicas each with two available medications.

Page 100: Just-Right Consistency: Closing The CAP Gap

RA(2)

RB(2) 1

11

pp(1)

RC(2) 1

Replica A checks precondition and delivers medication.

Page 101: Just-Right Consistency: Closing The CAP Gap

RA(2)

RB(2) 1

11

pp(1)

RC(2) 1

Correct outcomewhere one medication remains.

Page 102: Just-Right Consistency: Closing The CAP Gap

Is this safe with concurrent operations?

67

Page 103: Just-Right Consistency: Closing The CAP Gap

RA(2)

RB(2) ?

?

RC(2) ?

Three replicas each with two available medications.

Page 104: Just-Right Consistency: Closing The CAP Gap

RA(2)

RB(2) 4

41

pp(1)

RC(2) 44

add(3)

Replica A checks precondition and delivers medication.

Page 105: Just-Right Consistency: Closing The CAP Gap

RA(2)

RB(2) 4

41

pp(1)

RC(2) 44

add(3)

Replica C adds three medicationsto the prescription.

Page 106: Just-Right Consistency: Closing The CAP Gap

RA(2)

RB(2) 4

41

pp(1)

RC(2) 44

add(3)

Correct outcome with four remaining medications.

Page 107: Just-Right Consistency: Closing The CAP Gap

RA(2)

RB(2) 4

41

pp(1)

RC(2) 44

add(3)

Correct outcome with four remaining medications.

Precondition is stable under concurrent addition.

Page 108: Just-Right Consistency: Closing The CAP Gap

Is this safe with concurrent deliveries?

72

Page 109: Just-Right Consistency: Closing The CAP Gap

RA(2)

RB(2) ?

?

RC(2) ?

Three replicas each with two available medications.

Page 110: Just-Right Consistency: Closing The CAP Gap

RA(2)

RB(2) -1

-11

pp(1)

RC(2) -10

pp(2)

Replica A checks precondition and delivers medication.

Page 111: Just-Right Consistency: Closing The CAP Gap

RA(2)

RB(2) -1

-11

pp(1)

RC(2) -10

pp(2)

Replica C concurrently checks preconditionand delivers two medications.

Page 112: Just-Right Consistency: Closing The CAP Gap

RA(2)

RB(2) -1

-11

pp(1)

RC(2) -10

pp(2)

Incorrect outcome violating non-negative invariant.

Page 113: Just-Right Consistency: Closing The CAP Gap

RA(2)

RB(2) -1

-11

pp(1)

RC(2) -10

pp(2)

Incorrect outcome violating non-negative invariant.

Precondition is NOT stable under concurrent fulfillment.

Page 114: Just-Right Consistency: Closing The CAP Gap

RA(2)

RB(2) -1

-11

pp(1)

RC(2) -10

pp(2)

Incorrect outcome violating non-negative invariant.

Precondition is NOT stable under concurrent fulfillment.

• Forbid concurrency Prevent operations from proceeding without synchronization to enforce invariant

• Allow concurrency and remove invariantAllow operation to proceed, knowing that the invariant may be violated under concurrent operations

Page 115: Just-Right Consistency: Closing The CAP Gap

How do we know when it’s safe?

77

Page 116: Just-Right Consistency: Closing The CAP Gap

CISE Analysis

78

Page 117: Just-Right Consistency: Closing The CAP Gap

RA

RB I?

I??

Upre?

RC I??

Vpre?

Analyze possible pairs of concurrent operations…

Page 118: Just-Right Consistency: Closing The CAP Gap

RA

RB I?

I??

Upre?

RC I??

Vpre?

…to identify operations where the invariant can be violated.

Page 119: Just-Right Consistency: Closing The CAP Gap

CISE Analysis• Individually correct

Individual operations never violate the invariant

81

Page 120: Just-Right Consistency: Closing The CAP Gap

CISE Analysis• Individually correct

Individual operations never violate the invariant

• ConvergenceConcurrent effects commute

81

Page 121: Just-Right Consistency: Closing The CAP Gap

CISE Analysis• Individually correct

Individual operations never violate the invariant

• ConvergenceConcurrent effects commute

• Precondition stabilityPreconditions are stable under every pair of concurrent operations

81

Page 122: Just-Right Consistency: Closing The CAP Gap

CISE Analysis• Individually correct

Individual operations never violate the invariant

• ConvergenceConcurrent effects commute

• Precondition stabilityPreconditions are stable under every pair of concurrent operations

81

If satisfied, invariant is guaranteed with concurrency.

Page 123: Just-Right Consistency: Closing The CAP Gap

Database AntidoteDB

82

Page 124: Just-Right Consistency: Closing The CAP Gap

AntidoteDB• Open-source Erlang database

Developed in Erlang, on top of the Riak Core distributed systems framework

83

Page 125: Just-Right Consistency: Closing The CAP Gap

AntidoteDB• Open-source Erlang database

Developed in Erlang, on top of the Riak Core distributed systems framework

• Transactional Causal ConsistencyOnly industrial-grade database providing both causal consistency and all-or-nothing transactions

83

Page 126: Just-Right Consistency: Closing The CAP Gap

AntidoteDB• Open-source Erlang database

Developed in Erlang, on top of the Riak Core distributed systems framework

• Transactional Causal ConsistencyOnly industrial-grade database providing both causal consistency and all-or-nothing transactions

• Alpha release availableCurrently under development, but an alpha release of the product is available on GitHub

83

Page 127: Just-Right Consistency: Closing The CAP Gap

A

B

N1

N2

TxnMgr

Materializer

Log

InterDC-Repl

Each data center…

Page 128: Just-Right Consistency: Closing The CAP Gap

A

B

N1

N2

TxnMgr

Materializer

Log

InterDC-Repl

…contains multiple nodes…

Page 129: Just-Right Consistency: Closing The CAP Gap

A

B

N1

N2

TxnMgr

Materializer

Log

InterDC-Repl

…each operating a transaction manager, materializers, log.

Page 130: Just-Right Consistency: Closing The CAP Gap

A

B

N1

N2

TxnMgr

Materializer

Log

InterDC-Repl

Strong consistency inside of the data center…

Page 131: Just-Right Consistency: Closing The CAP Gap

A

B

N1

N2

TxnMgr

Materializer

Log

InterDC-Repl

…with a causal consistency protocol running in the wide area.

Page 132: Just-Right Consistency: Closing The CAP Gap

Data Model

89

Register• Last-Writer Wins • Multi-Value

Set• Grow-Only • Add-Wins • Remove-Wins

Map

Counter• Unlimited • Restricted ≥ 0

Graph• Directed • Monotonic DAG • Edit graph

Sequence

Page 133: Just-Right Consistency: Closing The CAP Gap

Object API

90

User1 = {michel, antidote_crdt_mvreg, user_bucket},

{ok, Time2} = antidote:update_objects(ignore, [], [{User1, assign,

{["Michel", “[email protected]”], ClientIdentifier}}]),

{ok, Result, Time2} = antidote:read_objects( ignore, [], [User1]).

Page 134: Just-Right Consistency: Closing The CAP Gap

Object API

91

User1 = {michel, antidote_crdt_mvreg, user_bucket},

{ok, Time2} = antidote:update_objects(ignore, [], [{User1, assign,

{["Michel", “[email protected]”], ClientIdentifier}}]),

{ok, Result, Time2} = antidote:read_objects( ignore, [], [User1]).

Identify an object by object identifier.

Page 135: Just-Right Consistency: Closing The CAP Gap

Object API

92

User1 = {michel, antidote_crdt_mvreg, user_bucket},

{ok, Time2} = antidote:update_objects(ignore, [], [{User1, assign,

{["Michel", “[email protected]”], ClientIdentifier}}]),

{ok, Result, Time2} = antidote:read_objects( ignore, [], [User1]).

Use the update API to assign a value to this register.

Page 136: Just-Right Consistency: Closing The CAP Gap

Object API

93

User1 = {michel, antidote_crdt_mvreg, user_bucket},

{ok, Time2} = antidote:update_objects(ignore, [], [{User1, assign,

{["Michel", “[email protected]”], ClientIdentifier}}]),

{ok, Result, Time2} = antidote:read_objects( ignore, [], [User1]).

Read the object, providing a minimum snapshot time.

Page 137: Just-Right Consistency: Closing The CAP Gap

Object API

93

User1 = {michel, antidote_crdt_mvreg, user_bucket},

{ok, Time2} = antidote:update_objects(ignore, [], [{User1, assign,

{["Michel", “[email protected]”], ClientIdentifier}}]),

{ok, Result, Time2} = antidote:read_objects( ignore, [], [User1]).

Read the object, providing a minimum snapshot time.

Simple, operation-based API. (think Redis, Riak CRDTs)

Page 138: Just-Right Consistency: Closing The CAP Gap

Object API

93

User1 = {michel, antidote_crdt_mvreg, user_bucket},

{ok, Time2} = antidote:update_objects(ignore, [], [{User1, assign,

{["Michel", “[email protected]”], ClientIdentifier}}]),

{ok, Result, Time2} = antidote:read_objects( ignore, [], [User1]).

Read the object, providing a minimum snapshot time.

Simple, operation-based API. (think Redis, Riak CRDTs)

Causal dependencies are automatically captured by

execution order.

Page 139: Just-Right Consistency: Closing The CAP Gap

Transaction API

94

{ok, TxId} = antidote:start_transaction(Timestamp, []), {ok, _} = antidote:read_objects([Set], TxId), ok = antidote:update_objects([{Set, add, "Java"}], TxId), {ok, _} = antidote:commit_transaction(TxId).

Page 140: Just-Right Consistency: Closing The CAP Gap

Transaction API

95

Start a transaction with the transaction API, with a given snapshot time and return a transaction identifier.

{ok, TxId} = antidote:start_transaction(Timestamp, []), {ok, _} = antidote:read_objects([Set], TxId), ok = antidote:update_objects([{Set, add, "Java"}], TxId), {ok, _} = antidote:commit_transaction(TxId).

Page 141: Just-Right Consistency: Closing The CAP Gap

{ok, TxId} = antidote:start_transaction(Timestamp, []), {ok, _} = antidote:read_objects([Set], TxId), ok = antidote:update_objects([{Set, add, "Java"}], TxId), {ok, _} = antidote:commit_transaction(TxId).

Transaction API

96

Read objects using the interactive transaction API.

Page 142: Just-Right Consistency: Closing The CAP Gap

{ok, TxId} = antidote:start_transaction(Timestamp, []), {ok, _} = antidote:read_objects([Set], TxId), ok = antidote:update_objects([{Set, add, "Java"}], TxId), {ok, _} = antidote:commit_transaction(TxId).

Transaction API

97

Update objects using the interactive transaction API.

Page 143: Just-Right Consistency: Closing The CAP Gap

{ok, TxId} = antidote:start_transaction(Timestamp, []), {ok, _} = antidote:read_objects([Set], TxId), ok = antidote:update_objects([{Set, add, "Java"}], TxId), {ok, _} = antidote:commit_transaction(TxId).

Transaction API

98

Once finished updating, commit the transaction.

Page 144: Just-Right Consistency: Closing The CAP Gap

{ok, TxId} = antidote:start_transaction(Timestamp, []), {ok, _} = antidote:read_objects([Set], TxId), ok = antidote:update_objects([{Set, add, "Java"}], TxId), {ok, _} = antidote:commit_transaction(TxId).

Transaction API

98

Once finished updating, commit the transaction.

Transactions read causally consistent snapshots

and updates are applied atomically.

Page 145: Just-Right Consistency: Closing The CAP Gap

Scalability

99

Kops

/ s

100200300400500600700800

1 x 5

1 x 1

01

x 25

2 x 2

53

x 25

1 x 5

1 x 1

01

x 25

2 x 2

53

x 25

1 x 5

1 x 1

01

x 25

2 x 2

53

x 25

1 x 5

1 x 1

01

x 25

2 x 2

53

x 25

99(1) 90(10) 75(25) 50(50)

read(update) ratio

DCs × Servers

LWW registers 100k keys/partitionpower law distribution

Page 146: Just-Right Consistency: Closing The CAP Gap

Cure vs. SOA

100

Kops

/ s

0100200300400500600700800900

10001100

Eige

rGR Cure EC

Eige

rGR Cure EC

Eige

rGR Cure EC

Eige

rGR Cure EC

99(1) 90(10) 75(25) 50(50)

read(update) ratio

3 DCs × 25 ServersLWW registers

Page 147: Just-Right Consistency: Closing The CAP Gap

Cure vs. EC

101

Kops

/ s

100200300400500600700800900

100011001200

Cure

, 1KB

EC, 1

KBCu

re, 1

0KB

EC, 1

0KB

Cure

, 1KB

EC, 1

KBCu

re, 1

0KB

EC, 1

0KB

Cure

, 1KB

EC, 1

KBCu

re, 1

0KB

EC, 1

0KB

Cure

, 1KB

EC, 1

KBCu

re, 1

0KB

EC, 1

0KB

99(1) 90(10) 75(25) 50(50)

read(update) ratio

3 DCs x 25 ServersCRDT sets

Page 148: Just-Right Consistency: Closing The CAP Gap

Future Features• Intra-DC replication

Antidote provides no replication within the datacenter and assumes only geo-replication at the moment

102

Page 149: Just-Right Consistency: Closing The CAP Gap

Future Features• Intra-DC replication

Antidote provides no replication within the datacenter and assumes only geo-replication at the moment

• ACID transactionsFor Antidote to provide all of JRC, it needs ACID transaction support: no research needed, only implementation

102

Page 150: Just-Right Consistency: Closing The CAP Gap

Moving Forward• Research prototype

Originally a research prototype to build a database requiring reduced synchronization (SyncFree FP7) with Basho, Rovio, and Trifork

103

Page 151: Just-Right Consistency: Closing The CAP Gap

Moving Forward• Research prototype

Originally a research prototype to build a database requiring reduced synchronization (SyncFree FP7) with Basho, Rovio, and Trifork

• Research aheadLightKone (H2020) will investigate moving AntidoteDB close to the edge to provide DDN services

103

Page 152: Just-Right Consistency: Closing The CAP Gap

Moving Forward• Research prototype

Originally a research prototype to build a database requiring reduced synchronization (SyncFree FP7) with Basho, Rovio, and Trifork

• Research aheadLightKone (H2020) will investigate moving AntidoteDB close to the edge to provide DDN services

• IndustrializationObtaining seed funding to start a company to industrialize AntidoteDB

103

Page 153: Just-Right Consistency: Closing The CAP Gap

Resources• https://github.com/SyncFree/antidote

AntidoteDB

104

Page 154: Just-Right Consistency: Closing The CAP Gap

Resources• https://github.com/SyncFree/antidote

AntidoteDB

• http://syncfree.github.io/antidote/Documentation for AntidoteDB

104

Page 155: Just-Right Consistency: Closing The CAP Gap

Resources• https://github.com/SyncFree/antidote

AntidoteDB

• http://syncfree.github.io/antidote/Documentation for AntidoteDB

• www.antidotedb.comWebsite

104

Page 156: Just-Right Consistency: Closing The CAP Gap

Resources• https://github.com/SyncFree/antidote

AntidoteDB

• http://syncfree.github.io/antidote/Documentation for AntidoteDB

• www.antidotedb.comWebsite

• docker pull antidotedb/antidoteTry out Antidote!

104

Page 157: Just-Right Consistency: Closing The CAP Gap

Thanks!

105

More questions? Come visit us at the

Evolution bar!