intro to neo4j and graph databases

117
Intro to Neo4j and Graph Databases Neo4j Webinar March 2016

Upload: neo4j-the-fastest-and-most-scalable-native-graph-database

Post on 15-Apr-2017

1.508 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Intro to Neo4j and Graph Databases

Intro to Neo4j and Graph Databases

Neo4j Webinar March 2016

Page 2: Intro to Neo4j and Graph Databases

ABOUT ME

• William Lyon • Developer Relations Engineer @neo4j • http://neo4j.com/developer

[email protected] @lyonwj

Page 3: Intro to Neo4j and Graph Databases

Agenda

• What is a graph [database]? • Use cases - why graphs? • Neo4j product overview

• Labeled property graph data model • Cypher query language

• RDBMS to graph • Resources • Questions?

Page 4: Intro to Neo4j and Graph Databases

Chart

Page 5: Intro to Neo4j and Graph Databases

Chart Graph

Page 6: Intro to Neo4j and Graph Databases

A Graph Is Connected Data

Page 7: Intro to Neo4j and Graph Databases

ROAD

TRAFFIC

LIGHTS

A Graph Is Connected Data

Page 8: Intro to Neo4j and Graph Databases

HA

S

AVAILABLE

A Graph Is Connected Data

HOTEL

ROOMS

AVAILABLE

Page 9: Intro to Neo4j and Graph Databases

KNOWS

KN

OW

S

KNOWS

WO

RK

S_AT

WORKS_AT

WORKS_AT

COMPANY

STANFORD

STU

DIE

D_A

T

KNOWS

NEO

COLUMBIA

A Graph Is Connected Data

STU

DIE

D_A

T

STUDIED_AT

STUDIED_AT

Page 10: Intro to Neo4j and Graph Databases

A Graph Is Connected Data

Page 11: Intro to Neo4j and Graph Databases
Page 12: Intro to Neo4j and Graph Databases

Use of Graphs has created some of the most successful companies in the world

C34,3%B

38,4%A3,3%

D3,8%

1,8%1,8% 1,8%

1,8%

1,8%

E8,1%

F3,9%

Page 13: Intro to Neo4j and Graph Databases

Finance Social networks RetailHR & Recruiting

Manufacturing & Logistics

Health Care Telco

Today we see graph-projects in virtually every industry

Page 14: Intro to Neo4j and Graph Databases
Page 15: Intro to Neo4j and Graph Databases

NEO4j USE CASESReal Time Recommendations

Master Data Management

Fraud Detection

Identity & Access Management

Graph Based Search

Network & IT-Operations

Page 16: Intro to Neo4j and Graph Databases

NEO4j USE CASESReal 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 17: Intro to Neo4j and Graph Databases

“As the current market leader in graph databases, and with enterprise features for scalability and availability, Neo4j is the right choice to meet our demands.” Marcos Wada

Software Developer, Walmart

NEO4j USE CASESReal Time Recommendations

Master Data Management

Fraud Detection

Identity & Access Management

Graph Based Search

Network & IT-Operations

Page 18: Intro to Neo4j and Graph Databases

NEO4j USE CASESReal 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 19: Intro to Neo4j and Graph Databases

Neo4j is the heart of Cisco HMP: used for governance and single source of truth and a one-stop shop for all of Cisco’s hierarchies.

NEO4j USE CASESReal Time Recommendations

Master Data Management

Fraud Detection

Identity & Access Management

Graph Based Search

Network & IT-Operations

Page 20: Intro to Neo4j and Graph Databases

NEO4j USE CASESReal 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 21: Intro to Neo4j and Graph Databases

“Graph databases offer new methods of uncovering fraud rings and other sophisticated scams with a high-level of accuracy, and are capable of stopping advanced fraud scenarios in real-time.”

Gorka SadowskiCyber Security Expert

NEO4j USE CASESReal Time Recommendations

Master Data Management

Fraud Detection

Identity & Access Management

Graph Based Search

Network & IT-Operations

Page 22: Intro to Neo4j and Graph Databases

GRAPH THINKING: Graph Based Search

NEO4j USE CASESReal 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: Intro to Neo4j and Graph Databases

Uses Neo4j to manage the digital assets inside of its next generation in-flight entertainment system.

NEO4j USE CASESReal Time Recommendations

Master Data Management

Fraud Detection

Identity & Access Management

Graph Based Search

Network & IT-Operations

Page 24: Intro to Neo4j and Graph Databases

NEO4j USE CASESReal 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 25: Intro to Neo4j and Graph Databases

Uses Neo4j for network topology analysis for big telco service providers

