real world applications with spring data neo4j

169
© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission. Graph Databases Rock - Learn Why! By Michael Hunger Neo Technology Mittwoch, 11. September 13

Upload: spring-io

Post on 26-Jan-2015

110 views

Category:

Technology


1 download

DESCRIPTION

Speaker: Michael Hunger Spring Data Neo4j in its 2.x version is a mature implementation of an object graph mapping framework, that both closely integrates with the Spring Framework and also offers unique modeling and querying opportunities by having chosen the property graph data model. This talk presents how several Neo Technology customers already put Spring Data Neo4j into production. They stem from a variety of domains – gaming, server center monitoring, education, appliance management, energy market simulation and more. Based on those use-cases we discuss how to implement real-world applications with Spring Data Neo4j and the Spring Framework. First we want to discuss the business problems they had to solve and why a graph database was a good fit for them. After a quick intro to Spring Data Neo4j and Neo4j, we will talk about modeling choices and the benefits and implications of choosing a rich data model. We'll follow the example domains into code, from annotated domain entities, to the usage of the powerful repository abstractions. Showing how to use Neo4jTemplate to implement some lower level functionality will round off the core library usage. Building on this, we look into the integration aspects, how Spring Data Neo4j can be combined with other Spring projects, like Spring Data MongoDB, Spring Data REST, and Spring Batch. A quick demonstration shows on how to access Spring Data Neo4j from the (Web)-UI layer. The talk will close of with a glimpse into the future: Neo4j added some very interesting features in its 2.0 release. From node labels, automatic indexes and constraints to a transactional http endpoint for Cypher. These changes make it possible to rethink some aspects of Spring Data Neo4j, like type representation and indexing. But also some bigger ideas for changes ahead like basing the object graph mapping completely on Neo4j's Cypher Graph Query Language will be touched.

TRANSCRIPT

Page 1: Real World Applications with Spring Data Neo4j

© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission.

Graph Databases Rock - Learn Why!By Michael Hunger

Neo Technology

Mittwoch, 11. September 13

Page 2: Real World Applications with Spring Data Neo4j

The book on your seat! -“Graph Databases”

• The definitive guide on graph databases• discusses graph concepts, history and data model• compares with other NoSQL technologies• details use-cases from different domains• explains Neo4j‘s humane query language „Cypher“

Written by experts - Emil Eifrem, Ian Robinson, Jim WebberCompliments of Neo Technology

Mittwoch, 11. September 13

Page 3: Real World Applications with Spring Data Neo4j

Bookmark: GraphConnect Oct 3-4 2013 San Francisco

4

$99 ticket coupon in your book

Mittwoch, 11. September 13

Page 4: Real World Applications with Spring Data Neo4j

4

• Wed, Sep 11, 6-9PM• David's Restaurant,

5151 Stars and Stripes Drive• Just around the corner• Enjoy dessert, wine, beer• Chance to win a signed

Spring Data Book

Meetup - Tomorrow (Wed) EveningSpring Data Neo4j: Past, Current & Future

http://www.meetup.com/graphdb-sf/events/138428012/

Mittwoch, 11. September 13

Page 5: Real World Applications with Spring Data Neo4j

(SDN)<-[:LEARN]-(YOU)-[:GET]->(Book)

YOU

Coffee? Awake?

Spring?

Book

GraphConnectticket

Spring DataNeo4j

NoSQL? Sleep?

Neo4j?

Mittwoch, 11. September 13

Page 6: Real World Applications with Spring Data Neo4j

(Michael)-[:CODES]->(SDN)-[:USES]->(Neo4j)

ME

Spring Cloud

Community

Cypher

console

community graph

ServerCustomers

Kernel

Mittwoch, 11. September 13

Page 7: Real World Applications with Spring Data Neo4j

Agenda

1. Connected Data, Graph Databases and Neo4j

2. Spring Data Neo4j

3. Twitter-Graph - Small Example App

4. Real World Customers and Use-Cases

5. Summary

6. Q & A

Mittwoch, 11. September 13

Page 8: Real World Applications with Spring Data Neo4j

NOSQL

Mittwoch, 11. September 13

Page 9: Real World Applications with Spring Data Neo4j

complexity = f(size, semi-structure, connectedness)

Data Complexity

Mittwoch, 11. September 13

Page 10: Real World Applications with Spring Data Neo4j

NOSQL databases

NOSQL

RelationalGraph

DocumentKeyValueRiak

Column oriented

Redis

Cassandra

Mongo

Couch

Neo4j

MySQL Postgres

Mittwoch, 11. September 13

Page 11: Real World Applications with Spring Data Neo4j

Volume vs. Complexity & NOSQL databases

Mittwoch, 11. September 13

Page 12: Real World Applications with Spring Data Neo4j

Volume vs. Complexity & NOSQL databases

Volume ~= Size

Mittwoch, 11. September 13

Page 13: Real World Applications with Spring Data Neo4j

Volume vs. Complexity & NOSQL databases

Den

sity

~=

Com

plex

ity

Volume ~= Size

Mittwoch, 11. September 13

Page 14: Real World Applications with Spring Data Neo4j

Volume vs. Complexity & NOSQL databases

Den

sity

~=

Com

plex

ity

Volume ~= Size

Key-ValueStore

Mittwoch, 11. September 13

Page 15: Real World Applications with Spring Data Neo4j

Volume vs. Complexity & NOSQL databases

