causal consistency for large neo4j clusters
play

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


  1. Causal Consistency For Large Neo4j Clusters Jim Webber Chief Scientist, Neo4j QCon London

  2. Leads to a social graph

  3. Motivation Why do we need clusters of Neo4j?

  4. Massive Throughput

  5. Data Redundancy

  6. Data Redundancy

  7. Data Redundancy

  8. Data Redundancy

  9. High Availability

  10. High Availability

  11. High Availability Error! 503: Service Unavailable

  12. High Availability Error! 503: Service Unavailable

  13. High Availability Error! 503: Service Unavailable

  14. High Availability Error! 503: Service Unavailable

  15. High Availability Error! 503: Service Unavailable ✓

  16. Massive Throughput Data Redundancy High Availability

  17. 3.0 Massive Throughput Data Redundancy High Availability

  18. 3.1 Causal Clustering Bigger Clusters Consensus Commit Built-in load balancing 3.0 Massive Throughput Data Redundancy High Availability

  19. Roles for safety and scale Divide and conquer complexity

  20. Core Read Replicas

  21. Core • Small group of Neo4j databases • Fault-tolerant Consensus Commit • Responsible for data safety

  22. Writing to the Core Cluster Neo4j Cluster Neo4j Driver

  23. Writing to the Core Cluster Neo4j Cluster Neo4j Driver CREATE (:User {...}) ✓

  24. Writing to the Core Cluster Neo4j Cluster Neo4j Driver CREATE (:User {...}) ✓

  25. Writing to the Core Cluster Neo4j Cluster Neo4j Driver ✓ CREATE (:User {...}) ✓ ✓

  26. Writing to the Core Cluster Neo4j Cluster Neo4j Driver ✓ CREATE (:User {...}) ✓ ✓

  27. Writing to the Core Cluster Neo4j Cluster Neo4j Driver ✓ CREATE (:User {...}) ✓ ✓

  28. Writing to the Core Cluster Neo4j Cluster Neo4j Driver ✓ ✓ Success ✓

  29. Writing to the Core Cluster Neo4j Cluster Neo4j Driver ✓ ✓ ✓ Success ✓ ✓

  30. Raft Protocol Non-Blocking Consensus for Humans

  31. Raft Protocol https://github.com/ongardie/raftscope

  32. 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

  33. Consensus Log → Committed Transactions → Updated Graph Neo4j Raft implementation 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Transactions are only appended to the transaction 0 1 2 3 4 5 6 7 8 9 10 11 Transactions are applied, updating the graph log when committed according to Raft 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 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 Uncommitted entries may differ between 0 1 2 3 4 5 6 7 8 9 10 11 0 1 2 3 4 5 6 7 8 9 10 members Consensus log: stores both committed and Transaction log: the same transactions appear uncommitted transactions in the same order on all members

  34. Core • Small group of Neo4j databases • Fault-tolerant Consensus Commit • Responsible for data safety

  35. Read Replicas • For massive query throughput • Read-only replicas • Not involved in Consensus Commit • Disposable, suitable for auto-scaling

  36. Propagating updates to the Read Replicas Neo4j Cluster Neo4j Driver

  37. Propagating updates to the Read Replicas Neo4j Cluster Neo4j Driver Write

  38. Propagating updates to the Read Replicas Neo4j Cluster Neo4j Driver Write

  39. Reading from the Read Replicas Neo4j Cluster Neo4j Driver Read

  40. Updating the graph Querying the graph

  41. Core Updating the graph Read Queries, analysis, reporting Replicas

  42. 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

  43. :sysinfo

  44. Building an App Computer science meets technology

  45. App Neo4j Server Driver Bolt protocol

  46. Java Python <dependency> <groupId> org.neo4j.driver </groupId> pip install neo4j-driver <artifactId> neo4j-java-driver </artifactId> </dependency> .NET JavaScript PM> Install-Package Neo4j.Driver npm install neo4j-driver

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

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

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

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

  51. Application Neo4j Server Driver Max Jim Jane Mark

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

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

  54. Consistency models Can you read what you write?

  55. Cluster members slightly “ahead” or “behind” of each other If I query this server, 11 I’ll see all updates 0 1 2 3 4 5 6 7 8 9 10 from all committed transactions 0 1 2 3 4 5 6 7 8 9 10 11 0 1 2 3 4 5 6 7 8 9 10 If I query this server I 0 1 2 3 4 5 6 7 8 9 10 won’t see the updates from transaction . 11 0 1 2 3 4 5 6 7 8 9 10

  56. Updating the graph Querying the graph

  57. You need to login in to continue your purchase! Login Register

  58. You need to login in Username: to continue your Password: purchase! Login Register Create Account

  59. You need to login in Username: jim_w to continue your Password: purchase! ******** Login Register Create Account

  60. You need to login in Username: to continue your Password: purchase! Login Register Login

  61. Username: jim_w Password: ******** Login

  62. No account Login Username: Successful found! jim_w 𝙔 Password: ******** Login Purchase Try again

  63. A few moments later... Username: jim_w ✓ Password: ******** Login

  64. A few moments later... Login Username: Successful jim_w ✓ Password: ******** Login Purchase

  65. Q Why didn’t this work? A Eventual Consistency

  66. App Server A Driver Create Account 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

  67. App Server A Driver Create Account CREATE (:User) 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

  68. App Server A Driver Create Account CREATE (:User) 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

  69. App Server A Driver Create Account CREATE (:User) 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 11 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9

  70. App Server A Driver Create Account CREATE (:User) 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 11 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9

  71. App Server A Driver Create Account CREATE (:User) 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 11 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9

  72. App Server A Driver Create Account CREATE (:User) 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

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend