Top Banner
NoSQL Polyglot Persistence Using Neo4j and MongoDB together William Lyon @lyonwj
97

Polyglot Persistence with MongoDB and Neo4j

Apr 14, 2017

Download

Technology

Corie Brickman
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: Polyglot Persistence with MongoDB and Neo4j

NoSQL Polyglot PersistenceUsing Neo4j and MongoDB together

William Lyon @lyonwj

Page 2: Polyglot Persistence with MongoDB and Neo4j

William LyonDeveloper Relations Engineer @neo4j

[email protected] @lyonwj lyonwj.com

Page 3: Polyglot Persistence with MongoDB and Neo4j

Does Neo4j work with ______ ?

Languages, frameworks, databases…

Page 4: Polyglot Persistence with MongoDB and Neo4j

Does Neo4j work with ______ ?

Languages

Page 5: Polyglot Persistence with MongoDB and Neo4j

Does Neo4j work with ______ ?

Frameworks

Page 6: Polyglot Persistence with MongoDB and Neo4j

Does Neo4j work with ______ ?

Frameworks

Page 7: Polyglot Persistence with MongoDB and Neo4j

Does Neo4j work with ______ ?

Deployment

Page 8: Polyglot Persistence with MongoDB and Neo4j

Does Neo4j work with ______ ?

Databases

Page 9: Polyglot Persistence with MongoDB and Neo4j

Does Neo4j work with ______ ?

Languages, frameworks, databases…

Page 10: Polyglot Persistence with MongoDB and Neo4j

Does Neo4j work with ?

Page 11: Polyglot Persistence with MongoDB and Neo4j

Why?+

Page 12: Polyglot Persistence with MongoDB and Neo4j

MongoDB

Features

• NoSQL database• Document datamodel• JSON-like documents (BSON)• Flexible data model• Horizontal scalability (sharding)• Complex queries

{ "session": { "title": "12 Years of Spring: An Open Source Journey", "abstract": "Spring emerged as a core open source project in early 2003 and evolved to a broad portfolio of open source projects up until 2015." }, "topics": [ "keynote", "spring" ], "room": "Auditorium", "timeslot": "Wed 29th, 09:30-10:30", "speaker": { "name": "Juergen Hoeller", "bio": "Juergen Hoeller is co-founder of the Spring Framework open source project.", "twitter": "https://twitter.com/springjuergen", "picture": "http://www.springio.net/wp-content/uploads/2014/11/juergen_hoeller-220x220.jpeg" }}

Page 13: Polyglot Persistence with MongoDB and Neo4j

MongoDB

Use Cases

• Product catalog• User profiles• Metadata• Content• Events• Analytics

{ "session": { "title": "12 Years of Spring: An Open Source Journey", "abstract": "Spring emerged as a core open source project in early 2003 and evolved to a broad portfolio of open source projects up until 2015." }, "topics": [ "keynote", "spring" ], "room": "Auditorium", "timeslot": "Wed 29th, 09:30-10:30", "speaker": { "name": "Juergen Hoeller", "bio": "Juergen Hoeller is co-founder of the Spring Framework open source project.", "twitter": "https://twitter.com/springjuergen", "picture": "http://www.springio.net/wp-content/uploads/2014/11/juergen_hoeller-220x220.jpeg" }}

https://www.mongodb.com/use-cases/

Page 14: Polyglot Persistence with MongoDB and Neo4j

MongoDB

Use Cases

• Product catalog• User profiles• Metadata• Content• Events• Analytics

{ "session": { "title": "12 Years of Spring: An Open Source Journey", "abstract": "Spring emerged as a core open source project in early 2003 and evolved to a broad portfolio of open source projects up until 2015." }, "topics": [ "keynote", "spring" ], "room": "Auditorium", "timeslot": "Wed 29th, 09:30-10:30", "speaker": { "name": "Juergen Hoeller", "bio": "Juergen Hoeller is co-founder of the Spring Framework open source project.", "twitter": "https://twitter.com/springjuergen", "picture": "http://www.springio.net/wp-content/uploads/2014/11/juergen_hoeller-220x220.jpeg" }}

https://www.mongodb.com/use-cases/

Page 15: Polyglot Persistence with MongoDB and Neo4j

Neo4j

Graph Database

• Property graph data model• Nodes and relationships

• Native graph processing• Cypher query language

Page 16: Polyglot Persistence with MongoDB and Neo4j

Property Graph Model Components

Nodes • The objects in the graph • Can have name-value properties • Can be labeled

Relationships • Relate nodes by type and

direction • Can have name-value properties

CAR

DRIVES

name: “Dan” born: May 29, 1970

twitter: “@dan”name: “Ann”

born: Dec 5, 1975

since: Jan 10, 2011

brand: “Volvo” model: “V70”

LOVES

LOVES

LIVES WITH

OWNS

PERSON PERSON

Page 17: Polyglot Persistence with MongoDB and Neo4j

Cypher: SQL for graphs

CREATE (:Person { name:“Dan”} ) -[:LOVES]-> (:Person { name:“Ann”} )

LOVES

Dan Ann

LABEL PROPERTY

NODE NODE

LABEL PROPERTY

Page 18: Polyglot Persistence with MongoDB and Neo4j

NEO4J USE CASES

Real Time Recommendations

Master Data Management

Fraud Detection

Identity & Access Management

Graph Based Search

Network & IT-Operations

Page 19: Polyglot Persistence with MongoDB and Neo4j

NEO4J USE CASES

Real Time Recommendations

Master Data Management

Fraud Detection

Identity & Access Management

Graph Based Search

Network & IT-Operations

GRAPH THINKING: Real Time Recommendations

VIEW

ED

VIEWED

BOUG

HT

VIEWED BOUGHT

BOUGHT

BO

UG

HT

BOUG

HT

Page 20: Polyglot Persistence with MongoDB and Neo4j

NEO4J USE CASES

Real Time Recommendations

Master Data Management

Fraud Detection

Identity & Access Management

Graph Based Search

Network & IT-Operations

GRAPH THINKING: Master Data Management

MANAGES

MANAGES

LEADS

REGION

MANAGES

MANAGES

REGION

LEADS

LEADS

COLL

ABO

RATE

S

Page 21: Polyglot Persistence with MongoDB and Neo4j

NEO4J USE CASES

Real Time Recommendations

Master Data Management

Fraud Detection

Identity & Access Management

Graph Based Search

Network & IT-Operations

GRAPH THINKING: Fraud Detection

OPENED_ACCOUNT

HAS IS_ISSUED

HAS

LIVES LIVES

IS_ISSUED

OPE

NED_

ACCO

UNT

Page 22: Polyglot Persistence with MongoDB and Neo4j

GRAPH THINKING: Graph Based Search

NEO4J USE CASES

Real Time Recommendations

Master Data Management

Fraud Detection

Identity & Access Management

Graph Based Search

Network & IT-Operations

PUBLISH

INCLUDE

INCLUDE

CREATE

CAPT

URE

IN

INSO

URCE

USES

USES

IN

IN

USES

SOURCE SOURCE

Page 23: Polyglot Persistence with MongoDB and Neo4j

NEO4J USE CASES

Real Time Recommendations

Master Data Management

Fraud Detection

Identity & Access Management

Graph Based Search

Network & IT-Operations

BROWSESCO

NNEC

TS

BRIDGES

ROUTES

POW

ERSROUTES

POWERSPOWERS

HOSTS

QUERIES

GRAPH THINKING: Network & IT-Operations

Page 24: Polyglot Persistence with MongoDB and Neo4j

GRAPH THINKING: Identity And Access Management

NEO4J USE CASES

Real Time Recommendations

Master Data Management

Fraud Detection

Identity & Access Management

Graph Based Search

Network & IT-Operations

TRUSTS

TRUSTS

ID

ID

AUTHENTICATES

AUTH

ENTI

CATE

S

OWNS

OWNSC

AN

_REA

D

Page 25: Polyglot Persistence with MongoDB and Neo4j
Page 26: Polyglot Persistence with MongoDB and Neo4j

Why?+

Page 27: Polyglot Persistence with MongoDB and Neo4j

The Traditional Approach Towards Data

Page 28: Polyglot Persistence with MongoDB and Neo4j

SYSTEMS OF RECORD

Page 29: Polyglot Persistence with MongoDB and Neo4j

RDBMS

SYSTEMS OF RECORD

Page 30: Polyglot Persistence with MongoDB and Neo4j

HR-tools Supply Payments Logistics CRM Support

TRADITIONAL DATA STRUCTURE

RDBMS RDBMS RDBMSRDBMS RDBMS RDBMS

Page 31: Polyglot Persistence with MongoDB and Neo4j

SHIFT TOWARDS SYSTEMS OF ENGAGEMENT

Page 32: Polyglot Persistence with MongoDB and Neo4j

Users Engaging With DevicesUsers Engaging With Users Devices Engaging With Devices

SYSTEMS OF ENGAGEMENT

Page 33: Polyglot Persistence with MongoDB and Neo4j

SHIFT TOWARDS SYSTEMS OF ENGAGEMENT

You are here!

Data volume

Page 34: Polyglot Persistence with MongoDB and Neo4j