Den

sity

~=

Com

plex

ity

ColumnFamily

Volume ~= Size

Key-ValueStore

Mittwoch, 11. September 13

Page 16: Real World Applications with Spring Data Neo4j

Volume vs. Complexity & NOSQL databases

Den

sity

~=

Com

plex

ity

ColumnFamily

Volume ~= Size

Key-ValueStore

DocumentDatabases

Mittwoch, 11. September 13

Page 17: Real World Applications with Spring Data Neo4j

Volume vs. Complexity & NOSQL databases

RDBMSD

ensi

ty ~

= C

ompl

exity

ColumnFamily

Volume ~= Size

Key-ValueStore

DocumentDatabases

Mittwoch, 11. September 13

Page 18: Real World Applications with Spring Data Neo4j

Volume vs. Complexity & NOSQL databases

RDBMSD

ensi

ty ~

= C

ompl

exity

ColumnFamily

Volume ~= Size

Key-ValueStore

DocumentDatabases

GraphDatabases

Mittwoch, 11. September 13

Page 19: Real World Applications with Spring Data Neo4j

Volume vs. Complexity & NOSQL databases

RDBMSD

ensi

ty ~

= C

ompl

exity

ColumnFamily

Volume ~= Size

Key-ValueStore

DocumentDatabases

GraphDatabases

90%of

usecases

Mittwoch, 11. September 13

Page 20: Real World Applications with Spring Data Neo4j

Volume vs. Complexity & NOSQL databases

RDBMSD

ensi

ty ~

= C

ompl

exity

ColumnFamily

Volume ~= Size

Key-ValueStore

DocumentDatabases

GraphDatabases

90%of

usecases

Mittwoch, 11. September 13

Page 21: Real World Applications with Spring Data Neo4j

Are Graphs Everywhere ?

Mittwoch, 11. September 13

Page 22: Real World Applications with Spring Data Neo4j

The big graphs are visible

4Mittwoch, 11. September 13

Page 23: Real World Applications with Spring Data Neo4j

The big graphs are visible

4

Facebook Open Graph

Mittwoch, 11. September 13

Page 24: Real World Applications with Spring Data Neo4j

The big graphs are visible

4

Facebook Open Graph

Mittwoch, 11. September 13

Page 25: Real World Applications with Spring Data Neo4j

Social Network

Mittwoch, 11. September 13

Page 26: Real World Applications with Spring Data Neo4j

(Network) Impact Analysis

Mittwoch, 11. September 13

Page 27: Real World Applications with Spring Data Neo4j

Route Finding

Mittwoch, 11. September 13

Page 28: Real World Applications with Spring Data Neo4j

Recommendations

Mittwoch, 11. September 13

Page 29: Real World Applications with Spring Data Neo4j

Logistics

Mittwoch, 11. September 13

Page 30: Real World Applications with Spring Data Neo4j

Access Control

Mittwoch, 11. September 13

Page 31: Real World Applications with Spring Data Neo4j

Fraud Analysis

Mittwoch, 11. September 13

Page 32: Real World Applications with Spring Data Neo4j

Graphs are everywhere !!

21

Science

Art

Friends

Neighbor

Work

Family

Biology

Chemistry

7

ComputersInternet

HistoryPoliticsSociety Reactions

Environments

Proteins

Genes

Users

Networks

Devices

ServicesSoftware

Stories

Creativity Visuals

Business

Geo

Retail

ERP

CloudTravel

Mittwoch, 11. September 13

Page 33: Real World Applications with Spring Data Neo4j

Graph Databases

Mittwoch, 11. September 13

Page 34: Real World Applications with Spring Data Neo4j

23Mittwoch, 11. September 13

Page 35: Real World Applications with Spring Data Neo4j

You know relational

23Mittwoch, 11. September 13

Page 36: Real World Applications with Spring Data Neo4j

You know relational

23Mittwoch, 11. September 13

Page 37: Real World Applications with Spring Data Neo4j

You know relational

23

customer

Mittwoch, 11. September 13

Page 38: Real World Applications with Spring Data Neo4j

You know relational

23

customer account

Mittwoch, 11. September 13

Page 39: Real World Applications with Spring Data Neo4j

You know relational

23

customer accountcust_acct

Mittwoch, 11. September 13

Page 40: Real World Applications with Spring Data Neo4j

You know relational

23

customer accountcust_acct

Mittwoch, 11. September 13

Page 41: Real World Applications with Spring Data Neo4j

You know relational

23

customer accountcust_acct

Mittwoch, 11. September 13

Page 42: Real World Applications with Spring Data Neo4j

You know relational

23

customer accountcust_acct

Mittwoch, 11. September 13

Page 43: Real World Applications with Spring Data Neo4j

You know relational

23

now consider relationships...

Mittwoch, 11. September 13

Page 44: Real World Applications with Spring Data Neo4j

You know relational

23

now consider relationships...

Mittwoch, 11. September 13

Page 45: Real World Applications with Spring Data Neo4j

You know relational

23

now consider relationships...

Mittwoch, 11. September 13

Page 46: Real World Applications with Spring Data Neo4j

You know relational

23

now consider relationships...

Mittwoch, 11. September 13

Page 47: Real World Applications with Spring Data Neo4j

You know relational

23

now consider relationships...

Mittwoch, 11. September 13

Page 48: Real World Applications with Spring Data Neo4j

You know relational

23

now consider relationships...

Mittwoch, 11. September 13

Page 49: Real World Applications with Spring Data Neo4j

23Mittwoch, 11. September 13

Page 50: Real World Applications with Spring Data Neo4j

We're talking about a Property Graph

24Mittwoch, 11. September 13

Page 51: Real World Applications with Spring Data Neo4j

We're talking about a Property Graph

24

Nodes

Mittwoch, 11. September 13

Page 52: Real World Applications with Spring Data Neo4j

We're talking about a Property Graph

24

Nodes

Relationships

Mittwoch, 11. September 13

Page 53: Real World Applications with Spring Data Neo4j

Emil

Andrés

Lars

Johan

Allison

Peter

Michael

Tobias

Andreas

IanMica

Delia

knows

knows

knowsknows

knows

knows

knows

knows

knows

knowsMica

knowsknowsMica

Delia

knows

We're talking about a Property Graph

24

Nodes

Relationships

Properties (each a key+value)

+ Indexes (for easy look-ups)

Mittwoch, 11. September 13

Page 54: Real World Applications with Spring Data Neo4j

How do I query this graph?

Andreas

// lookup starting point in an indexstart n=node:People(name = ‘Andreas’)

START user=node:User(name = ‘Andreas’)MATCH (user)<-[:OWNS]-(account)-[:CONTAINS]-> (booking)-[:TO]->(recipient) RETURN recipient, count(*)ORDER BY count DESC LIMIT 10

Mittwoch, 11. September 13

Page 55: Real World Applications with Spring Data Neo4j

How do I query this graph?

26

SELECT skills.*, user_skill.* FROM users JOIN user_skill ON users.id = user_skill.user_id JOIN skills ON user_skill.skill_id = skill.id WHERE users.id = 1

START user = node:() MATCH (user)-[user_skill]->(skill) RETURN skill, user_skill

Mittwoch, 11. September 13

Page 56: Real World Applications with Spring Data Neo4j

Whiteboard friendly

4Mittwoch, 11. September 13

Page 57: Real World Applications with Spring Data Neo4j

Whiteboard friendly

4

AndreasPeter

EmilAllison

Mittwoch, 11. September 13

Page 58: Real World Applications with Spring Data Neo4j

Whiteboard friendly

4

AndreasPeter

EmilAllison

knows

knows knows

knows

Mittwoch, 11. September 13

Page 59: Real World Applications with Spring Data Neo4j

Whiteboard friendly

4

AndreasPeter

EmilAllison

knows

knows knows

knows

Mittwoch, 11. September 13

Page 60: Real World Applications with Spring Data Neo4j

4Mittwoch, 11. September 13

Page 61: Real World Applications with Spring Data Neo4j

(Neo4j) -[:IS_A]->(Graph Database)

4Mittwoch, 11. September 13

Page 62: Real World Applications with Spring Data Neo4j

(Neo4j) -[:IS_A]->(Graph Database)

4

- A Graph Database:

Mittwoch, 11. September 13

Page 63: Real World Applications with Spring Data Neo4j

(Neo4j) -[:IS_A]->(Graph Database)

4

- A Graph Database:

- a schema-free Property Graph

Mittwoch, 11. September 13

Page 64: Real World Applications with Spring Data Neo4j

(Neo4j) -[:IS_A]->(Graph Database)

4

- A Graph Database:

- a schema-free Property Graph

- perfect for complex, highly connected data

Mittwoch, 11. September 13

Page 65: Real World Applications with Spring Data Neo4j

(Neo4j) -[:IS_A]->(Graph Database)

4

- A Graph Database:

- a schema-free Property Graph

- perfect for complex, highly connected data

- A Graph Database:

Mittwoch, 11. September 13

Page 66: Real World Applications with Spring Data Neo4j

(Neo4j) -[:IS_A]->(Graph Database)

4

- A Graph Database:

- a schema-free Property Graph

- perfect for complex, highly connected data

- A Graph Database:

- reliable with real ACID Transactions

Mittwoch, 11. September 13

Page 67: Real World Applications with Spring Data Neo4j

(Neo4j) -[:IS_A]->(Graph Database)

4

- A Graph Database:

- a schema-free Property Graph

- perfect for complex, highly connected data

- A Graph Database:

- reliable with real ACID Transactions

- scalable: billions of nodes and relationships

Mittwoch, 11. September 13

Page 68: Real World Applications with Spring Data Neo4j

(Neo4j) -[:IS_A]->(Graph Database)

4

- A Graph Database:

- a schema-free Property Graph

- perfect for complex, highly connected data

- A Graph Database:

- reliable with real ACID Transactions

- scalable: billions of nodes and relationships

- fast with millons traversals / second

Mittwoch, 11. September 13

Page 69: Real World Applications with Spring Data Neo4j

(Neo4j) -[:IS_A]->(Graph Database)

4

- A Graph Database:

- a schema-free Property Graph

- perfect for complex, highly connected data

- A Graph Database:

- reliable with real ACID Transactions

- scalable: billions of nodes and relationships

- fast with millons traversals / second

- Server with REST API, or Embeddable on the JVM

Mittwoch, 11. September 13

Page 70: Real World Applications with Spring Data Neo4j

(Neo4j) -[:IS_A]->(Graph Database)

4

- A Graph Database:

- a schema-free Property Graph

- perfect for complex, highly connected data

- A Graph Database:

- reliable with real ACID Transactions

