Graphs are everywhere. From websites adding social capabilities to Telcos providing personalized customer services, to innovative bioinformatics research, organizations are adopting graph databases as the best way to model and query connected data. If you can whiteboard, you can model your domain in a graph database.
In this session Emil Eifrem provides a close look at the graph model and offers best use cases for effective, cost-efficient data storage and accessibility.
Take Aways: Understand the model of a graph database and how it compares to document and relational databases Understand why graph databases are best suited for the storage, mapping and querying of connected data
Emil's presentation will be followed by a Hands-on Guide to Spring Data Neo4j. Spring Data Neo4j provides straightforward object persistence into the Neo4j graph database. Conceived by Rod Johnson and Neo Technology CEO Emil Eifrem, it is the founding project of the Spring Data effort. The library leverages a tight integration with the Spring Framework and the Spring Data infrastructure. Besides the easy to use object graph mapping it offers the powerful graph manipulation and query capabilities of Neo4j with a convenient API.
The talk introduces the different aspects of Spring Data Neo4j and shows applications in several example domains.
During the session we walk through the creation of a engaging sample application that starts with the setup and annotating the domain objects. We see the usage of Neo4jTemplate and the powerful repository abstraction. After deploying the application to a cloud PaaS we execute some interesting query use-cases on the collected data.
8. The Evolution of Web Search
Pre-1999 1999 - 2012
WWW Indexing Google Invents
PageRank
4
9. The Evolution of Web Search
Pre-1999 1999 - 2012 2012-?
WWW Indexing Google Invents Google Launches the
PageRank Knowledge Graph
4
10. The Evolution of Web Search
Pre-1999 1999 - 2012 2012-?
WWW Indexing Google Invents Google Launches the
PageRank Knowledge Graph
Atomic Data
4
11. The Evolution of Web Search
Pre-1999 1999 - 2012 2012-?
WWW Indexing Google Invents Google Launches the
PageRank Knowledge Graph
Simple
Atomic Data
Connected Data
4
12. The Evolution of Web Search
Pre-1999 1999 - 2012 2012-?
WWW Indexing Google Invents Google Launches the
PageRank Knowledge Graph
Simple Rich
Atomic Data
Connected Data Connected Data
4
39. The Property Graph model
Em Joh
il a n
knows knows
Alli Tob Lar
son ias knows s
knows
And And knows
knows rea rés
s
knows knows knows
Pet Miic
Mc knows Ian
er knows a
a
knows knows
De Mic
lia h ael
11
40. The Property Graph model
Em Joh
il a n
knows knows
Alli Tob Lar
son ias knows s
Nodes And
knows
And knows
knows rea rés
s
knows knows knows
Pet Miic
Mc knows Ian
er knows a
a
knows knows
De Mic
lia h ael
11
41. The Property Graph model
Em Joh
il a n
knows knows
Alli Tob Lar
son ias knows s
Nodes And
knows
And knows
knows rea rés
s
knows knows knows
Pet Miic
Mc knows Ian
er knows a
a
knows knows
De Mic
lia h ael
Relationships
11
42. The Property Graph model
E Joh
Em mil Joh
a a n
il n
knows knows
knows
knows
AllAlliso
iso n Tob Tobia knows Lar Lar
s
Nodes n ias s knows s
knows
knows
An And And And knows knows
knows
knows dre re rés rés
as as
knows
knows knows
knows knowsknows
Pet e
Pe t Miic M
M c Mi knows Ian Ian
r er knows
knows a ica
a ca knows
knows
knows knows
knows
De D Mi c M
lia el hae ich
ia l ae
Relationships l
Properties (each a key+value)
+ Indexes (for easy look-ups)
11
49. Great! But what about performance?
• a sample social graph
13
50. Great! But what about performance?
• a sample social graph
–with ~1,000 persons
13
51. Great! But what about performance?
• a sample social graph
–with ~1,000 persons
• average 50 friends per person
13
52. Great! But what about performance?
• a sample social graph
–with ~1,000 persons
• average 50 friends per person
• pathExists(a,b) limited to depth 4
13
53. Great! But what about performance?
• a sample social graph
–with ~1,000 persons
• average 50 friends per person
• pathExists(a,b) limited to depth 4
• caches warmed up to eliminate disk I/O
13
54. Great! But what about performance?
• a sample social graph
–with ~1,000 persons
• average 50 friends per person
• pathExists(a,b) limited to depth 4
• caches warmed up to eliminate disk I/O
# persons query time
Relational database 1,000 2000ms
Neo4j 1,000 2ms
Neo4j 1,000,000
13
55. Great! But what about performance?
• a sample social graph
–with ~1,000 persons
• average 50 friends per person
• pathExists(a,b) limited to depth 4
• caches warmed up to eliminate disk I/O
# persons query time
Relational database 1,000 2000ms
Neo4j 1,000 2ms
Neo4j 1,000,000
13
56. Great! But what about performance?
• a sample social graph
–with ~1,000 persons
• average 50 friends per person
• pathExists(a,b) limited to depth 4
• caches warmed up to eliminate disk I/O
# persons query time
Relational database 1,000 2000ms
Neo4j 1,000 2ms
Neo4j 1,000,000
13
57. Great! But what about performance?
• a sample social graph
–with ~1,000 persons
• average 50 friends per person
• pathExists(a,b) limited to depth 4
• caches warmed up to eliminate disk I/O
# persons query time
Relational database 1,000 2000ms
Neo4j 1,000 2ms
Neo4j 1,000,000 2ms
14
58. How do I query this graph?
// lookup starting point in an index
START user=node:User(name
start n=node:People(name ==‘Andreas’)
‘Andreas’)
MATCH (user)-[:HAS_SENT]->(tweet)-[:TAGGED_BY]->(tag)
RETURN tag
And
rea
s
59. How do I query this graph?
// lookup starting point in an index
START user=node:User(name
start n=node:People(name ==‘Andreas’)
‘Andreas’)
MATCH (user)-[:HAS_SENT]->(tweet)-[:TAGGED_BY]->(tag)
RETURN tag
And
rea
s
64. (Neo4j) -[:IS_A]-> (Graph Database)
- A Graph Database:
- a schema-free Property Graph
- perfect for complex, highly connected data
4
65. (Neo4j) -[:IS_A]-> (Graph Database)
- A Graph Database:
- a schema-free Property Graph
- perfect for complex, highly connected data
- A Graph Database:
4
66. (Neo4j) -[:IS_A]-> (Graph Database)
- A Graph Database:
- a schema-free Property Graph
- perfect for complex, highly connected data
- A Graph Database:
- reliable with real ACID Transactions
4
67. (Neo4j) -[:IS_A]-> (Graph Database)
- A Graph Database:
- a schema-free Property Graph
- perfect for complex, highly connected data
- A Graph Database:
- reliable with real ACID Transactions
- scalable: 34 billions nodes and relationships
4
68. (Neo4j) -[:IS_A]-> (Graph Database)
- A Graph Database:
- a schema-free Property Graph
- perfect for complex, highly connected data
- A Graph Database:
- reliable with real ACID Transactions
- scalable: 34 billions nodes and relationships
- fast with millons traversals / second
4
69. (Neo4j) -[:IS_A]-> (Graph Database)
- A Graph Database:
- a schema-free Property Graph
- perfect for complex, highly connected data
- A Graph Database:
- reliable with real ACID Transactions
- scalable: 34 billions nodes and relationships
- fast with millons traversals / second
- Server with REST API, or Embeddable on the JVM
4
70. (Neo4j) -[:IS_A]-> (Graph Database)
- A Graph Database:
- a schema-free Property Graph
- perfect for complex, highly connected data
- A Graph Database:
- reliable with real ACID Transactions
- scalable: 34 billions nodes and relationships
- fast with millons traversals / second
- Server with REST API, or Embeddable on the JVM
- higher-performance with High-Availability (read scaling)
4
71. (Cypher) -[:IS_A]-> (Graph Query Language)
๏ Declarative query language
• Describe what you want, not how
• Based on pattern matching
๏ Example:
START tag=node:Tag(tag=”s12gx”), # index lookup
MATCH sender-[:SENDER]->tweet-[:TAG]->tag
WHERE new_friends.age > 18
RETURN sender.name, count(*)
ORDER BY count(*) DESC
LIMIT 10
4
75. Spring Data Neo4j
๏ Spring Data: VMWare/SpringSource initiative to give Spring
developers easy access to the emerging world of NOSQL
๏ Spring Data Neo4j is the integration library for Neo4j
๏ Simple programming model:
annotation-based programming for applications with rich domains
๏ Always possible to drop down to core Neo4j-API
๏ simple and powerful repository abstraction
๏ two mapping modes
๏ Neo4j-Server support
76. Spring Data Neo4j features
• Annotation-based programming model
• Spring Data Commons Repository support
• Neo4j Query and Traversal support
– on dynamic fields and via repository methods
• Neo4j indexing support (includes fulltext and numeric range queries)
• Entity types stored in the graph database as well
• Dynamic type projection (duck typing)
• Cross-store support for partial JPA / graph entities
• Support for JSR-303 (bean validation)
• Support for the Neo4j Server (remote server and in server extension)
• Neo4jTemplate with exception translation, optional transaction management
and more
22
77. Classic Neo4j domain class
public class Tag {
private final Node underlyingNode;
Tag( final Node node ) {
underlyingNode = node;
}
public Node getUnderlyingNode() {
return underlyingNode;
}
public final String getName() {
return (String) underlyingNode.getProperty( “name” );
}
public void setName( final String name ) {
underlyingNode.setProperty( “name”, name );
}
}
78. Spring Data Neo4j domain class
@NodeEntity
public class Tag {
@GraphId private Long id;
private String name;
}
79. Spring Data Neo4j domain class
@NodeEntity
public class Tag {
@GraphId private Long id;
@Indexed(unique = true)
private String name;
}
81. Defining entity classes
• @NodeEntity
• Represents a node in the graph
• Fields saved as properties on node
• References stored as relationships between nodes
• Instantiated using Java ‘new’ keyword, like any POJO
• Also returned by lookup mechanisms
• Type information stored in the graph
83. Defining entity classes
• @RelationshipEntity
• Represents a relationship in the graph
• Fields saved as properties on relationship
• Special fields for start- and end-nodes
• Only returned by lookup methods
84. Tweet domain class
@NodeEntity
public class Tweet {
@GraphId private Long id;
@Indexed(unique=true) Long tweetId;
String text;
@Fetch User sender; // eager loading
@RelatedTo(type="TAGGED") Collection<Tag> tags;
@RelatedTo(type="MENTIONS") Set<User> mentions;
@RelatedTo(type="SOURCE") Tweet source;
}
85. Interface based Repositories
• based on Repository infrastructure in Spring Data Commons
• just define the interface and the namespace configuration
• provide out-of-the-box support for
–CRUD-Operations
–Index-Lookups
–Traversal-Execution
–Annotated Graph-Queries (Cypher, Gremlin)
–Derived Queries
–Spatial Queries
• extensible via custom methods with provided implementations
28
87. Neo4j-Template (I)
• well known Spring Template Pattern
• Resource / Transaction Management
• Convenience Methods
• Nodes and Entities handling & conversion
• Fluent Query Result Handling
• Works also via REST with Neo4j-Server
• Exception Translation
30
88. Neo4j-Server-Support
<bean id="restGraphDatabaseService"
class="org.sf.data.neo4j.rest.SpringRestGraphDatabase">
<constructor-arg value="http://localhost:7473/db/data" />
</bean>
<neo4j:config graphDatabaseService="restGraphDatabaseService"/>
• drop-in replacement for the embedded GraphDatabase
• works transparently with POJO-Entity-Mapping and
Neo4j-Template
31
89. Sample App
-uses Spring Social (minimally)
-Simple Domain: Tweets, Users, Tags
-connected Entities
-Repositories, Service
-standalone App with
-embedded Neo4j-Database
-Neo4j-Server
92. Whiteboard friendly - Abstract
:User
PO
ST
ED
:Tweet
S
ION
NT
ME
:User :Tweet
POSTED
93. Whiteboard friendly - Abstract
:User
PO
ST
ED
TAGGED
:Tag
:Tweet TAGG
ED
:Tag
S
ION ED
NT G
ME G
:User :Tweet TA
POSTED
94. Whiteboard friendly - Example
Attending the
#S2GX #SDN
session by
@mesirii
Looking forward to
my #SDN session
95. Whiteboard friendly - Example
@peterneubauer
PO
ST
ED
Attending the
#S2GX #SDN
session by
@mesirii
Looking forward to
@mesirii POSTED
my #SDN session
96. Whiteboard friendly - Example
@peterneubauer
PO
ST
ED
Attending the
#S2GX #SDN
session by
@mesirii
S
ION
NT
ME Looking forward to
@mesirii POSTED
my #SDN session
97. Whiteboard friendly - Example
@peterneubauer
PO
ST
ED
Attending the
TAGGED
#S2GX
#S2GX #SDN TAGG
session by ED
@mesirii
#SDN
S
ION ED
NT G
ME Looking forward to TA
G
@mesirii POSTED
my #SDN session
102. Hubway Data Challenge - Import
• Boston Bike Sharing Network
• Import using Spring Data Neo4j
• Visualization with Cypher & d3.js (Chord)
http://bit.ly/neo_hubway
39
103. Cineasts.net - a social movie database
Check Out: http://spring.neo4j.org/tutorial
104. Spring Data Neo4j Guidebook
“Good Relationships”
“I’m excited about Spring Data Neo4j.... makes working with Neo4j
amazingly easy, and therefore has the potential to make you more successful
as a developer.”
Rod Johnson, founder of Spring
- Spring Data Neo4j comes with a great Guide Book, featuring:
- Forewords by Rod Johnson and Emil Eifrem
- An easy to read, narrative tutorial walkthrough for cineasts.net
- A comprehensive reference for all the details
- Check it out: http://bit.ly/sd-book
- Free e-book and printed
105. Spring Data Neo4j Guidebook
“Good Relationships”
“I’m excited about Spring Data Neo4j.... makes working with Neo4j
amazingly easy, and therefore has the potential to make you more successful
as a developer.”
Rod Johnson, founder of Spring
- Spring Data Neo4j comes with a great Guide Book, featuring:
- Forewords by Rod Johnson and Emil Eifrem
- An easy to read, narrative tutorial walkthrough for cineasts.net
- A comprehensive reference for all the details
- Check it out: http://bit.ly/sd-book
- Free e-book and printed
106. O‘Reilly Spring Data Book
„Modern Data Access for Enterprise Java“
• book by the Spring Data project leads
• introduction to Spring Data & SD-repositories
• covers all subprojects
• available in O‘Reilly OFPS and O‘Reilly store (e-book)
• http://bit.ly/sd-book
109. How do I get started?
๏ Documentation
• http://spring.neo4j.org
4
110. How do I get started?
๏ Documentation
• http://spring.neo4j.org
• Dev-Notes
4
111. How do I get started?
๏ Documentation
• http://spring.neo4j.org
• Dev-Notes
• Spring Data Book
4
112. How do I get started?
๏ Documentation
• http://spring.neo4j.org
• Dev-Notes
• Spring Data Book
• Good Relationships
4
113. How do I get started?
๏ Documentation
• http://spring.neo4j.org
• Dev-Notes
• Spring Data Book
• Good Relationships
๏ Get Neo4j
4
114. How do I get started?
๏ Documentation
• http://spring.neo4j.org
• Dev-Notes
• Spring Data Book
• Good Relationships
๏ Get Neo4j
• http://neo4j.org/download
4
115. How do I get started?
๏ Documentation
• http://spring.neo4j.org
• Dev-Notes
• Spring Data Book
• Good Relationships
๏ Get Neo4j
• http://neo4j.org/download
๏ Participate
• http://neo4j.org/forums
• http://spring.neo4j.org/discussions
4
116. How do I get started?
๏ Documentation
• http://spring.neo4j.org
• Dev-Notes
• Spring Data Book
• Good Relationships
๏ Get Neo4j
• http://neo4j.org/download
๏ Participate
• http://neo4j.org/forums
• http://spring.neo4j.org/discussions
• http://neo4j.meetup.com
4
117. How do I get started?
๏ Documentation
• http://spring.neo4j.org
• Dev-Notes
• Spring Data Book
• Good Relationships
๏ Get Neo4j
• http://neo4j.org/download
๏ Participate
• http://neo4j.org/forums
• http://spring.neo4j.org/discussions
• http://neo4j.meetup.com
• a session like this one ;)
4
118. GraphConnect Nov 6th 2012 San Francisco
50%
dis
CONNECT ABOUT | UPCOMING EVENTS | cou
REGISTRATION | CONTACT
nt a
t our
boo
th
WORLD’S LEADING GRAPH CONFERENCE
SAN FRANCISCO 2012
4
Neo4j Query and Traversal support on dynamic fields and via repository methods\nNeo4j indexing support (includes unique indexes, fulltext and numeric range queries)\nEntity types stored in the graph (index or category-nodes)\nDynamic type projection (duck typing)\nCross-store support for partial JPA / graph entities\nSupport for JSR-303 (bean validation)\nSupport for the Neo4j Server (remote server and in server extension)\nNeo4jTemplate with exception translation, optional transaction management and more\n