NEO4j USE CASESReal Time Recommendations

Master Data Management

Fraud Detection

Identity & Access Management

Graph Based Search

Network & IT-Operations

Page 26: Intro to Neo4j and Graph Databases

GRAPH THINKING: Identity And Access Management

NEO4j USE CASESReal 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 27: Intro to Neo4j and Graph Databases

A way of representing data

DATA DATA

Page 28: Intro to Neo4j and Graph Databases

Relational Database

A way of representing data

Page 29: Intro to Neo4j and Graph Databases

Graph DatabaseRelational Database

A way of representing data

Good for:

• Well-understood data structures that don’t change too frequently

• Known problems involving discrete parts of the data, or minimal connectivity

Good for:

• Dynamic systems: where the data topology is difficult to predict

• Dynamic requirements: the evolve with the business

• Problems where the relationships in data contribute meaning & value

Page 30: Intro to Neo4j and Graph Databases

THE PROPERTY GRAPH DATA MODEL

Page 31: Intro to Neo4j and Graph Databases

Ann DanLoves

Ann Loves Dan

Page 32: Intro to Neo4j and Graph Databases

Ann Loves Dan

LOVES

RELATIONSHIPNODE NODE

Page 33: Intro to Neo4j and Graph Databases

Relationships are Directional

LOVES

LOVES

RELATIONSHIPSNODE NODE

Page 34: Intro to Neo4j and Graph Databases

Detailed Property Graph

name: “Ann” born: May 29, 1970

twitter: “@ann”

name: “Dan” born: Dec 5, 1975

brand: “Volvo” model: “V70”

LOVES

LOVES

LIVES WITH

OWNS

DRIVES DRIVESsince: Jan 10, 2011 since: Jan 10, 2011

Page 35: Intro to Neo4j and Graph Databases

OWNS

name: “Ann” born: May 29, 1970

twitter: “@ann”

name: “Dan” born: Dec 5, 1975

brand: “Volvo” model: “V70”

LOVES

LOVES

LIVES WITH

DRIVES DRIVESsince: Jan 10, 2011 since: Jan 10, 2011

:Person :Person

:Car

:Vehicle

Labeled Property Graph

Page 36: Intro to Neo4j and Graph Databases

Mapping to Languages

VERB

VERB

VERB

VERB

VERB VERBadverb adverb

:Noun :Noun

:Noun

adjective adjective adjective

adjective adjective

adjective adjective

Page 37: Intro to Neo4j and Graph Databases

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 38: Intro to Neo4j and Graph Databases

WHY GRAPHS?

Page 39: Intro to Neo4j and Graph Databases

IntuitivnessSpeedAgility

Page 40: Intro to Neo4j and Graph Databases

IntuitivenessSpeedAgility

Page 41: Intro to Neo4j and Graph Databases

Intuitiveness

Page 42: Intro to Neo4j and Graph Databases

IntuitivnessSpeedAgility

Page 43: Intro to Neo4j and Graph Databases

Relational Versus Graph Models

Relational Model Graph Model

KNOWS

KNOWS

KNOWS

ANDREAS

TOBIAS

MICA

DELIA

Person FriendPerson-Friend

ANDREASDELIA

TOBIAS

MICA

Index free adjacency

Page 44: Intro to Neo4j and Graph Databases

Speed

“We found Neo4j to be literally thousands of times faster than our prior MySQL solution, with queries that require

10-100 times less code. Today, Neo4j provides eBay with functionality that was previously impossible.”

- Volker Pacher, Senior Developer

“Minutes to milliseconds” performance Queries up to 1000x faster than RDBMS or other NoSQL

Page 45: Intro to Neo4j and Graph Databases

IntuitivnessSpeedAgility

Page 46: Intro to Neo4j and Graph Databases

A Naturally Adaptive Model

A Query Language Designed for Connectedness

+

=Agility

Page 47: Intro to Neo4j and Graph Databases

CYPHERSQL for graphs

Page 48: Intro to Neo4j and Graph Databases

(Very) Brief Cypher Tutorial

Page 49: Intro to Neo4j and Graph Databases

Creating the Data

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

LOVES

LABEL PROPERTY

NODE NODE

LABEL PROPERTY

Page 50: Intro to Neo4j and Graph Databases

Representing Bi-Directionality

FB_FRIENDS

MATCH (:Person { name:“Ann”} ) - [:FB_FRIENDS] -> (:Person { name:“Dan”} )

MATCH (:Person { name:“Ann”} ) - [:FB_FRIENDS] - (:Person { name:“Dan”} )

Page 51: Intro to Neo4j and Graph Databases