- scalable: billions of nodes and relationships

- fast with millons traversals / second

- Server with REST API, or Embeddable on the JVM

- higher-performance with High-Availability (read scaling)

Mittwoch, 11. September 13

Page 71: Real World Applications with Spring Data Neo4j

(Neo4j) -[:IS_A]->(Graph Database)

4

JS

Clojure

Heroku

ACID TX

LuceneIndex

ServerRUNS_AS

HIGH_AVAIL.

SCALES_TO

embedded

RUNS_AS

RUNS_ON

Ruby

.net

PROVIDES

MySQL

Mongo

LICENSED_LIKE

INTEG

RATES

Master/Slave

billionsNodes >1

M trav/s

Mittwoch, 11. September 13

Page 72: Real World Applications with Spring Data Neo4j

(Cypher) -[:IS_A]->(Graph Query Language)

4

• Declarative query language

- Describe what you want, not how

- Based on graph pattern matching

• Example:

START user=node:User(name=”Michael”), # index lookupMATCH (user)-[:SKILL]->()<-[rating:SKILL]-(colleague)WHERE rating.ability > 3RETURN colleague.name, count(*)ORDER BY count(*) DESCLIMIT 10

Mittwoch, 11. September 13

Page 73: Real World Applications with Spring Data Neo4j

Spring Data Neo4j

Mittwoch, 11. September 13

Page 74: Real World Applications with Spring Data Neo4j

Spring Data Neo4j

• Spring Data: SpringSource initiative to give Spring developers easy, consistent access to the world of NOSQL databases

• projects support different data-stores

• convenient, common access patterns

• but don‘t hide the power of the database

•Spring Data Neo4j is the integration library for Neo4j

Mittwoch, 11. September 13

Page 75: Real World Applications with Spring Data Neo4j

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 sub-projects

• consistent sample project across the sub-projects

• e-commerce domain

• I give one out at the Meetup tomorrow evening!

Mittwoch, 11. September 13

Page 76: Real World Applications with Spring Data Neo4j

Spring Data Neo4j features• Annotation-based programming model• Spring Data Repository support• Neo4j Cypher Query and Traversal support

–on dynamic fields and via repository methods• Neo4j indexing support (includes fulltext and numeric

range queries)• Always possible to drop down to Neo4j APIs

35Mittwoch, 11. September 13

Page 77: Real World Applications with Spring Data Neo4j

Spring Data Neo4j features• Entity types stored in the graph database• 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 server

extension)• Neo4jTemplate with exception translation, optional

transaction management and more

36Mittwoch, 11. September 13

Page 78: Real World Applications with Spring Data Neo4j

Classic Neo4j domain classpublic class User { private final Node underlyingNode;

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

Mittwoch, 11. September 13

Page 79: Real World Applications with Spring Data Neo4j

@NodeEntitypublic class User { @GraphId private Long id; private String name;}

Spring Data Neo4j domain class

Mittwoch, 11. September 13

Page 80: Real World Applications with Spring Data Neo4j

@NodeEntitypublic class User { @GraphId private Long id; private String name;}

@Indexed(unique = true)

Spring Data Neo4j domain class

Mittwoch, 11. September 13

Page 81: Real World Applications with Spring Data Neo4j

Defining entity classes

Mittwoch, 11. September 13

Page 82: Real World Applications with Spring Data Neo4j

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

Mittwoch, 11. September 13

Page 83: Real World Applications with Spring Data Neo4j

Defining entity classes

Mittwoch, 11. September 13

Page 84: Real World Applications with Spring Data Neo4j

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

Mittwoch, 11. September 13

Page 85: Real World Applications with Spring Data Neo4j

Tweet domain class

@NodeEntitypublic 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;}

Mittwoch, 11. September 13

Page 86: Real World Applications with Spring Data Neo4j

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)–Derived Queries–Spatial Queries

• extensible via custom methods with provided implementations

42Mittwoch, 11. September 13

Page 87: Real World Applications with Spring Data Neo4j

Repositories

43

interface TweetRepository extends GraphRepository<Tweet> { Tweet findByTweetId(String id); Collection<Tweet> findByTagsName(String name); @Query("start user=node({0}) match user<-[:SENDER]-tweet-[:TAGGED]->tag return distinct tag.name") Page<String> findUserTags(User user);}

<neo4j:repositories base-package="com.example.repositories"/>

@Controllerpublic class TwitterController { @Autowired TweetRepository tweetRepository;

@RequestMapping(value = "/tweet/{id}",...) public String show(Model model, @PathVariable String id) { Tweet tweet = tweetRepository.findByTweetId(id); model.addAttribute("tweet", tweet); return "/tweet/show"; }}

Mittwoch, 11. September 13

Page 88: Real World Applications with Spring Data Neo4j

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

44Mittwoch, 11. September 13

Page 89: Real World Applications with Spring Data Neo4j

Small Example App

-uses Spring Social (minimally)

-Simple Domain: Tweets, Users, Tags

-connected Entities

-Repositories, Service

-standalone App with

-embedded Neo4j-Database

-Neo4j-Server

https://github.com/jexp/sdn-twitter

Mittwoch, 11. September 13

Page 90: Real World Applications with Spring Data Neo4j

Whiteboard friendly - Abstract

:Tweet

:Tweet:User

:User

POSTED

POSTED

:TagTAGGED

TAGGED

:Tag

TAGG

ED

