Top Banner
Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters Dr. Jim Webber Chief Scientist, Neo4j
113

Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Apr 29, 2018

Download

Documents

dodan
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Mixing Causal Consistency and

Asynchronous Replication for Large

Neo4j Clusters

Dr. Jim Webber

Chief Scientist, Neo4j

Page 2: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters
Page 3: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters
Page 4: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters
Page 5: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters
Page 6: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Leads to a social graph

Page 7: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Graphs underpin ML to

defeat some cancers

Page 8: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

NASA’s Orion mission to Mars:

2 years shaved from planning schedule

Page 9: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters
Page 10: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters
Page 11: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

MotivationWhy do we need clusters of

Neo4j?

Page 12: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Massive

Throughput

Page 13: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Data Redundancy

Page 14: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Data Redundancy

Page 15: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Data Redundancy

Page 16: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Data Redundancy

Page 17: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

High Availability

Page 18: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

High Availability

Page 19: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

High Availability

Error!

503: Service Unavailable

Page 20: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

High Availability

Error!

503: Service Unavailable

Page 21: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

High Availability

Error!

503: Service Unavailable

Page 22: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

High Availability

Error!

503: Service Unavailable

Page 23: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

High Availability

Error!

503: Service Unavailable

Page 24: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Data RedundancyMassive Throughput High Availability

Page 25: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Data RedundancyMassive Throughput High Availability

3.0

Page 26: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Data RedundancyMassive Throughput High Availability

3.0

Bigger Clusters Consensus CommitBuilt-in load

balancing

3.1Causal

Clustering

Page 27: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

MotivationCan you reason about

consistency?

Page 28: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Register

Login

You need

to login in

to continue

your

purchase!

Page 29: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Register

Login

You need

to login in

to continue

your

purchase!

Username:

Password:

Create Account

Page 30: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Register

Login

You need

to login in

to continue

your

purchase!

Username:

jim_w

Password:

********

Create Account

Page 31: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Register

Login

You need

to login in

to continue

your

purchase!

Username:

Password:

Login

Page 32: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Username:

jim_w

Password:

********

Login

Page 33: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Purchase

Login

Successful

Try again

No account

found!Username:

jim_w

Password:

********

Login

𝙓

Page 34: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters
Page 35: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Three critical issues:Fault Tolerance, Scale, and

Correctness

Page 36: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Design Trade-offAvailability Reliability

Page 37: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Roles for safety and scaleDivide and conquer

complexity

Page 38: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Read

Replicas

Core

Page 39: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

• Small group of Neo4j databases

• Fault-tolerant Consensus Commit

• Responsible for data safety

Core

Page 40: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Writing to the Core Cluster

Neo4j

Driver

Neo4j

Cluster

Page 41: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Writing to the Core Cluster

Neo4j

Driver

CREATE (:User {...})

Neo4j

Cluster

Page 42: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Writing to the Core Cluster

Neo4j

Driver

CREATE (:User {...})

Neo4j

Cluster

Page 43: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Writing to the Core Cluster

Neo4j

Driver

CREATE (:User {...})

Neo4j

Cluster

Page 44: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Writing to the Core Cluster

Neo4j

Driver

CREATE (:User {...})

Neo4j

Cluster

Page 45: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Writing to the Core Cluster

Neo4j

Driver

CREATE (:User {...})

Neo4j

Cluster

Page 46: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Writing to the Core Cluster

Neo4j

Driver

Success

Neo4j

Cluster

Page 47: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Writing to the Core Cluster

Neo4j

Driver

Success

Neo4j

Cluster

Page 48: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Raft ProtocolNon-Blocking Consensus for

Humans

Page 49: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters
Page 50: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Raft Protocol

https://github.com/ongardie/raftscope

Page 51: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Raft in a Nutshell

• Raft keeps logs tied together (geddit?)

• Logs contain entries for both the data and cluster membership

• Entries are appended and subsequently committed if a simple majority agree

• Implication: majority agree with the log as proposed

• Anyone can call an election: highest term (logical clock) wins, followed by

highest committed, followed by highest appended

• Appended but uncommitted entries can be truncated, but this is safe

(transaction aborted)

Page 52: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters
Page 53: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

@heidiann360

Page 54: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Consensus Log → Committed Transactions →

Updated Graph

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10 11 12 13

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

Transaction log: the same

transactions appear in the same