CypherTypical Complex SQL Join The Same Query using Cypher

MATCH (boss)-[:MANAGES*0..3]->(sub), (sub)-[:MANAGES*1..3]->(report)WHERE boss.name = “John Doe”RETURN sub.name AS Subordinate, count(report) AS Total

Project Impact

Less time writing queries• More time understanding the answers • Leaving time to ask the next question

Less time debugging queries: • More time writing the next piece of code • Improved quality of overall code base

Code that’s easier to read: • Faster ramp-up for new project members • Improved maintainability & troubleshooting

Page 52: Intro to Neo4j and Graph Databases

http://www.opencypher.org/

Page 53: Intro to Neo4j and Graph Databases

Neo4j

Graph Database

• Property graph data model• Nodes and relationships• Native graph processing• (open)Cypher query language

neo4j.com

Page 54: Intro to Neo4j and Graph Databases

Neo4j – Key Product Features

Native Graph StorageEnsures data consistency and performance

Native Graph Processing Millions of hops per second, in real time

“Whiteboard Friendly” Data ModelingModel data as it naturally occurs

High Data IntegrityFully ACID transactions

Powerful, Expressive Query Language Requires 10x to 100x less code than SQL Scalability and High Availability Vertical and horizontal scaling optimized for graphs Built-in ETLSeamless import from other databases Integration Drivers and APIs for popular languages

MATCH(A)

Page 55: Intro to Neo4j and Graph Databases

How do you use Neo4j?

CREATE MODEL

+

LOAD DATA QUERY DATA

Page 56: Intro to Neo4j and Graph Databases

How do you use Neo4j?

Page 57: Intro to Neo4j and Graph Databases
Page 58: Intro to Neo4j and Graph Databases

How do you use Neo4j?

Page 59: Intro to Neo4j and Graph Databases

Language Drivers

Page 60: Intro to Neo4j and Graph Databases

Language Drivers

Page 61: Intro to Neo4j and Graph Databases

Native Server-Side Extensions

Page 62: Intro to Neo4j and Graph Databases

Architectural Options

DataStorageandBusinessRulesExecu5on

DataMiningandAggrega5on

Applica'on

GraphDatabaseCluster

Neo4j Neo4j Neo4j

AdHocAnalysis

BulkAnaly'cInfrastructureHadoop,EDW…

DataScien'st

EndUser

DatabasesRela5onalNoSQLHadoop

Page 63: Intro to Neo4j and Graph Databases

SQL

Day in the Life of a RDBMS Developer

Page 64: Intro to Neo4j and Graph Databases

• Complex to model and store relationships • Performance degrades with increases in data • Queries get long and complex • Maintenance is painful

SQL Pains

Page 65: Intro to Neo4j and Graph Databases

• Easy to model and store relationships • Performance of relationship traversal remains constant with

growth in data size • Queries are shortened and more readable • Adding additional properties and relationships can be done on

the fly - no migrations

Graph Gains

Page 66: Intro to Neo4j and Graph Databases

FROM RDBMS TO GRAPHS

Page 67: Intro to Neo4j and Graph Databases
Page 68: Intro to Neo4j and Graph Databases
Page 69: Intro to Neo4j and Graph Databases

Northwind

Page 70: Intro to Neo4j and Graph Databases

Northwind - the canonical RDBMS Example

Page 71: Intro to Neo4j and Graph Databases

( )-[:TO]->(Graph)

Page 72: Intro to Neo4j and Graph Databases
Page 73: Intro to Neo4j and Graph Databases

( )-[:IS_BETTER_AS]->(Graph)

Page 74: Intro to Neo4j and Graph Databases

Starting with the ER Diagram

Page 75: Intro to Neo4j and Graph Databases

Locate the Foreign Keys

Page 76: Intro to Neo4j and Graph Databases

Drop the Foreign Keys

Page 77: Intro to Neo4j and Graph Databases

Find the JOIN Tables

Page 78: Intro to Neo4j and Graph Databases

(Simple) JOIN Tables Become Relationships

Page 79: Intro to Neo4j and Graph Databases

Attributed JOIN Tables -> Relationships with Properties

Page 80: Intro to Neo4j and Graph Databases

Querying a Subset Today

Page 81: Intro to Neo4j and Graph Databases

As a Graph

Page 82: Intro to Neo4j and Graph Databases

QUERYING THE GRAPH

Page 83: Intro to Neo4j and Graph Databases

using openCypher

Page 84: Intro to Neo4j and Graph Databases

Property Graph Model

CREATE(:Employee{firstName:“Steven”})-[:REPORTS_TO]->(:Employee{firstName:“Andrew”})