Mittwoch, 11. September 13

Page 91: Real World Applications with Spring Data Neo4j

Whiteboard friendly - Abstract

MENTION

S

:Tweet

:Tweet:User

:User

POSTED

POSTED

:TagTAGGED

TAGGED

:Tag

TAGG

ED

Mittwoch, 11. September 13

Page 92: Real World Applications with Spring Data Neo4j

Whiteboard friendly - Example

Attending the #S2GX

#SDN session by @mesirii

Looking forward to my #SDN

session

Mittwoch, 11. September 13

Page 93: Real World Applications with Spring Data Neo4j

Whiteboard friendly - Example

Attending the #S2GX

#SDN session by @mesirii

Looking forward to my #SDN

session@mesirii

@peterneubauer

POSTED

POSTED

Mittwoch, 11. September 13

Page 94: Real World Applications with Spring Data Neo4j

Whiteboard friendly - Example

MENTION

S

Attending the #S2GX

#SDN session by @mesirii

Looking forward to my #SDN

session@mesirii

@peterneubauer

POSTED

POSTED

Mittwoch, 11. September 13

Page 95: Real World Applications with Spring Data Neo4j

Whiteboard friendly - Example

MENTION

S

Attending the #S2GX

#SDN session by @mesirii

Looking forward to my #SDN

session@mesirii

@peterneubauer

POSTED

POSTED

#S2GXTAGGED

TAGGED

#SDN

TAGG

ED

Mittwoch, 11. September 13

Page 96: Real World Applications with Spring Data Neo4j

Twitter - Graph Data Model

4Mittwoch, 11. September 13

Page 97: Real World Applications with Spring Data Neo4j

Spring Data Neo4j - Sample Domain Class & Service

4Mittwoch, 11. September 13

Page 98: Real World Applications with Spring Data Neo4j

Neo4j - Sample Graph Query

START tag1=node:Tag("tag:*obama*")> MATCH tag1<-[:TAG]-tweet-[:sender]->user, user<-[:sender]-tweet2-[:TAG]->tag2> WHERE tag2.tag =~ "(?i).*romney.*"> RETURN count(*) as cnt, tag1.tag,tag2.tag> ORDER BY count(*) DESC> LIMIT 10;

4

+--------------------------------------+| cnt | tag1.tag | tag2.tag |+--------------------------------------+| 440 | "obama" | "voteromney" || 148 | "obama" | "romneyryan2012" || 65 | "obama" | "romney" || 56 | "voteobama" | "romneyryan" || 42 | "voteobama" | "romney" |+--------------------------------------+5 rows194 ms

Mittwoch, 11. September 13

Page 99: Real World Applications with Spring Data Neo4j

Real World Use-Cases with

Mittwoch, 11. September 13

Page 100: Real World Applications with Spring Data Neo4j

(Neo4j) -[:LOVES]-> (Our Customers)

52Mittwoch, 11. September 13

Page 101: Real World Applications with Spring Data Neo4j

(Neo4j) -[:LOVES]-> (Our Customers)

52Mittwoch, 11. September 13

Page 102: Real World Applications with Spring Data Neo4j

• hard to get permission to talk in public• complex domain models, challenging implementations• hard to get insights in implementation• challenges / feedback seldomly communicated

• this presentation is a „best effort“ mix of – actual,– inferred,– adapted information

Challenges with „Real World Use-Cases“

53Mittwoch, 11. September 13

Page 103: Real World Applications with Spring Data Neo4j

Airline: Media Asset Management

54Mittwoch, 11. September 13

Page 104: Real World Applications with Spring Data Neo4j

• Many movies, music, tv-series• Each of them with publishers, publication rights• Permissions, Broadcasting rules• Asset Management/Tracking

– also technical components, virtual containers• Streaming Box Management (What is where, Documentation)• Impact analytics of legal changes or program updates• Decision support system• Complex domain model

Airline: Media Asset Management

55Mittwoch, 11. September 13

Page 105: Real World Applications with Spring Data Neo4j

• Neo4j Embedded• SDN Advanced Mapping• REST Server with Spring WebMVC• Thymeleaf• Rich UI with

– CRUD for all 50 elements– dependency network visualization, with interactive navigation– advanced query generator / console

Airline: Media Asset Management (Technical)

56Mittwoch, 11. September 13

Page 106: Real World Applications with Spring Data Neo4j

Airline: Media Asset Management

57

Media-Box

Aircraft

Aircraft

TV-Series

Movie

Media-Box Recording

Metadata

Metadata

APPL

IES_

TOA

PP

LIE

S_T

O

INSTALLED

INST

ALLE

D

Route

Airport AirportCountry

REGULATES

Metadata

STO

RE

D_O

N

Mittwoch, 11. September 13

Page 107: Real World Applications with Spring Data Neo4j

Airline: Media Asset Management

58Mittwoch, 11. September 13

Page 108: Real World Applications with Spring Data Neo4j

Airline: Media Asset Management

58Mittwoch, 11. September 13

Page 109: Real World Applications with Spring Data Neo4j

Airline: Media Asset Management

58Mittwoch, 11. September 13

Page 110: Real World Applications with Spring Data Neo4j

Airline: Media Asset Management

58Mittwoch, 11. September 13

Page 111: Real World Applications with Spring Data Neo4j

Airline: Media Asset Management

58Mittwoch, 11. September 13

Page 112: Real World Applications with Spring Data Neo4j