SYSTEMS OF RECORDRelational Database Model

StructuredPre-computed

Based on rigid rules

SYSTEMS OF ENGAGEMENTNoSQL Database Model

Highly FlexibleReal-Time QueriesHighly Contextual

Page 35: Polyglot Persistence with MongoDB and Neo4j

http://bigdata-blog.com/nosql-definition

Page 36: Polyglot Persistence with MongoDB and Neo4j
Page 37: Polyglot Persistence with MongoDB and Neo4j

Polyglot Persistence

Page 38: Polyglot Persistence with MongoDB and Neo4j

Polyglot Persistence

• Different types of data in different ways• Take advantage of strengths of different databases

http://martinfowler.com/bliki/PolyglotPersistence.html

Page 39: Polyglot Persistence with MongoDB and Neo4j

Polyglot Persistence

Functionality Database type

Shopping Cart Rapid session reads / writes

Key-value store

Orders / Product Catalog

Frequent reads Document

Customer social graph

Recommendation Graph

http://www.jamesserra.com/archive/2015/07/what-is-polyglot-persistence/

Page 40: Polyglot Persistence with MongoDB and Neo4j

DataStorageandBusinessRulesExecu5on

DataMiningandAggrega5on

Applica'on

GraphDatabaseCluster

Neo4j Neo4j Neo4j

AdHocAnalysis

BulkAnaly'cInfrastructureHadoop,EDW…

DataScien'st

EndUser

DatabasesRela5onalNoSQLHadoop

Page 41: Polyglot Persistence with MongoDB and Neo4j

Added Complexity

Page 42: Polyglot Persistence with MongoDB and Neo4j

Challenge #1: Data Sync

Page 43: Polyglot Persistence with MongoDB and Neo4j

MIGRATEALLDATA

MIGRATESUBSET

DUPLICATESUBSET

Non-GraphQueries GraphQueries

GraphQueriesNon-GraphQueries

AllQueries

Rela3onalDatabase

GraphDatabase

Application

Application

Application

NonGraphData

AllData

?

Page 44: Polyglot Persistence with MongoDB and Neo4j
Page 45: Polyglot Persistence with MongoDB and Neo4j
Page 46: Polyglot Persistence with MongoDB and Neo4j

Course CatalogBrowse & Search

• Good use-case for a document database

Page 47: Polyglot Persistence with MongoDB and Neo4j
Page 48: Polyglot Persistence with MongoDB and Neo4j

https://github.com/johnymontana/CourseCatalog

Page 49: Polyglot Persistence with MongoDB and Neo4j

Course CatalogBrowse & Search

• Good use-case for a document database

Page 50: Polyglot Persistence with MongoDB and Neo4j
Page 51: Polyglot Persistence with MongoDB and Neo4j
Page 52: Polyglot Persistence with MongoDB and Neo4j

Graph Based Recommendations

Page 53: Polyglot Persistence with MongoDB and Neo4j

Graph Based Recommendations

Page 54: Polyglot Persistence with MongoDB and Neo4j

Graph Based Recommendations

Page 55: Polyglot Persistence with MongoDB and Neo4j
Page 56: Polyglot Persistence with MongoDB and Neo4j

?

Page 57: Polyglot Persistence with MongoDB and Neo4j

Option 1: APOC Procedures

Page 58: Polyglot Persistence with MongoDB and Neo4j

https://github.com/neo4j-contrib/neo4j-apoc-procedures

Page 59: Polyglot Persistence with MongoDB and Neo4j

Java Stored Procedures

User-defined procedures are written in Java, deployed into the database, and called from Cypher.

http://neo4j.com/docs/developer-manual/current/#procedures

Page 60: Polyglot Persistence with MongoDB and Neo4j

Built-in Procedures

Page 61: Polyglot Persistence with MongoDB and Neo4j

Built-in Procedures

Page 62: Polyglot Persistence with MongoDB and Neo4j

User-defined Procedures

https://github.com/neo4j-examples/neo4j-procedure-template

Page 63: Polyglot Persistence with MongoDB and Neo4j

Apoc Procedures

https://github.com/neo4j-contrib/neo4j-apoc-procedures

Page 64: Polyglot Persistence with MongoDB and Neo4j

THERE’S A PROCEDURE FOR THAT

https://github.com/neo4j-contrib/neo4j-apoc-procedures

Page 65: Polyglot Persistence with MongoDB and Neo4j

https://github.com/neo4j-contrib/neo4j-apoc-procedures/blob/master/readme.adoc

Page 66: Polyglot Persistence with MongoDB and Neo4j

https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_loading_data_from_web_apis_json_xml_csv

Page 67: Polyglot Persistence with MongoDB and Neo4j