REPORTS_TO Steven Andrew

LABEL PROPERTY

NODE NODE

LABEL PROPERTY

Page 85: Intro to Neo4j and Graph Databases

Who do people report to?MATCH (e:Employee)<-[:REPORTS_TO]-(sub:Employee)RETURN *

Page 86: Intro to Neo4j and Graph Databases

Who do people report to?

Page 87: Intro to Neo4j and Graph Databases

Who do people report to?MATCH (e:Employee)<-[:REPORTS_TO]-(sub:Employee)RETURN e.employeeID AS managerID, e.firstName AS managerName, sub.employeeID AS employeeID, sub.firstName AS employeeName;

Page 88: Intro to Neo4j and Graph Databases

Who do people report to?

Page 89: Intro to Neo4j and Graph Databases

Who does Robert report to?

MATCH p=(e:Employee)<-[:REPORTS_TO]-(sub:Employee)WHERE sub.firstName = ‘Robert’RETURN p

Page 90: Intro to Neo4j and Graph Databases

Who does Robert report to?

Page 91: Intro to Neo4j and Graph Databases

What is Robert’s reporting chain?

MATCH p=(e:Employee)<-[:REPORTS_TO*]-(sub:Employee)WHERE sub.firstName = ‘Robert’RETURN p

Page 92: Intro to Neo4j and Graph Databases

What is Robert’s reporting chain?

Page 93: Intro to Neo4j and Graph Databases

Who’s the Big Boss?MATCH (e:Employee)WHERE NOT (e)-[:REPORTS_TO]->()RETURN e.firstName as bigBoss

Page 94: Intro to Neo4j and Graph Databases

Who’s the Big Boss?

Page 95: Intro to Neo4j and Graph Databases

Product Cross-SellingMATCH (choc:Product {productName: 'Chocolade'}) <-[:INCLUDES]-(:Order)<-[:SOLD]-(employee), (employee)-[:SOLD]->(o2)-[:INCLUDES]->(other:Product)RETURN employee.firstName, other.productName, COUNT(DISTINCT o2) as countORDER BY count DESCLIMIT 5;

Page 96: Intro to Neo4j and Graph Databases

Product Cross-Selling

Page 97: Intro to Neo4j and Graph Databases

LOADING OUR DATA

Page 98: Intro to Neo4j and Graph Databases

CSV

Page 99: Intro to Neo4j and Graph Databases

CSV files for Northwind

Page 100: Intro to Neo4j and Graph Databases

3 Steps to Creating the Graph

IMPORT NODES CREATE INDEXES IMPORT RELATIONSHIPS

Page 101: Intro to Neo4j and Graph Databases

Importing Nodes// Create customersUSING PERIODIC COMMITLOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-contrib/developer-resources/gh-pages/data/northwind/customers.csv" AS rowCREATE (:Customer {companyName: row.CompanyName, customerID: row.CustomerID, fax: row.Fax, phone: row.Phone});

// Create productsUSING PERIODIC COMMITLOAD CSV WITH HEADERS FROM "https://raw.githubusercontent.com/neo4j-contrib/developer-resources/gh-pages/data/northwind/products.csv" AS rowCREATE (:Product {productName: row.ProductName, productID: row.ProductID, unitPrice: toFloat(row.UnitPrice)});

Page 102: Intro to Neo4j and Graph Databases

:play northward graph

Page 103: Intro to Neo4j and Graph Databases

High Performance LOADingneo4j-import

4.58 million thingsand their relationships…

Loads in 100 seconds!

Page 104: Intro to Neo4j and Graph Databases

POWERING AN APP

Page 105: Intro to Neo4j and Graph Databases

Simple App

Page 106: Intro to Neo4j and Graph Databases

Simple Python Code

Page 107: Intro to Neo4j and Graph Databases

Simple Python Code

Page 108: Intro to Neo4j and Graph Databases

Simple Python Code

Page 109: Intro to Neo4j and Graph Databases

Simple Python Code

Page 110: Intro to Neo4j and Graph Databases

Resources

Page 111: Intro to Neo4j and Graph Databases

neo4j.com/download

Page 112: Intro to Neo4j and Graph Databases

Simple App

http://network.graphdemos.com/

Page 113: Intro to Neo4j and Graph Databases

neo4j.com/developer

Page 114: Intro to Neo4j and Graph Databases

There Are Lots of Ways to Easily Learn Neo4j

Page 115: Intro to Neo4j and Graph Databases

graphdatabases.com

Page 116: Intro to Neo4j and Graph Databases

http://neo4j.com/graphgists/