Causal Consistency For Large Neo4j Clusters Jim Webber Chief - - PowerPoint PPT Presentation

causal consistency for large neo4j clusters
SMART_READER_LITE
LIVE PREVIEW

Causal Consistency For Large Neo4j Clusters Jim Webber Chief - - PowerPoint PPT Presentation

Causal Consistency For Large Neo4j Clusters Jim Webber Chief Scientist, Neo4j QCon London Leads to a social graph Motivation Why do we need clusters of Neo4j? Massive Throughput Data Redundancy Data Redundancy Data Redundancy Data


slide-1
SLIDE 1

Causal Consistency For Large Neo4j Clusters

Jim Webber Chief Scientist, Neo4j QCon London

slide-2
SLIDE 2
slide-3
SLIDE 3
slide-4
SLIDE 4
slide-5
SLIDE 5
slide-6
SLIDE 6

Leads to a social graph

slide-7
SLIDE 7
slide-8
SLIDE 8

Motivation

Why do we need clusters of Neo4j?

slide-9
SLIDE 9

Massive Throughput

slide-10
SLIDE 10

Data Redundancy

slide-11
SLIDE 11

Data Redundancy

slide-12
SLIDE 12

Data Redundancy

slide-13
SLIDE 13

Data Redundancy

slide-14
SLIDE 14

High Availability

slide-15
SLIDE 15

High Availability

slide-16
SLIDE 16

High Availability

Error! 503: Service Unavailable

slide-17
SLIDE 17

High Availability

Error! 503: Service Unavailable

slide-18
SLIDE 18

High Availability

Error! 503: Service Unavailable

slide-19
SLIDE 19

High Availability

Error! 503: Service Unavailable

slide-20
SLIDE 20

High Availability

Error! 503: Service Unavailable

slide-21
SLIDE 21

Data Redundancy Massive Throughput High Availability

slide-22
SLIDE 22

Data Redundancy Massive Throughput High Availability

3.0

slide-23
SLIDE 23

Data Redundancy Massive Throughput High Availability

3.0

Bigger Clusters Consensus Commit Built-in load balancing

3.1

Causal Clustering

slide-24
SLIDE 24

Roles for safety and scale

Divide and conquer complexity

slide-25
SLIDE 25

Read Replicas Core

slide-26
SLIDE 26
  • Small group of Neo4j databases
  • Fault-tolerant Consensus Commit
  • Responsible for data safety

Core

slide-27
SLIDE 27

Writing to the Core Cluster

Neo4j Driver Neo4j Cluster

slide-28
SLIDE 28

Writing to the Core Cluster

Neo4j Driver

CREATE (:User {...})

Neo4j Cluster

slide-29
SLIDE 29

Writing to the Core Cluster

Neo4j Driver

CREATE (:User {...})

Neo4j Cluster

slide-30
SLIDE 30

Writing to the Core Cluster

Neo4j Driver

CREATE (:User {...})

✓ ✓ ✓

Neo4j Cluster

slide-31
SLIDE 31

Writing to the Core Cluster

Neo4j Driver

CREATE (:User {...})

✓ ✓ ✓

Neo4j Cluster

slide-32
SLIDE 32

Writing to the Core Cluster

Neo4j Driver

CREATE (:User {...})

✓ ✓ ✓

Neo4j Cluster

slide-33
SLIDE 33

Writing to the Core Cluster

Neo4j Driver

✓ ✓ ✓

Success Neo4j Cluster

slide-34
SLIDE 34

Writing to the Core Cluster

Neo4j Driver

✓ ✓ ✓

Success Neo4j Cluster

✓ ✓

slide-35
SLIDE 35

Raft Protocol

Non-Blocking Consensus for Humans

slide-36
SLIDE 36
slide-37
SLIDE 37

Raft Protocol

https://github.com/ongardie/raftscope

slide-38
SLIDE 38

Raft in a Nutshell

  • Raft keeps logs tied together (geddit?)
  • Logs contain entries for both the database and the 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 not committed, entries can be truncated, but this is safe (translates as transaction

aborted)

https://github.com/ongardie/raftscope

slide-39
SLIDE 39

Consensus Log → Committed Transactions → Updated Graph

1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 5 6 7 8 9 10 11 12 13 1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 5 6 7 8 9 10 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

Transactions are only appended to the transaction log when committed according to Raft Transactions are applied, updating the graph

Neo4j Raft implementation

slide-40
SLIDE 40
  • Small group of Neo4j databases
  • Fault-tolerant Consensus Commit
  • Responsible for data safety

Core

slide-41
SLIDE 41
  • For massive query throughput
  • Read-only replicas
  • Not involved in Consensus Commit
  • Disposable, suitable for auto-scaling

Read Replicas

slide-42
SLIDE 42

Propagating updates to the Read Replicas

Neo4j Driver Neo4j Cluster

slide-43
SLIDE 43

Propagating updates to the Read Replicas

Neo4j Driver Neo4j Cluster Write

slide-44
SLIDE 44

Propagating updates to the Read Replicas

Neo4j Driver Neo4j Cluster Write

slide-45
SLIDE 45

Reading from the Read Replicas

Neo4j Driver Neo4j Cluster Read

slide-46
SLIDE 46

Updating the graph Querying the graph

slide-47
SLIDE 47

Read Replicas Core