?

Page 68: Polyglot Persistence with MongoDB and Neo4j

https://docs.mongodb.com/ecosystem/tools/http-interfaces/

Page 69: Polyglot Persistence with MongoDB and Neo4j
Page 70: Polyglot Persistence with MongoDB and Neo4j
Page 71: Polyglot Persistence with MongoDB and Neo4j
Page 72: Polyglot Persistence with MongoDB and Neo4j
Page 73: Polyglot Persistence with MongoDB and Neo4j
Page 74: Polyglot Persistence with MongoDB and Neo4j
Page 75: Polyglot Persistence with MongoDB and Neo4j

Option 2: Neo4j Doc Manager

Page 76: Polyglot Persistence with MongoDB and Neo4j

Neo4j Doc Manager

•Automatically sync documents from MongoDB to Neo4j•Convert documents into graph model

http://neo4j.com/developer/mongodb/

Page 77: Polyglot Persistence with MongoDB and Neo4j

Neo4j Doc ManagerAutomatically sync documents from MongoDB to Neo4j

Page 78: Polyglot Persistence with MongoDB and Neo4j

Document to property graph{ "session": { "title": "12 Years of Spring: An Open Source Journey", "abstract": "Spring emerged as a core open source project in early 2003 and evolved to a broad portfolio of open source projects up until 2015." }, "topics": [ "keynote", "spring" ], "room": "Auditorium", "timeslot": "Wed 29th, 09:30-10:30", "speaker": { "name": "Juergen Hoeller", "bio": "Juergen Hoeller is co-founder of the Spring Framework open source project.", "twitter": "https://twitter.com/springjuergen", "picture": "http://www.springio.net/wp-content/uploads/2014/11/juergen_hoeller-220x220.jpeg" }}

Page 79: Polyglot Persistence with MongoDB and Neo4j

{ "session": { "title": "12 Years of Spring: An Open Source Journey", "abstract": "Spring emerged as a core open source project in early 2003 and evolved to a broad portfolio of open source projects up until 2015." }, "topics": [ "keynote", "spring" ], "room": "Auditorium", "timeslot": "Wed 29th, 09:30-10:30", "speaker": { "name": "Juergen Hoeller", "bio": "Juergen Hoeller is co-founder of the Spring Framework open source project.", "twitter": "https://twitter.com/springjuergen", "picture": "http://www.springio.net/wp-content/uploads/2014/11/juergen_hoeller-220x220.jpeg" }}

Document to property graph

Page 80: Polyglot Persistence with MongoDB and Neo4j

https://github.com/neo4j-contrib/neo4j_doc_manager

Page 81: Polyglot Persistence with MongoDB and Neo4j

Demo

Page 82: Polyglot Persistence with MongoDB and Neo4j

Using Data Relationships for Recommendations

Content-based filtering Recommend items based on what users have liked in the past

Collaborative filtering Predict what users like based on the similarity of their behaviors, activities and preferences to others

Movie

Person

Person

RATED

SIMILARITY

rating: 7

value: .92

Page 83: Polyglot Persistence with MongoDB and Neo4j
Page 84: Polyglot Persistence with MongoDB and Neo4j
Page 85: Polyglot Persistence with MongoDB and Neo4j
Page 86: Polyglot Persistence with MongoDB and Neo4j
Page 87: Polyglot Persistence with MongoDB and Neo4j

Challenge #2: Operations

Page 88: Polyglot Persistence with MongoDB and Neo4j

http://neo4j.com/developer/docker/

Page 89: Polyglot Persistence with MongoDB and Neo4j

https://hub.docker.com/_/neo4j/

docker pull neo4j

Official Neo4j Docker Image

Page 90: Polyglot Persistence with MongoDB and Neo4j

https://www.docker.com/products/docker-compose

Page 91: Polyglot Persistence with MongoDB and Neo4j

docker-compose.yml

Page 92: Polyglot Persistence with MongoDB and Neo4j
Page 93: Polyglot Persistence with MongoDB and Neo4j

Resources

Page 94: Polyglot Persistence with MongoDB and Neo4j

http://neo4j.com/blog/couchbase-jdbc-integrations-neo4j-3-0/

Couchbase + Neo4j integration

Page 95: Polyglot Persistence with MongoDB and Neo4j

http://neo4j.com/developer/

Neo4j Developer Resources

Page 96: Polyglot Persistence with MongoDB and Neo4j

Neo4j Integrations http://neo4j.com/developer/integration/

Neo4j + MongoDB http://neo4j.com/developer/mongodb/

Neo4j Doc Manager https://github.com/neo4j-contrib/neo4j_doc_manager