order on all members

Consensus log: stores both

committed and uncommitted

transactions

Uncommitted

entries may

differ

between

members

Tra

nsa

ctio

ns a

re o

nly

ap

pe

nd

ed to

th

e

tra

nsa

ctio

n lo

g w

he

n c

om

mitte

d

acco

rdin

g to

Ra

ft

Tra

nsa

ctio

ns a

re a

pp

lied

, u

pd

ating th

e

gra

ph

Neo4j Raft

implementation

Page 55: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

• Small group of Neo4j databases

• Fault-tolerant Consensus Commit

• Responsible for data safety

Core

Page 56: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

• For massive query throughput

• Read-only replicas• Not involved in Consensus

Commit • Disposable, suitable for

auto-scaling

Read

Replicas

Page 57: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Propagating updates to the Read Replicas

Neo4j

Driver

Neo4j

Cluster

Page 58: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Propagating updates to the Read Replicas

Neo4j

Driver

Neo4j

Cluster

Write

Page 59: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Propagating updates to the Read Replicas

Neo4j

Driver

Neo4j

Cluster

Write

Page 60: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Reading from the Read Replicas

Neo4j

Driver

Neo4j

Cluster

Read

Page 61: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Updating the graph Querying the graph

Page 62: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Read

Replic

as

Cor

e Updating the graph

Queries, analysis,

reporting

Page 63: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

ESTATE=$(neo-workbench estate add database -p Local -b core-block -s 3)

neo-workbench estate add database -p Local -b edge-block -s 10 $ESTATE

neo-workbench database install -m Core \

--package-uri file:///Users/jim/Downloads/neo4j-enterprise-3.1.1-unix.tar.gz \

-b core-block $ESTATE

neo-workbench database install -m Read_Replica \

--package-uri file:///Users/jim/Downloads/neo4j-enterprise-3.1.1-unix.tar.gz \

-b edge-block $ESTATE

neo-workbench database start $ESTATE

Page 64: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Building an AppComputer science meets

software dev

Page 65: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

App

Server

Neo4j

Driver

Bolt

protocol

Page 66: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Java<dependency><groupId>org.neo4j.driver</groupId><artifactId>neo4j-java-driver</artifactId>

</dependency>

Python

pip install neo4j-driver

.NET

PM> Install-Package Neo4j.Driver

JavaScript

npm install neo4j-driver

Page 67: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

https ://neo4j.com/developer/language-guides

Page 68: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

bolt://

GraphDatabase.driver( "bolt://aServer" )

Page 69: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

bolt+routing://

GraphDatabase.driver( "bolt+routing://aCoreServer" )

Page 70: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

GraphDatabase.driver( "bolt+routing://aCoreServer" )

Bootstrap: specify any core server to route load across the whole clus ter

bolt+routing://

Page 71: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Application S erver

Neo4j Driver

Max

J im

J ane

Mark

Page 72: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

R outed write s tatements

driver = GraphDatabase.driver( "bolt+routing://aCoreServer" );

try ( Session session = driver.session( AccessMode.WRITE ) )

{

try ( Transaction tx = session.beginTransaction() )

{

tx.run( "MERGE (user:User {userId: {userId}})",

parameters( "userId", userId ) );

tx.success();

}

}

Page 73: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

R outed read queries

driver = GraphDatabase.driver( "bolt+routing://aCoreServer" );

try ( Session session = driver.session( AccessMode.READ ) )

{

try ( Transaction tx = session.beginTransaction() )

{

tx.run( "MATCH (user:User {userId: {userId}})-[*]-(:Product) RETURN *",

parameters( "userId", userId ) );

tx.success();

}

}

Page 74: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

C ons is tenc y modelsC an you read what you write?

Page 75: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

C luster members s lightly “ahead” or “behind” of each other

0 1 2 3 4 5 6 7 8 9 1011

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

If I query this server I won’t

see the updates from transaction

.

If I query this server, I’ll see all updates from all

committed transactions

11

11

Page 76: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Register

Login

You need

to login in

to continue

your

purchase!

Page 77: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Register

Login

You need

to login in

to continue

your

purchase!

Username:

Password:

Create Account

Page 78: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Register

Login

You need

to login in

to continue

your

purchase!

Username:

jim_w

Password:

********

Create Account

Page 79: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Register

Login

You need

to login in

to continue

your

purchase!

Username:

Password:

Login

Page 80: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Username:

jim_w

Password:

********

Login

Page 81: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters
Page 82: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Purchase

Login

Successful

Try again

No account

found!Username:

jim_w

Password:

********

Login

𝙓

Page 83: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Username:

jim_w

Password:

********

A few moments later...

Login

Page 84: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Purchase

Login

SuccessfulUsername:

jim_w

Password:

********

Login

A few moments later...

Page 85: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Q Why didn’t this work?A E ventual C ons istency

Page 86: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

C reate Account

App S erver

ADriver

Page 87: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

CREATE (:User)

C reate Account

App S erver

ADriver

Page 88: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

CREATE (:User)

C reate Account

App S erver

ADriver

Page 89: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

CREATE (:User)

C reate Account

App S erver

ADriver

11

Page 90: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11CREATE (:User)

C reate Account

App S erver

ADriver

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

11

Page 91: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11CREATE (:User)

C reate Account

App S erver

ADriver

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

11

Page 92: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

CREATE (:User)

C reate Account

App S erver

ADriver

11

Page 93: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

CREATE (:User)

C reate Account

App S erver

ADriver

MATCH (:User)Login

App S erver

BDriver

11

Page 94: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

CREATE (:User)

C reate Account

App S erver

ADriver

MATCH (:User)Login

App S erver

BDriver

11

Page 95: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Bookmark

S ess ion token

S tring (for portability)

Opaque to application

R epresents ultimate user’s most

recent view of the graph

More capabilities to come

Page 96: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

L et’s try again, with C ausal C ons istency

Page 97: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

C reate Account

App S erver

ADriver

Page 98: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

CREATE (:User)

C reate Account

App S erver

ADriver

Page 99: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

CREATE (:User)

C reate Account

App S erver

ADriver

Page 100: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

CREATE (:User)

C reate Account

App S erver

ADriver

11

Page 101: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11CREATE (:User)

C reate Account

App S erver

ADriver

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

11

Page 102: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11CREATE (:User)

C reate Account

App S erver

ADriver

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

11

Page 103: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

CREATE (:User)

C reate Account

App S erver

ADriver

11

Page 104: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9

CREATE (:User)

C reate Account

App S erver

ADriver

MATCH (:User)Login

App S erver

BDriver

11

Page 105: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

CREATE (:User)

C reate Account

MATCH (:User)Login

App S erver

A

App S erver

B

Driver

Driver

Page 106: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

CREATE (:User)

C reate Account

MATCH (:User)Login

App S erver

A

App S erver

B

Driver

Driver

11

Page 107: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

CREATE (:User)

C reate Account

MATCH (:User)Login

App S erver

A

App S erver

B

Driver

Driver

11

Page 108: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

O btain bookmark

try ( Session session = driver.session( AccessMode.WRITE ) )

{

try ( Transaction tx = session.beginTransaction() )

{

tx.run( "CREATE (user:User {userId: {userId}, passwordHash:

{passwordHash})",

parameters( "userId", userId, "passwordHash", passwordHash ) );

tx.success();

}

String bookmark = session.lastBookmark();

}

Page 109: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

CREATE (:User)

C reate Account

MATCH (:User)Login

App S erver

A

App S erver

B

Driver

Driver

11

Obtain bookmark

Page 110: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Use a bookmark

try ( Session session = driver.session( AccessMode.READ ) )

{

try ( Transaction tx = session.beginTransaction( bookmark ) )

{

tx.run( "MATCH (user:User {userId: {userId}}) RETURN *",

parameters( "userId", userId ) );

tx.success();

}

}

Page 111: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10 11

0 1 2 3 4 5 6 7 8 9 10

0 1 2 3 4 5 6 7 8 9 10

CREATE (:User)

C reate Account

MATCH (:User)Login

App S erver

A

App S erver

B

Driver

Driver

11

Use bookmark

Page 112: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Takeaways

• Different roles for safety and scale

• Supports large clusters, multi-DC

• Drivers work with cluster to route to best instances

• All wrapped in causal consistency: your always read (at least) your own writes

Page 113: Mixing Causal Consistency and Asynchronous …yowconference.com.au/slides/yow2017/Webber-MixingCausal...Mixing Causal Consistency and Asynchronous Replication for Large Neo4j Clusters

Thanks for lis tening

Dr. J im WebberChief S cientis t, Neo4j