Updating the graph Queries, analysis, reporting

slide-48
SLIDE 48

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

slide-49
SLIDE 49

:sysinfo

slide-50
SLIDE 50

Building an App

Computer science meets technology

slide-51
SLIDE 51

App Server Neo4j Driver Bolt protocol

slide-52
SLIDE 52

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

slide-53
SLIDE 53

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

slide-54
SLIDE 54

bolt://

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

slide-55
SLIDE 55

bolt+routing://

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

slide-56
SLIDE 56

GraphDatabase.driver( "bolt+routing://aCoreServer" ) Bootstrap: specify any core server to route load across the whole cluster

bolt+routing://

slide-57
SLIDE 57

Application Server Neo4j Driver

Max Jim Jane Mark

slide-58
SLIDE 58

Routed write statements

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(); } }

slide-59
SLIDE 59

Routed 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(); } }

slide-60
SLIDE 60

Consistency models

Can you read what you write?

slide-61
SLIDE 61

Cluster members slightly “ahead” or “behind” of each other

1 2 3 4 5 6 7 8 9 10

11

1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 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

slide-62
SLIDE 62

Updating the graph Querying the graph

slide-63
SLIDE 63

Register Login

You need to login in to continue your purchase!

slide-64
SLIDE 64

Register Login

You need to login in to continue your purchase!

Username: Password:

Create Account

slide-65
SLIDE 65

Register Login

You need to login in to continue your purchase!

Username:

jim_w

Password:

********

Create Account

slide-66
SLIDE 66

Register Login

You need to login in to continue your purchase!

Username: Password:

Login

slide-67
SLIDE 67

Username:

jim_w

Password:

********

Login

slide-68
SLIDE 68

Purchase

Login Successful

Try again

No account found!

Username:

jim_w

Password:

********

Login

𝙔

slide-69
SLIDE 69

Username:

jim_w

Password:

********

A few moments later...

Login

slide-70
SLIDE 70

Purchase

Login Successful

Username:

jim_w

Password:

********

Login

A few moments later...

slide-71
SLIDE 71

Q Why didn’t this work? A Eventual Consistency

slide-72
SLIDE 72

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

Create Account

App Server A Driver

slide-73
SLIDE 73

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

CREATE (:User)

Create Account

App Server A Driver

slide-74
SLIDE 74

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

CREATE (:User)

Create Account

App Server A Driver

slide-75
SLIDE 75

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

CREATE (:User)

Create Account

App Server A Driver

11

slide-76
SLIDE 76

1 2 3 4 5 6 7 8 9 10 11

CREATE (:User)

Create Account

App Server A Driver

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

slide-77
SLIDE 77

1 2 3 4 5 6 7 8 9 10 11

CREATE (:User)

Create Account

App Server A Driver

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

slide-78
SLIDE 78

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

CREATE (:User)

Create Account

App Server A Driver

11

slide-79
SLIDE 79

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

CREATE (:User)

Create Account

App Server A Driver

MATCH (:User)

Login

App Server B Driver

11

slide-80
SLIDE 80

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

CREATE (:User)

Create Account

App Server A Driver

MATCH (:User)

Login

App Server B Driver

11

slide-81
SLIDE 81

Bookmark

Session token String (for portability) Opaque to application Represents ultimate user’s most recent view

  • f the graph

More capabilities to come

slide-82
SLIDE 82

Let’s try again, with Causal Consistency

slide-83
SLIDE 83

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

Create Account

App Server A Driver

slide-84
SLIDE 84

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

CREATE (:User)

Create Account

App Server A Driver

slide-85
SLIDE 85

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

CREATE (:User)

Create Account

App Server A Driver

slide-86
SLIDE 86

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

CREATE (:User)

Create Account

App Server A Driver

11

slide-87
SLIDE 87

1 2 3 4 5 6 7 8 9 10 11

CREATE (:User)

Create Account

App Server A Driver

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

slide-88
SLIDE 88

1 2 3 4 5 6 7 8 9 10 11

CREATE (:User)

Create Account

App Server A Driver

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

slide-89
SLIDE 89

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

CREATE (:User)

Create Account

App Server A Driver

11

slide-90
SLIDE 90

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

CREATE (:User)

Create Account

App Server A Driver

MATCH (:User)

Login

App Server B Driver

11

slide-91
SLIDE 91

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

CREATE (:User)

Create Account

MATCH (:User)

Login

App Server A App Server B Driver Driver

slide-92
SLIDE 92

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

CREATE (:User)

Create Account

MATCH (:User)

Login

App Server A App Server B Driver Driver

11

slide-93
SLIDE 93

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

CREATE (:User)

Create Account

MATCH (:User)

Login

App Server A App Server B Driver Driver

11

slide-94
SLIDE 94

Obtain 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(); }

slide-95
SLIDE 95

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

CREATE (:User)

Create Account

MATCH (:User)

Login

App Server A App Server B Driver Driver

11

Obtain bookmark

slide-96
SLIDE 96

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(); } }

slide-97
SLIDE 97

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

CREATE (:User)

Create Account

MATCH (:User)

Login

App Server A App Server B Driver Driver

11

Use bookmark

slide-98
SLIDE 98

Read Replicas Core

Updating the graph Queries, analysis, reporting

slide-99
SLIDE 99

Thank you for listening

@jimwebber