1
Introduction to
             Neo4j
Michael Hunger
@mesirii
#neo4j
                          2
Introduction to
             Neo4j
Michael Hunger
@mesirii
#neo4j
                          2
Neo4j




        Introduction to
             Neo4j
Michael Hunger
@mesirii
#neo4j
                          2
2
(Michael) -[:WORKS_ON]-> (Neo4j)
                                         console


Cypher             community
                     graph
                                   Community

                     ME

Server


          Spring               Cloud


                                               3
4
The Path Forward




                   4
The Path Forward

1.No .. NO .. NOSQL




                         4
The Path Forward

1.No .. NO .. NOSQL
2.Why graphs?




                         4
The Path Forward

1.No .. NO .. NOSQL
2.Why graphs?
3.What's a graph database?




                             4
The Path Forward

1.No .. NO .. NOSQL
2.Why graphs?
3.What's a graph database?
4.Some things about Neo4j.



                             4
The Path Forward

1.No .. NO .. NOSQL
2.Why graphs?
3.What's a graph database?
4.Some things about Neo4j.
5.How do people use Neo4j?

                             4
NOSQL




        5
NOSQL       Neo4j




        5
Neo4j




5
What is NOSQL?




                 6
What is NOSQL?




                 6
What is NOSQL?

   It’s not “No to SQL”




                          6
What is NOSQL?

   It’s not “No to SQL”
                          It’s not “Never SQL”




                                                 6
What is NOSQL?

   It’s not “No to SQL”
                           It’s not “Never SQL”


         It’s “Not        Only SQL”




                                                  6
What is NOSQL?

   It’s not “No to SQL”
                             It’s not “Never SQL”


         It’s “Not        Only SQL”
   NOSQL no-seek-wool n. Describes ongoing
   trend where developers increasingly opt for
   non-relational databases to help solve their
   problems, in an effort to use the right tool for
   the right job.


                                                      6
NOSQL Databases
 Riak


                                                    Couch
  KeyValue

Redis                                   Document

                          NOSQL                 Mongo


    Column
    oriented
                                   Graph    Neo4j

Cassandra           Relational
            MySQL
                             Postgres               7
8
Living in a NOSQL World




                          8
Living in a NOSQL World




        Volume ~= Size


                          8
Living in a NOSQL World
Density ~= Complexity




                                Volume ~= Size


                                                  8
Living in a NOSQL World
Density ~= Complexity




                                                 Key-Value
                                                   Store




                                Volume ~= Size


                                                             8
Living in a NOSQL World
Density ~= Complexity




                                             Column
                                             Family

                                                      Key-Value
                                                        Store




                                Volume ~= Size


                                                                  8
Living in a NOSQL World
Density ~= Complexity




                                    Document
                                    Databases




                                                Column
                                                Family

                                                         Key-Value
                                                           Store




                                Volume ~= Size


                                                                     8
Living in a NOSQL World

                              RDBMS
Density ~= Complexity




                                      Document
                                      Databases




                                                  Column
                                                  Family

                                                           Key-Value
                                                             Store




                                 Volume ~= Size


                                                                       8
Living in a NOSQL World
                                Graph
                              Databases


                               RDBMS
Density ~= Complexity




                                          Document
                                          Databases




                                                      Column
                                                      Family

                                                               Key-Value
                                                                 Store




                                    Volume ~= Size


                                                                           8
Living in a NOSQL World
                                 Graph
                               Databases


                                RDBMS
Density ~= Complexity




                                           Document
                                           Databases




                                                       Column
                                                       Family

                                                                Key-Value
                                                                  Store




                  90%                Volume ~= Size
                   of
                  use
                 cases
                                                                            8
Living in a NOSQL World
                                     Graph
                                   Databases


                                    RDBMS
Density ~= Complexity




                                               Document
                                               Databases




                                                           Column
                                                           Family

                                                                    Key-Value
                                                                      Store




                            90%          Volume ~= Size
                             of
                            use
                           cases
                                                                                8
Trends in BigData & NOSQL
 1. increasing data size (big data)

  • “Every 2 -days we create as much information as we did up to
      2003” Eric Schmidt
 2. increasingly connected data (graph data)

  • for example, text documents to html
 3. semi-structured data

  • individualization of data, with common sub-set
 4. architecture - a facade over multiple services

  • from monolithic to modular, distributed applications
                                                            9
10
A Graph?


           10
A Graph?
Yes, a graph

               10
They are everywhere




     Flight Patterns in Europe
                                 11
Graphs Everywhere
 ๏ Relationships in
    • Politics, Economics, History, Science,Transportation
 ๏ Biology, Chemistry, Physics, Sociology
    • Body, Ecosphere, Reaction, Interactions
 ๏ Internet
    • Hardware, Software, Interaction
 ๏ Social Networks
    • Family, Friends
    • Work, Communities
    • Neighbours, Cities, Society                            12
Good Relationships