Junisphere: Complex structural document handling

59Mittwoch, 11. September 13

Page 113: Real World Applications with Spring Data Neo4j

• Business proccess to IT systems mapping (Exec View)• Conways Law

– Business Process Structure resembles Information Architecture it runs on

• Map and trace both–Initial and continous updates

• Optimize both sides–Servers and Services

• http://www.neotechnology.com/junispheres-usecase/

Junisphere: Complex structural document handling

60Mittwoch, 11. September 13

Page 114: Real World Applications with Spring Data Neo4j

Junisphere: Complex structural document handling

61

•Junisphere AG is a Zurich-based IT solutions provider

•Founded in 2001. Profitable. Self funded.

•Software & services.

•Novel approach to infrastructure monitoring: Starts with the end user, mapped to business processes and services, and dependent infrastructure

Mittwoch, 11. September 13

Page 115: Real World Applications with Spring Data Neo4j

Junisphere: Complex structural document handling

62

•“Business Service Management” requires mapping of complex graph, covering: business processes--> business services--> IT infrastructure

•Embed capability of storing and retrieving this information into OEM application

•Re-architecting outdated C++ application based on relational database, with Java

Mittwoch, 11. September 13

Page 116: Real World Applications with Spring Data Neo4j

Junisphere: Complex structural document handling

63

•Actively sought out a Java-based solution that could store data as a graph

•Domain model is reflected directly in the database:

•“No time lost in translation”

•“Our business and enterprise consultants now speak the same language, and can model the domain with the database on a 1:1 ratio.”

•Spring Data Neo4j strong fit for Java architecture

Mittwoch, 11. September 13

Page 117: Real World Applications with Spring Data Neo4j

• dictionary contents is created by many parties• for each contribution you have to track the contracts

Publisher: Dictionary Translation Contract Handling

64Mittwoch, 11. September 13

Page 118: Real World Applications with Spring Data Neo4j

• Java Embedded Neo4j• Spring Data Neo4j• Integrated in Java Service Architecture• XML-Editor• Device/HW-Scanners report back model changes• Models are trees/networks,

– need to merge model-updates – with inferred updates/deltas from full models

Junisphere: eReality (technical)

65Mittwoch, 11. September 13

Page 119: Real World Applications with Spring Data Neo4j

66

DEFINES

Process

DEPENDS_ON

Activity

Service

Process

Activity

DEPENDS_ON

Flow Model

Device

KPI

KPI

RELATES_TO

DeviceFLOWS_TO

Function

DEPENDS_ON

RUNS_ON

KPI

DEPENDS_ON

Junisphere: eReality (Model)

Mittwoch, 11. September 13

Page 120: Real World Applications with Spring Data Neo4j

67

Our requirements> Convenient modelling of our domain

> Pushing states from measurements in "real time" through the model (1000 times/s)

> Versioning of the model

> Multi tenancy support

> Different views of the same model− Availability, performance, etc. views

> Referencing properties of objects from other objects

Mittwoch, 11. September 13

Page 121: Real World Applications with Spring Data Neo4j

67

Our requirements> Convenient modelling of our domain

> Pushing states from measurements in "real time" through the model (1000 times/s)

> Versioning of the model

> Multi tenancy support

> Different views of the same model− Availability, performance, etc. views

> Referencing properties of objects from other objects

Perfect fit

Mittwoch, 11. September 13

Page 122: Real World Applications with Spring Data Neo4j

67

Our requirements> Convenient modelling of our domain

> Pushing states from measurements in "real time" through the model (1000 times/s)

> Versioning of the model

> Multi tenancy support

> Different views of the same model− Availability, performance, etc. views

> Referencing properties of objects from other objects

Perfect fit

Proof of concept app with 2000 traversals/s

Mittwoch, 11. September 13

Page 123: Real World Applications with Spring Data Neo4j

67

Our requirements> Convenient modelling of our domain

> Pushing states from measurements in "real time" through the model (1000 times/s)

> Versioning of the model

> Multi tenancy support

> Different views of the same model− Availability, performance, etc. views

> Referencing properties of objects from other objects

Perfect fit

Proof of concept app with 2000 traversals/s

Proof of concept solution delivered by neo4j-team

Mittwoch, 11. September 13

Page 124: Real World Applications with Spring Data Neo4j

67

Our requirements> Convenient modelling of our domain

> Pushing states from measurements in "real time" through the model (1000 times/s)

> Versioning of the model

> Multi tenancy support

> Different views of the same model− Availability, performance, etc. views

> Referencing properties of objects from other objects

Perfect fit

Proof of concept app with 2000 traversals/s

Proof of concept solution delivered by neo4j-teamDone with indices per tenant and filtering traversal results

Mittwoch, 11. September 13

Page 125: Real World Applications with Spring Data Neo4j

67

Our requirements> Convenient modelling of our domain

> Pushing states from measurements in "real time" through the model (1000 times/s)

> Versioning of the model

> Multi tenancy support

> Different views of the same model− Availability, performance, etc. views

> Referencing properties of objects from other objects

Perfect fit

Proof of concept app with 2000 traversals/s

Proof of concept solution delivered by neo4j-teamDone with indices per tenant and filtering traversal resultsFeasible

Mittwoch, 11. September 13

Page 126: Real World Applications with Spring Data Neo4j

67

Our requirements> Convenient modelling of our domain

