Graph db

Preview:

Citation preview

Imran Ahmed August 2015

Graph is Everywhere !!! An Introduction to Graph Databases and Neo4j

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

Agenda

No SQL Overview Graph Databases Comparison with RDBMS What is Neo4j? Cypher Query Language How to migrate ? Real-world implementation use cases with Neo4j Install and Deploy Conclusion

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

What is NOSQL ?It’s not “No to SQL”

It’s not “Never SQL”

It’s “Not only SQL”

NOSQL describes the ongoing trends where we as developers searching for different options based on changing requirements.

BTW what is changing and why we need NOSQL ?

Data is getting bigger…

Data is more connected… Data is more semi-structured…

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

Types of NOSQL…

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

Types of NOSQL…Key-Value• A hash table where there is a unique key and a pointer to a

particular item of data.E.g.: Oracle BDB, Amazon Simple DB etc.

Column (Big Table)• There are still keys but they point to multiple columns. The

columns are arranged by column family.• Supports Large amount of Data.E.g.: Cassandra, HBase.

Document• The semi-structured documents are stored in formats like JSON.

Supports Large amount of Data.• These were inspired by Lotus Notes and are similar to key-value

stores.E.g.: CouchDB, MongoDB.

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

Graph Database

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

What is Graph DB ?A Database with explicit graph structure

Data Model• Nodes - Table• Edges - Relationships• Properties – Column

Every node knows its adjacent nodes

No separate index lookup or complex joins present

White board friendly.

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

Why Graph DB ?

Fast and easy to query

Very high scalability - up to 32 billion nodes

Fast deep traversals instead of slow SQL queries that span many table joins.

Support ACID transactions with rollbacks support

Performance never degrade with increase in data unlike RDBMS

Priceless for connected data - That’s why industry leaders like FB, Google, eBay etc has already gone its way.

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

Let’s compare

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

Let’s compare

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

Let’s compare

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

Neo4j

World’s leading and most popular graph database

Open source , implemented in java

Schema free property graph

Perfect for complex and highly connected data

Here both nodes and relationships can contain properties

REST API - Accessible from most of the programming languages like Java, C#, Python, Pearl, Scala, Cypher etc.

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

Cypher Query Language

Pattern matching query Language (like SQL for graphs)

It follows SQL like syntax and supports many clauses like Where , Order By etc.

It basically describes what you want and not how you want.

Avoid using Ids.

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

Cypher Example

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

Let’s compare head to head

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

Eassyyyy isn’t it ???

Let’s compare head to head

Compare Recommendation Engine.

Problem: Recommendation engine should look at the products that peer customers have purchased and then suggest them to the current user.

Complex sql - Recommendation engine.png Simple CQL - Recommendation engine.png

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

RDBMS GRAPH

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

RDBMS GRAPH

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

RDBMS GRAPH

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

RDBMS GRAPH

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

RDBMS GRAPH

US | UK | BENELUX | ME | IND©1996-2015 Aspire Systems, Inc.

Fraud Detection Case Study

Fraud - create data sample.txt

Fraud - Find disputed transactions.txt

Fraud - Find undisputed for each disputed.txt

Fraud - Zero in to the location.txt

Fraud Detection - Result

Key questions …

Cost Efficient ? Open source

Scalable ?

Performance ?

Normalized ?

User friendly ?

Up to 32 billion nodes

Better & Consistent

Supports all ACID properties

Simple queries, No joins, Multiple Language support,

Nice UI

EMBRACE IT

REALITY IS A GRAPH

Conclusion

This is just the beginning...Visit www.neo4j.org for more!

Get Graphy!

References:

https://en.wikipedia.org/wiki/Graph_database

http://www.tutorialspoint.com/neo4j

http://www.neo4j.org

http://www.neo4j.org/learn/cypher

WP-OvercomingSQLstrain.pdf

Recommended