๏ the world is rich, messy and related data
๏ relationships are as least as important as the things they connect
๏ Graphs = Whole > Σ parts
๏ complex interactions
๏ always changing, change of structures as well
๏ Graph: Relationships are part of the data
๏ RDBMS: Relationships part of the fixed schema



                                                                13
Questions and Answers

๏ Complex Questions
๏ Answers lie between the lines (things)
๏ Locality of the information
๏ Global searches / operations very expensive
๏ constant query time, regardless of data volume




                                                   14
Categories ?

๏ Categories == Classes, Trees ?
๏ What if more than one category fits?
๏ Tags
๏ Categories vi relationships like „IS_A“
๏ any number, easy change
๏ „virtual“ Relationships - Traversals
๏ Category dynamically derived from queries



                                              15
Fowler & Christakis „Connected“




                                  16
New York Times R&D „Cascade“




                               17
Deb Roy - MIT & Bluefin Labs


                    „Birth of a Word“ TED Talk

                    Researches Social Reactions
                    to (Media) Events




                                                  18
19
Everyone is talking about graphs...




                                      19
Everyone is talking about graphs...




Facebook Open Graph




                                      19
Everyone is talking about graphs...




Facebook Open Graph




                                      19
20
Each of us has not only one graph, but many!




                                          20
Graph DB 101


               21
A graph database...




                      22
A graph database...

 NO: not for charts & diagrams, or vector artwork




                                                    22
A graph database...

 NO: not for charts & diagrams, or vector artwork
 YES: for storing data that is structured as a graph




                                                       22
A graph database...

 NO: not for charts & diagrams, or vector artwork
 YES: for storing data that is structured as a graph
    remember linked lists, trees?




                                                       22
A graph database...

 NO: not for charts & diagrams, or vector artwork
 YES: for storing data that is structured as a graph
    remember linked lists, trees?
    graphs are the general-purpose data structure




                                                       22
A graph database...

 NO: not for charts & diagrams, or vector artwork
 YES: for storing data that is structured as a graph
    remember linked lists, trees?
    graphs are the general-purpose data structure
 “A relational database may tell you the average age of everyone
    in this session,
 but a graph database will tell you who is most likely to buy you a
    beer.”



                                                                      22
23
You know relational




                      23
You know relational




                      23
You know relational




            foo

                      23
You know relational




            foo       bar

                            23
You know relational




            foo       foo_bar   bar

                                      23
You know relational




            foo       foo_bar   bar

                                      23
You know relational




            foo       foo_bar   bar

                                      23
You know relational




            foo       foo_bar   bar

                                      23
You know relational
now consider relationships...




                                23
You know relational
now consider relationships...




                                23
You know relational
now consider relationships...




                                23
You know relational
now consider relationships...




                                23
You know relational
now consider relationships...




                                23
You know relational
now consider relationships...




                                23
23
24
We're talking about a
Property Graph




                        24
We're talking about a
Property Graph


     Nodes




                        24
We're talking about a
Property Graph


     Nodes


      Relationships




                        24
We're talking about a
Property Graph
                                             Em                                       Joh
                                                  il                                      a   n
                                   knows                                     knows
                      Alli                                         Tob                                    Lar

     Nodes
                             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

      Relationships

             Properties (each a key+value)

        + Indexes (for easy look-ups)
                                                                                                                  24
24
25
Looks different, fine. Who cares?




                                   25
Looks different, fine. Who cares?
๏ a sample social graph




                                   25
Looks different, fine. Who cares?
๏ a sample social graph
   • with ~1,000 persons




                                   25
Looks different, fine. Who cares?
๏ a sample social graph
   • with ~1,000 persons
๏ average 50 friends per person




                                   25
Looks different, fine. Who cares?
๏ a sample social graph
   • with ~1,000 persons
๏ average 50 friends per person
๏ pathExists(a,b) limited to depth 4




                                       25
Looks different, fine. Who cares?
๏ 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




                                           25
Looks different, fine. Who cares?
๏ 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

                                                                25
Looks different, fine. Who cares?
๏ 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

                                                                25
Looks different, fine. Who cares?
๏ 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

                                                                25
25
Graph Database: Pros & Cons
๏ Strengths
   • Powerful data model, as general as RDBMS
   • Fast, for connected data
   • Easy to query
๏ Weaknesses:
   • Sharding (though they can scale reasonably well)
      ‣also, stay tuned for developments here
   • Requires conceptual shift
      ‣though graph-like thinking becomes addictive

                                                        26
27
And, but, so how do you
query this "graph" database?



                         27
28
Query a graph with a traversal




                                 28
Query a graph with a traversal




                                 28
Query a graph with a traversal
// lookup starting point in an index
start n=node:People(name = ‘Andreas’)




                        And
                              rea
                                    s




                                        28
Query a graph with a traversal
// lookup starting point in an index
   then traverse to find results
start n=node:People(name = ‘Andreas’)
  match (n)--()--(foaf) return foaf




                        And
                              rea
                                    s




                                        28