> Pushing states from measurements in "real time" through the model (1000 times/s)

> Versioning of the model

> Multi tenancy support

> Different views of the same model− Availability, performance, etc. views

> Referencing properties of objects from other objects

Perfect fit

Proof of concept app with 2000 traversals/s

Proof of concept solution delivered by neo4j-teamDone with indices per tenant and filtering traversal resultsFeasible

Storing the properties in its own nodes

Mittwoch, 11. September 13

Page 127: Real World Applications with Spring Data Neo4j

WhyOwnIt - Ownership Sharing Service

68Mittwoch, 11. September 13

Page 128: Real World Applications with Spring Data Neo4j

• Sharing Culture –You own things you only seldomly need–You need things you don‘t own

• Match needs and available devices/tools– add ratings, trust, recommendations– location based, close to you for pick-up

• Startup

WhyOwnIt - Ownership Sharing Service

69Mittwoch, 11. September 13

Page 129: Real World Applications with Spring Data Neo4j

WhyOwnIt - Ownership Sharing Service

70

Thing

Person

Category

Person

Person

HAS

OWNSCategory

NEEDS

TRUST

Person

RATED

RATED

ThingOWNS

Mittwoch, 11. September 13

Page 130: Real World Applications with Spring Data Neo4j

WhyOwnIt - Ownership Sharing Service

71Mittwoch, 11. September 13

Page 131: Real World Applications with Spring Data Neo4j

WhyOwnIt - Ownership Sharing Service

71Mittwoch, 11. September 13

Page 132: Real World Applications with Spring Data Neo4j

WhyOwnIt - Ownership Sharing Service

71Mittwoch, 11. September 13

Page 133: Real World Applications with Spring Data Neo4j

WhyOwnIt - Ownership Sharing Service

71Mittwoch, 11. September 13

Page 134: Real World Applications with Spring Data Neo4j

WhyOwnIt - Ownership Sharing Service

71Mittwoch, 11. September 13

Page 135: Real World Applications with Spring Data Neo4j

WhyOwnIt - Ownership Sharing Service

71Mittwoch, 11. September 13

Page 136: Real World Applications with Spring Data Neo4j

WhyOwnIt - Ownership Sharing Service

72Mittwoch, 11. September 13

Page 137: Real World Applications with Spring Data Neo4j

• Classical Pay and Win Games (Poker & Co)• Spring-Web-App with Oracle backend• Add Social

– Referral System with complex rules for inferred bonuses– Multi-Level Buddy-System– Prevent Fraud– Add more social functions on top (Groups)– Recommendations

• http://www.neotechnology.com/gamesys/

Gamesys - Add Social to Gaming

73Mittwoch, 11. September 13

Page 138: Real World Applications with Spring Data Neo4j

Gamesys - Add Social to Gaming

74

Player

PLAYS

Game

Round

Player

PLAY

S

Player

BUDDY

Player

Player Player

BUDDYBUDDY

REFERS

REFERSBUDDY

Mittwoch, 11. September 13

Page 139: Real World Applications with Spring Data Neo4j

Music Sharing/Discovery/Recommendation Service

75Mittwoch, 11. September 13

Page 140: Real World Applications with Spring Data Neo4j

• Recommend new artists and songs to your users– take their previous listen-history into account– look at what‘s hot amongst their friends– infer broader selection via bands and genres

• Detect duplicates using media-fingerprints– copyright infringements– de-duplicate data

Music Sharing/Discovery/Recommendation Service

76Mittwoch, 11. September 13

Page 141: Real World Applications with Spring Data Neo4j

Music Sharing/Discovery/Recommendation Service

77

Song

Artist

Band

Label

Song

Song

Artist Song

User

User

BYLISTENED

FOLLOWS

RAT

ED

BYPU

BLIS

HESW

ORKS_W

ITH

Mittwoch, 11. September 13

Page 142: Real World Applications with Spring Data Neo4j

Music Sharing/Discovery/Recommendation Service

78Mittwoch, 11. September 13

Page 143: Real World Applications with Spring Data Neo4j

• Financial Services - Asset / Account Management• Bank - Permission Management and Authorization

– Entitlement• Data Software Provider - Impact analysis of changes

– Implication of changes on the company core asset: DATA– Change tracking– Root Cause Analysis

Other Use-Cases

79Mittwoch, 11. September 13

Page 144: Real World Applications with Spring Data Neo4j

• Networked Storage Boxes– many components, disks, controllers, power supply, sensors

• Tracking of measurement data• Impact analytics• Early detection of anomalies• Intelligent fail over• Huge number of domain entities (~450)

– generating domain classes and repositories

SAN/NAS Provider - Lifetime device tracking

80Mittwoch, 11. September 13

Page 145: Real World Applications with Spring Data Neo4j

• Buy and Download & Game on Demand• Fraud detection

–delayed payments, charge backs, fradulent keys are invalid• Convert rules to traversals

–co-occurrance of sudden large sales–fradulent e-mail patterns

• Combination with Oracle Infrastructure• Cross-Store

Game Retailer

81Mittwoch, 11. September 13

Page 146: Real World Applications with Spring Data Neo4j

Open Source Projects

82Mittwoch, 11. September 13

Page 147: Real World Applications with Spring Data Neo4j

Cineasts.net - a social movie database

Check Out: http://spring.neo4j.org/tutorial

Mittwoch, 11. September 13

Page 148: Real World Applications with Spring Data Neo4j