28
Neo4j - the Graph Database




                       29
30
(Neo4j) -[:IS_A]-> (Graph Database)
                                                                                                    Lucene
Sharding                                      1 M/s

        Master/
                                                                                         Index




                                                      LS
         Slave




                                              TRAVERSA
                          HIG
                                                                    TES
                              H_A
                                 VA                               RA
                                                                 G
                                    IL.                       TE
                                                           IN
                                                                   PROVIDES                        ACID
        Server     RUN
                       S_A                                        LI                                TX
                          S                                         CE
                                                                         NS
                                                                              ED
                                                                                   _L
                                    ES_T
 Ruby                                                                                 IK



                                                           RU
            JS                                                                           E
                                                                                                 MySQL
                      S
                    _A




                                                             NS
                                  SC AL

                                          O

Clojure


                                                             _O
                    NS




           .net
                  RU




                                                               N                             Mongo
                            34bn
     embedded                                                     Heroku
                            Nodes                                                                   31
Neo4j is a Graph Database




                            32
Neo4j is a Graph Database
๏ A Graph Database:




                            32
Neo4j is a Graph Database
๏ A Graph Database:
   • a schema-free Property Graph




                                    32
Neo4j is a Graph Database
๏ A Graph Database:
   • a schema-free Property Graph
   • perfect for complex, highly connected data




                                                  32
Neo4j is a Graph Database
๏ A Graph Database:
   • a schema-free Property Graph
   • perfect for complex, highly connected data
๏ A Graph Database:




                                                  32
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



                                                  32
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: 32 Billion Nodes, 32 Billion Relationships, 64 Billion
       Properties




                                                                 32
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: 32 Billion Nodes, 32 Billion Relationships, 64 Billion
        Properties

   • fast with more than 1M traversals / second

                                                                 32
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: 32 Billion Nodes, 32 Billion Relationships, 64 Billion
        Properties

   • fast with more than 1M traversals / second
   • Server with REST API, or Embeddable on the JVM
                                                                 32
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: 32 Billion Nodes, 32 Billion Relationships, 64 Billion
        Properties

   • fast with more than 1M traversals / second
   • Server with REST API, or Embeddable on the JVM
   • higher-performance with High-Availability (read scaling)    32
Whiteboard --> Data




                      33
Whiteboard --> Data

                           Peter
          Andreas




                                   Allison

                    Emil




                                             33
Whiteboard --> Data

                                  Peter
          Andreas   knows


               knows          knows
                                              Allison
                                      knows
                       Emil




                                                        33
Whiteboard --> Data

                                  Peter
          Andreas   knows


               knows          knows
                                              Allison
                                      knows
                       Emil




                                                        33
Whiteboard --> Data

                                  Peter
          Andreas   knows


               knows          knows
                                              Allison
                                      knows
                       Emil




      // Cypher query - friend of a friend
      start n=node(0)
      match (n)--()--(foaf)
      return foaf

                                                        33
34
Two Ways to Work with Neo4j




                              34
Two Ways to Work with Neo4j
๏ 1. Embeddable on JVM




                              34
Two Ways to Work with Neo4j
๏ 1. Embeddable on JVM
   • Java, JRuby, Scala...




                              34
Two Ways to Work with Neo4j
๏ 1. Embeddable on JVM
   • Java, JRuby, Scala...
   • Tomcat, Rails, Akka, etc.




                                 34
Two Ways to Work with Neo4j
๏ 1. Embeddable on JVM
   • Java, JRuby, Scala...
   • Tomcat, Rails, Akka, etc.
   • great for testing




                                 34
Two Ways to Work with Neo4j
๏ 1. Embeddable on JVM
   • Java, JRuby, Scala...
   • Tomcat, Rails, Akka, etc.
   • great for testing




                                 34
Two Ways to Work with Neo4j
๏ 1. Embeddable on JVM
   • Java, JRuby, Scala...
   • Tomcat, Rails, Akka, etc.
   • great for testing




                                 34
Two Ways to Work with Neo4j
๏ 1. Embeddable on JVM
   • Java, JRuby, Scala...
   • Tomcat, Rails, Akka, etc.
   • great for testing




                                 34
Two Ways to Work with Neo4j
๏ 1. Embeddable on JVM
   • Java, JRuby, Scala...
   • Tomcat, Rails, Akka, etc.
   • great for testing




                                 34
Two Ways to Work with Neo4j
๏ 1. Embeddable on JVM
   • Java, JRuby, Scala...
   • Tomcat, Rails, Akka, etc.
   • great for testing




                                 34
Two Ways to Work with Neo4j




                              34
Show me some code, please
  GraphDatabaseService graphDb =
     new EmbeddedGraphDatabase(“var/neo4j”);
  Transaction tx = graphDb.beginTx();
  try {
    Node steve = graphDb.createNode();
    Node michael = graphDb.createNode();

    steve.setProperty(“name”, “Steve Vinoski”);
    michael.setProperty(“name”, “Michael Hunger”);

    Relationship presentedWith = steve.createRelationshipTo(
    michael, PresentationTypes.PRESENTED_WITH);
    presentedWith.setProperty(“date”, today);
    tx.success();
  } finally {
    tx.finish();
  }
Spring Data Neo4j
  @NodeEntity
  public class Movie {
    @Indexed private String title;
    @RelatedToVia(type = “ACTS_IN”, direction=INCOMING)
    private Set<Role> cast;
    private Director director;
  }


  @NodeEntity
  public class Actor {
    @RelatedTo(type = “ACTS_IN”)
    private Set<Movies> movies;
  }


  @RelationshipEntity
  public class Role {
    @StartNode private Actor actor;
    @EndNode private Movie movie;
    private String roleName;
  }
neo4j.rb
    gem install neo4j

  require 'rubygems'
  require 'neo4j'

  class Person
    include Neo4j::NodeMixin
    property :name, :age, :rank
    index :name
    has_n :friends
  end

  Neo4j::Transaction.run do
    neo = Person.new :name=>'Neo', :age=>29
    morpheus =
  Person.new :name=>'Morpheus', :rank=>'Captain'
    neo.friends << morpheus
  end

  neo.friends.each {|p|...}
Cypher Query Language
๏ Declarative query language
   • Describe what you want, not how
   • Based on pattern matching
๏ Examples:
   START david=node:people(name=”David”)   # index lookup
   MATCH david-[:knows]-friends-[:knows]-new_friends
   WHERE new_friends.age > 18
   RETURN new_friends

   START user=node(5, 15, 26, 28)   # node IDs
   MATCH user--friend
   RETURN user, COUNT(friend), SUM(friend.money)




                                                            38
Create Graph with Cypher




  CREATE
    (steve {name: “Steve Vinoski”})
      -[:PRESENTED_WITH {date:{day}}]->
    (michael {name: “Michael Hunger”})
Two Ways to Work with Neo4j




                              40
Two Ways to Work with Neo4j
๏ 2. Server with REST API




                              40
Two Ways to Work with Neo4j
๏ 2. Server with REST API
   • every language on the planet




                                    40
Two Ways to Work with Neo4j
๏ 2. Server with REST API
   • every language on the planet
   • flexible deployment scenarios




                                    40
Two Ways to Work with Neo4j
๏ 2. Server with REST API
   • every language on the planet
   • flexible deployment scenarios
   • DIY server, or cloud managed




                                    40
Two Ways to Work with Neo4j
๏ 2. Server with REST API
   • every language on the planet
   • flexible deployment scenarios
   • DIY server, or cloud managed




                                    40
Two Ways to Work with Neo4j
๏ 2. Server with REST API
   • every language on the planet
   • flexible deployment scenarios
   • DIY server, or cloud managed




                                    40
Two Ways to Work with Neo4j
๏ 2. Server with REST API
   • every language on the planet
   • flexible deployment scenarios
   • DIY server, or cloud managed




                                    40
Two Ways to Work with Neo4j
๏ 2. Server with REST API
   • every language on the planet
   • flexible deployment scenarios
   • DIY server, or cloud managed




                                    40
Two Ways to Work with Neo4j




                              40
Bindings

           REST://




                     41
Two Ways to Work with Neo4j




                              42
Two Ways to Work with Neo4j
๏ Server capability == Embedded capability




                                             42
Two Ways to Work with Neo4j
๏ Server capability == Embedded capability
   • same scalability, transactionality, and availability




                                                            42
Two Ways to Work with Neo4j
๏ Server capability == Embedded capability
   • same scalability, transactionality, and availability




                                                            42
Two Ways to Work with Neo4j
๏ Server capability == Embedded capability
   • same scalability, transactionality, and availability




                                                            42
42
How to get started?




                      43
How to get started?
๏ Documentation




                      43
How to get started?
๏ Documentation
    • docs.neo4j.org - tutorials+reference




                                             43
How to get started?
๏ Documentation
    • docs.neo4j.org - tutorials+reference
    • Neo4j in Action




                                             43
How to get started?
๏ Documentation
    • docs.neo4j.org - tutorials+reference
    • Neo4j in Action
    • Good Relationships




                                             43
How to get started?
๏ Documentation
    • docs.neo4j.org - tutorials+reference
    • Neo4j in Action
    • Good Relationships
๏ Get Neo4j




                                             43
How to get started?
๏ Documentation
    • docs.neo4j.org - tutorials+reference
    • Neo4j in Action
    • Good Relationships
๏ Get Neo4j
    • http://neo4j.org/download




                                             43
How to get started?
๏ Documentation
    • docs.neo4j.org - tutorials+reference
    • Neo4j in Action
    • Good Relationships
๏ Get Neo4j
    • http://neo4j.org/download
    • http://addons.heroku.com/neo4j/




                                             43
How to get started?
๏ Documentation
    • docs.neo4j.org - tutorials+reference
    • Neo4j in Action
    • Good Relationships