Spring Data Neo4j Guidebook“Good Relationships”

- 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

“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

Mittwoch, 11. September 13

Page 149: Real World Applications with Spring Data Neo4j

Spring Data Neo4j Guidebook“Good Relationships”

- 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

“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

Mittwoch, 11. September 13

Page 150: Real World Applications with Spring Data Neo4j

• Boston Bike Sharing Network• Import using Spring Data Neo4j• Visualization with Cypher & d3.js (Chord)

Hubway Data Challenge - Import

http://bit.ly/neo_hubway85

Mittwoch, 11. September 13

Page 151: Real World Applications with Spring Data Neo4j

Agent Spring - Energy Market Modeling

86Mittwoch, 11. September 13

Page 152: Real World Applications with Spring Data Neo4j

• Research project (open source)• Model energy producers and consumers• Trace dependencies, prices, usage, demands, market

activities• Simulate impact of changes over the course of several years• Sustainable energy vs. nuclear,

private usage vs. industry demand• Used in Latvia for decision making in energy politics

Agent Smith - Energy Market Modeling

87

https://github.com/alfredas/AgentSpring

Mittwoch, 11. September 13

Page 153: Real World Applications with Spring Data Neo4j

How do I get started?

4Mittwoch, 11. September 13

Page 154: Real World Applications with Spring Data Neo4j

How do I get started?

4

๏ Documentation

Mittwoch, 11. September 13

Page 155: Real World Applications with Spring Data Neo4j

How do I get started?

4

๏ Documentation

• http://spring.neo4j.org

Mittwoch, 11. September 13

Page 156: Real World Applications with Spring Data Neo4j

How do I get started?

4

๏ Documentation

• http://spring.neo4j.org

• Developer-Notes

Mittwoch, 11. September 13

Page 157: Real World Applications with Spring Data Neo4j

How do I get started?

4

๏ Documentation

• http://spring.neo4j.org

• Developer-Notes

• Spring Data Book

Mittwoch, 11. September 13

Page 158: Real World Applications with Spring Data Neo4j

How do I get started?

4

๏ Documentation

• http://spring.neo4j.org

• Developer-Notes

• Spring Data Book

• Good Relationships

Mittwoch, 11. September 13

Page 159: Real World Applications with Spring Data Neo4j

How do I get started?

4

๏ Documentation

• http://spring.neo4j.org

• Developer-Notes

• Spring Data Book

• Good Relationships

๏ Get Neo4j

Mittwoch, 11. September 13

Page 160: Real World Applications with Spring Data Neo4j

How do I get started?

4

๏ Documentation

• http://spring.neo4j.org

• Developer-Notes

• Spring Data Book

• Good Relationships

๏ Get Neo4j

• http://neo4j.org/download

Mittwoch, 11. September 13

Page 161: Real World Applications with Spring Data Neo4j

How do I get started?

4

๏ Documentation

• http://spring.neo4j.org

• Developer-Notes

• Spring Data Book

• Good Relationships

๏ Get Neo4j

• http://neo4j.org/download

๏ Participate

Mittwoch, 11. September 13

Page 162: Real World Applications with Spring Data Neo4j

How do I get started?

4

๏ Documentation

• http://spring.neo4j.org

• Developer-Notes

• Spring Data Book

• Good Relationships

๏ Get Neo4j

• http://neo4j.org/download

๏ Participate

• http://neo4j.org/forums

Mittwoch, 11. September 13

Page 163: Real World Applications with Spring Data Neo4j

How do I get started?

4

๏ Documentation

• http://spring.neo4j.org

• Developer-Notes

• Spring Data Book

• Good Relationships

๏ Get Neo4j

• http://neo4j.org/download

๏ Participate

• http://neo4j.org/forums

• http://spring.neo4j.org/discussions

Mittwoch, 11. September 13

Page 164: Real World Applications with Spring Data Neo4j

How do I get started?

4

๏ Documentation

• http://spring.neo4j.org

• Developer-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

Mittwoch, 11. September 13

Page 165: Real World Applications with Spring Data Neo4j

How do I get started?

4

๏ Documentation

• http://spring.neo4j.org

• Developer-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 ;)

Mittwoch, 11. September 13

Page 166: Real World Applications with Spring Data Neo4j

The book on your seat! -“Graph Databases”

• The definitive guide on graph databases• discusses graph concepts, history and data model• compares with other NoSQL technologies• details use-cases from different domains• explains Neo4j‘s humane query language „Cypher“

Written by experts - Emil Eifrem, Ian Robinson, Jim WebberCompliments of Neo Technology

Mittwoch, 11. September 13

Page 167: Real World Applications with Spring Data Neo4j

Bookmark: GraphConnect Oct 3-4 2013 San Francisco

4

$99 ticket coupon in your book

Mittwoch, 11. September 13

Page 168: Real World Applications with Spring Data Neo4j

91

• Wed, Sep 11, 6-9PM• David's Restaurant,

5151 Stars and Stripes Drive• Just around the corner• Enjoy dessert, wine, beer• Chance to win a signed

Spring Data Book

Meetup - Tomorrow (Wed) EveningSpring Data Neo4j: Past, Current & Future

http://www.meetup.com/graphdb-sf/events/138428012/

Mittwoch, 11. September 13

Page 169: Real World Applications with Spring Data Neo4j

Thank you !Questions ?

Mittwoch, 11. September 13