๏ Get Neo4j
    • http://neo4j.org/download
    • http://addons.heroku.com/neo4j/
๏ Participate
    • http://groups.google.com/group/neo4j
    • http://neo4j.meetup.com
    • a session like this one ;)
                                             43
Thank you!


             44

Intro to Neo4j presentation

  • 1.
  • 2.
    Introduction to Neo4j Michael Hunger @mesirii #neo4j 2
  • 3.
    Introduction to Neo4j Michael Hunger @mesirii #neo4j 2
  • 4.
    Neo4j Introduction to Neo4j Michael Hunger @mesirii #neo4j 2
  • 5.
  • 6.
    (Michael) -[:WORKS_ON]-> (Neo4j) console Cypher community graph Community ME Server Spring Cloud 3
  • 7.
  • 8.
  • 9.
    The Path Forward 1.No.. NO .. NOSQL 4
  • 10.
    The Path Forward 1.No.. NO .. NOSQL 2.Why graphs? 4
  • 11.
    The Path Forward 1.No.. NO .. NOSQL 2.Why graphs? 3.What's a graph database? 4
  • 12.
    The Path Forward 1.No.. NO .. NOSQL 2.Why graphs? 3.What's a graph database? 4.Some things about Neo4j. 4
  • 13.
    The Path Forward 1.No.. NO .. NOSQL 2.Why graphs? 3.What's a graph database? 4.Some things about Neo4j. 5.How do people use Neo4j? 4
  • 14.
  • 15.
    NOSQL Neo4j 5
  • 16.
  • 17.
  • 18.
  • 19.
    What is NOSQL? It’s not “No to SQL” 6
  • 20.
    What is NOSQL? It’s not “No to SQL” It’s not “Never SQL” 6
  • 21.
    What is NOSQL? It’s not “No to SQL” It’s not “Never SQL” It’s “Not Only SQL” 6
  • 22.
    What is NOSQL? It’s not “No to SQL” It’s not “Never SQL” It’s “Not Only SQL” NOSQL no-seek-wool n. Describes ongoing trend where developers increasingly opt for non-relational databases to help solve their problems, in an effort to use the right tool for the right job. 6
  • 23.
    NOSQL Databases Riak Couch KeyValue Redis Document NOSQL Mongo Column oriented Graph Neo4j Cassandra Relational MySQL Postgres 7
  • 24.
  • 25.
    Living in aNOSQL World 8
  • 26.
    Living in aNOSQL World Volume ~= Size 8
  • 27.
    Living in aNOSQL World Density ~= Complexity Volume ~= Size 8
  • 28.
    Living in aNOSQL World Density ~= Complexity Key-Value Store Volume ~= Size 8
  • 29.
    Living in aNOSQL World Density ~= Complexity Column Family Key-Value Store Volume ~= Size 8
  • 30.
    Living in aNOSQL World Density ~= Complexity Document Databases Column Family Key-Value Store Volume ~= Size 8
  • 31.
    Living in aNOSQL World RDBMS Density ~= Complexity Document Databases Column Family Key-Value Store Volume ~= Size 8
  • 32.
    Living in aNOSQL World Graph Databases RDBMS Density ~= Complexity Document Databases Column Family Key-Value Store Volume ~= Size 8
  • 33.
    Living in aNOSQL World Graph Databases RDBMS Density ~= Complexity Document Databases Column Family Key-Value Store 90% Volume ~= Size of use cases 8
  • 34.
    Living in aNOSQL World Graph Databases RDBMS Density ~= Complexity Document Databases Column Family Key-Value Store 90% Volume ~= Size of use cases 8
  • 35.
    Trends in BigData& NOSQL 1. increasing data size (big data) • “Every 2 -days we create as much information as we did up to 2003” Eric Schmidt 2. increasingly connected data (graph data) • for example, text documents to html 3. semi-structured data • individualization of data, with common sub-set 4. architecture - a facade over multiple services • from monolithic to modular, distributed applications 9
  • 36.
  • 37.
  • 38.
  • 39.
    They are everywhere Flight Patterns in Europe 11
  • 40.
    Graphs Everywhere ๏Relationships in • Politics, Economics, History, Science,Transportation ๏ Biology, Chemistry, Physics, Sociology • Body, Ecosphere, Reaction, Interactions ๏ Internet • Hardware, Software, Interaction ๏ Social Networks • Family, Friends • Work, Communities • Neighbours, Cities, Society 12
  • 41.
    Good Relationships ๏ theworld is rich, messy and related data ๏ relationships are as least as important as the things they connect ๏ Graphs = Whole > Σ parts ๏ complex interactions ๏ always changing, change of structures as well ๏ Graph: Relationships are part of the data ๏ RDBMS: Relationships part of the fixed schema 13
  • 42.
    Questions and Answers ๏Complex Questions ๏ Answers lie between the lines (things) ๏ Locality of the information ๏ Global searches / operations very expensive ๏ constant query time, regardless of data volume 14
  • 43.
    Categories ? ๏ Categories== Classes, Trees ? ๏ What if more than one category fits? ๏ Tags ๏ Categories vi relationships like „IS_A“ ๏ any number, easy change ๏ „virtual“ Relationships - Traversals ๏ Category dynamically derived from queries 15
  • 44.
    Fowler & Christakis„Connected“ 16
  • 45.
    New York TimesR&D „Cascade“ 17
  • 46.
    Deb Roy -MIT & Bluefin Labs „Birth of a Word“ TED Talk Researches Social Reactions to (Media) Events 18
  • 47.
  • 48.
    Everyone is talkingabout graphs... 19
  • 49.
    Everyone is talkingabout graphs... Facebook Open Graph 19
  • 50.
    Everyone is talkingabout graphs... Facebook Open Graph 19
  • 51.
  • 52.
    Each of ushas not only one graph, but many! 20
  • 53.
  • 54.
  • 55.
    A graph database... NO: not for charts & diagrams, or vector artwork 22
  • 56.
    A graph database... NO: not for charts & diagrams, or vector artwork YES: for storing data that is structured as a graph 22
  • 57.
    A graph database... NO: not for charts & diagrams, or vector artwork YES: for storing data that is structured as a graph remember linked lists, trees? 22
  • 58.
    A graph database... NO: not for charts & diagrams, or vector artwork YES: for storing data that is structured as a graph remember linked lists, trees? graphs are the general-purpose data structure 22
  • 59.
    A graph database... NO: not for charts & diagrams, or vector artwork YES: for storing data that is structured as a graph remember linked lists, trees? graphs are the general-purpose data structure “A relational database may tell you the average age of everyone in this session, but a graph database will tell you who is most likely to buy you a beer.” 22
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
    You know relational foo foo_bar bar 23
  • 66.
    You know relational foo foo_bar bar 23
  • 67.
    You know relational foo foo_bar bar 23
  • 68.
    You know relational foo foo_bar bar 23
  • 69.
    You know relational nowconsider relationships... 23
  • 70.
    You know relational nowconsider relationships... 23
  • 71.
    You know relational nowconsider relationships... 23
  • 72.
    You know relational nowconsider relationships... 23
  • 73.
    You know relational nowconsider relationships... 23
  • 74.
    You know relational nowconsider relationships... 23
  • 75.
  • 76.
  • 77.
    We're talking abouta Property Graph 24
  • 78.
    We're talking abouta Property Graph Nodes 24
  • 79.
    We're talking abouta Property Graph Nodes Relationships 24
  • 80.
    We're talking abouta Property Graph Em Joh il a n knows knows Alli Tob Lar Nodes 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 Relationships Properties (each a key+value) + Indexes (for easy look-ups) 24
  • 81.
  • 82.
  • 83.
  • 84.
    Looks different, fine.Who cares? ๏ a sample social graph 25
  • 85.
    Looks different, fine.Who cares? ๏ a sample social graph • with ~1,000 persons 25
  • 86.
    Looks different, fine.Who cares? ๏ a sample social graph • with ~1,000 persons ๏ average 50 friends per person 25
  • 87.
    Looks different, fine.Who cares? ๏ a sample social graph • with ~1,000 persons ๏ average 50 friends per person ๏ pathExists(a,b) limited to depth 4 25
  • 88.
    Looks different, fine.Who cares? ๏ 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 25
  • 89.
    Looks different, fine.Who cares? ๏ 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 25
  • 90.
    Looks different, fine.Who cares? ๏ 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 25
  • 91.
    Looks different, fine.Who cares? ๏ 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 25
  • 92.
  • 93.
    Graph Database: Pros& Cons ๏ Strengths • Powerful data model, as general as RDBMS • Fast, for connected data • Easy to query ๏ Weaknesses: • Sharding (though they can scale reasonably well) ‣also, stay tuned for developments here • Requires conceptual shift ‣though graph-like thinking becomes addictive 26
  • 94.
  • 95.
    And, but, sohow do you query this "graph" database? 27
  • 96.
  • 97.
    Query a graphwith a traversal 28
  • 98.
    Query a graphwith a traversal 28
  • 99.
    Query a graphwith a traversal // lookup starting point in an index start n=node:People(name = ‘Andreas’) And rea s 28
  • 100.
    Query a graphwith a traversal // lookup starting point in an index then traverse to find results start n=node:People(name = ‘Andreas’) match (n)--()--(foaf) return foaf And rea s 28
  • 101.
  • 102.
    Neo4j - theGraph Database 29
  • 103.
  • 104.
    (Neo4j) -[:IS_A]-> (GraphDatabase) Lucene Sharding 1 M/s Master/ Index LS Slave TRAVERSA HIG TES H_A VA RA G IL. TE IN PROVIDES ACID Server RUN S_A LI TX S CE NS ED _L ES_T Ruby IK RU JS E MySQL S _A NS SC AL O Clojure _O NS .net RU N Mongo 34bn embedded Heroku Nodes 31
  • 105.
    Neo4j is aGraph Database 32
  • 106.
    Neo4j is aGraph Database ๏ A Graph Database: 32
  • 107.
    Neo4j is aGraph Database ๏ A Graph Database: • a schema-free Property Graph 32
  • 108.
    Neo4j is aGraph Database ๏ A Graph Database: • a schema-free Property Graph • perfect for complex, highly connected data 32
  • 109.
    Neo4j is aGraph Database ๏ A Graph Database: • a schema-free Property Graph • perfect for complex, highly connected data ๏ A Graph Database: 32
  • 110.
    Neo4j is aGraph Database ๏ A Graph Database: • a schema-free Property Graph • perfect for complex, highly connected data ๏ A Graph Database: • reliable with real ACID Transactions 32
  • 111.
    Neo4j is aGraph Database ๏ A Graph Database: • a schema-free Property Graph • perfect for complex, highly connected data ๏ A Graph Database: • reliable with real ACID Transactions • scalable: 32 Billion Nodes, 32 Billion Relationships, 64 Billion Properties 32
  • 112.
    Neo4j is aGraph Database ๏ A Graph Database: • a schema-free Property Graph • perfect for complex, highly connected data ๏ A Graph Database: • reliable with real ACID Transactions • scalable: 32 Billion Nodes, 32 Billion Relationships, 64 Billion Properties • fast with more than 1M traversals / second 32
  • 113.
    Neo4j is aGraph Database ๏ A Graph Database: • a schema-free Property Graph • perfect for complex, highly connected data ๏ A Graph Database: • reliable with real ACID Transactions • scalable: 32 Billion Nodes, 32 Billion Relationships, 64 Billion Properties • fast with more than 1M traversals / second • Server with REST API, or Embeddable on the JVM 32
  • 114.
    Neo4j is aGraph Database ๏ A Graph Database: • a schema-free Property Graph • perfect for complex, highly connected data ๏ A Graph Database: • reliable with real ACID Transactions • scalable: 32 Billion Nodes, 32 Billion Relationships, 64 Billion Properties • fast with more than 1M traversals / second • Server with REST API, or Embeddable on the JVM • higher-performance with High-Availability (read scaling) 32
  • 115.
  • 116.
    Whiteboard --> Data Peter Andreas Allison Emil 33
  • 117.
    Whiteboard --> Data Peter Andreas knows knows knows Allison knows Emil 33
  • 118.
    Whiteboard --> Data Peter Andreas knows knows knows Allison knows Emil 33
  • 119.
    Whiteboard --> Data Peter Andreas knows knows knows Allison knows Emil // Cypher query - friend of a friend start n=node(0) match (n)--()--(foaf) return foaf 33
  • 120.
  • 121.
    Two Ways toWork with Neo4j 34
  • 122.
    Two Ways toWork with Neo4j ๏ 1. Embeddable on JVM 34
  • 123.
    Two Ways toWork with Neo4j ๏ 1. Embeddable on JVM • Java, JRuby, Scala... 34
  • 124.
    Two Ways toWork with Neo4j ๏ 1. Embeddable on JVM • Java, JRuby, Scala... • Tomcat, Rails, Akka, etc. 34
  • 125.
    Two Ways toWork with Neo4j ๏ 1. Embeddable on JVM • Java, JRuby, Scala... • Tomcat, Rails, Akka, etc. • great for testing 34
  • 126.
    Two Ways toWork with Neo4j ๏ 1. Embeddable on JVM • Java, JRuby, Scala... • Tomcat, Rails, Akka, etc. • great for testing 34
  • 127.
    Two Ways toWork with Neo4j ๏ 1. Embeddable on JVM • Java, JRuby, Scala... • Tomcat, Rails, Akka, etc. • great for testing 34
  • 128.
    Two Ways toWork with Neo4j ๏ 1. Embeddable on JVM • Java, JRuby, Scala... • Tomcat, Rails, Akka, etc. • great for testing 34
  • 129.
    Two Ways toWork with Neo4j ๏ 1. Embeddable on JVM • Java, JRuby, Scala... • Tomcat, Rails, Akka, etc. • great for testing 34
  • 130.
    Two Ways toWork with Neo4j ๏ 1. Embeddable on JVM • Java, JRuby, Scala... • Tomcat, Rails, Akka, etc. • great for testing 34
  • 131.
    Two Ways toWork with Neo4j 34
  • 132.
    Show me somecode, please GraphDatabaseService graphDb = new EmbeddedGraphDatabase(“var/neo4j”); Transaction tx = graphDb.beginTx(); try { Node steve = graphDb.createNode(); Node michael = graphDb.createNode(); steve.setProperty(“name”, “Steve Vinoski”); michael.setProperty(“name”, “Michael Hunger”); Relationship presentedWith = steve.createRelationshipTo( michael, PresentationTypes.PRESENTED_WITH); presentedWith.setProperty(“date”, today); tx.success(); } finally { tx.finish(); }
  • 133.
    Spring Data Neo4j @NodeEntity public class Movie { @Indexed private String title; @RelatedToVia(type = “ACTS_IN”, direction=INCOMING) private Set<Role> cast; private Director director; } @NodeEntity public class Actor { @RelatedTo(type = “ACTS_IN”) private Set<Movies> movies; } @RelationshipEntity public class Role { @StartNode private Actor actor; @EndNode private Movie movie; private String roleName; }
  • 134.
    neo4j.rb gem install neo4j require 'rubygems' require 'neo4j' class Person include Neo4j::NodeMixin property :name, :age, :rank index :name has_n :friends end Neo4j::Transaction.run do neo = Person.new :name=>'Neo', :age=>29 morpheus = Person.new :name=>'Morpheus', :rank=>'Captain' neo.friends << morpheus end neo.friends.each {|p|...}
  • 135.
    Cypher Query Language ๏Declarative query language • Describe what you want, not how • Based on pattern matching ๏ Examples: START david=node:people(name=”David”) # index lookup MATCH david-[:knows]-friends-[:knows]-new_friends WHERE new_friends.age > 18 RETURN new_friends START user=node(5, 15, 26, 28) # node IDs MATCH user--friend RETURN user, COUNT(friend), SUM(friend.money) 38
  • 136.
    Create Graph withCypher CREATE (steve {name: “Steve Vinoski”}) -[:PRESENTED_WITH {date:{day}}]-> (michael {name: “Michael Hunger”})
  • 137.
    Two Ways toWork with Neo4j 40
  • 138.
    Two Ways toWork with Neo4j ๏ 2. Server with REST API 40
  • 139.
    Two Ways toWork with Neo4j ๏ 2. Server with REST API • every language on the planet 40
  • 140.
    Two Ways toWork with Neo4j ๏ 2. Server with REST API • every language on the planet • flexible deployment scenarios 40
  • 141.
    Two Ways toWork with Neo4j ๏ 2. Server with REST API • every language on the planet • flexible deployment scenarios • DIY server, or cloud managed 40
  • 142.
    Two Ways toWork with Neo4j ๏ 2. Server with REST API • every language on the planet • flexible deployment scenarios • DIY server, or cloud managed 40
  • 143.
    Two Ways toWork with Neo4j ๏ 2. Server with REST API • every language on the planet • flexible deployment scenarios • DIY server, or cloud managed 40
  • 144.
    Two Ways toWork with Neo4j ๏ 2. Server with REST API • every language on the planet • flexible deployment scenarios • DIY server, or cloud managed 40
  • 145.
    Two Ways toWork with Neo4j ๏ 2. Server with REST API • every language on the planet • flexible deployment scenarios • DIY server, or cloud managed 40
  • 146.
    Two Ways toWork with Neo4j 40
  • 147.
    Bindings REST:// 41
  • 148.
    Two Ways toWork with Neo4j 42
  • 149.
    Two Ways toWork with Neo4j ๏ Server capability == Embedded capability 42
  • 150.
    Two Ways toWork with Neo4j ๏ Server capability == Embedded capability • same scalability, transactionality, and availability 42
  • 151.
    Two Ways toWork with Neo4j ๏ Server capability == Embedded capability • same scalability, transactionality, and availability 42
  • 152.
    Two Ways toWork with Neo4j ๏ Server capability == Embedded capability • same scalability, transactionality, and availability 42
  • 153.
  • 154.
    How to getstarted? 43
  • 155.
    How to getstarted? ๏ Documentation 43
  • 156.
    How to getstarted? ๏ Documentation • docs.neo4j.org - tutorials+reference 43
  • 157.
    How to getstarted? ๏ Documentation • docs.neo4j.org - tutorials+reference • Neo4j in Action 43
  • 158.
    How to getstarted? ๏ Documentation • docs.neo4j.org - tutorials+reference • Neo4j in Action • Good Relationships 43
  • 159.
    How to getstarted? ๏ Documentation • docs.neo4j.org - tutorials+reference • Neo4j in Action • Good Relationships ๏ Get Neo4j 43
  • 160.
    How to getstarted? ๏ Documentation • docs.neo4j.org - tutorials+reference • Neo4j in Action • Good Relationships ๏ Get Neo4j • http://neo4j.org/download 43
  • 161.
    How to getstarted? ๏ Documentation • docs.neo4j.org - tutorials+reference • Neo4j in Action • Good Relationships ๏ Get Neo4j • http://neo4j.org/download • http://addons.heroku.com/neo4j/ 43
  • 162.
    How to getstarted? ๏ Documentation • docs.neo4j.org - tutorials+reference • Neo4j in Action • Good Relationships ๏ Get Neo4j • http://neo4j.org/download • http://addons.heroku.com/neo4j/ ๏ Participate • http://groups.google.com/group/neo4j • http://neo4j.meetup.com • a session like this one ;) 43
  • 163.

Editor's Notes