Crash Course in Graph Databases

Oren Golan

Website/Slides: oren.github.io

Twitter: @oreng

Feedback: orengolan@gmail.com

Agenda

  1. Use cases for graph databases
  2. Advantages of graph databases
  3. Which graph database is good for me?
  4. Play time with Neo4j!
  5. Play time with Cayley!

Agenda

  1. Use cases for graph databases
  2. Advantages of graph databases
  3. Which graph database is good for me?
  4. Play time with Neo4j!
  5. Play time with Cayley!

Ubuntu Package Repository

Logistics

IoT

Fraud Detection

Cancer

Cancer

Our brain

Agenda

  1. Use cases for graph databases
  2. Advantages of graph databases
  3. Which graph database is good for me?
  4. Play time with Neo4j!
  5. Play time with Cayley!

Embrace Relationships

Whiteboard Friendly

SQL Hell

Performance

Finding extended friends in a relational database vs graph database.

Depth RDBMS execution time Graph execution time Records returned
2 0.01 sec 0.01 sec 2500
3 30 sec 0.16 sec 110,000
4 1543 sec 1.3 sec 600,000
5 Unfinished 2.1 sec 800,000

Flexiblity

Reduce the cost of change

Reduce Handoff

Agenda

  1. Use cases for graph databases
  2. Advantages of graph databases
  3. Which graph database is good for me?
  4. Play time with Neo4j!
  5. Play time with Cayley!

What is a Graph database?

"a graph database is a database that uses graph structures for semantic queries with nodes, edges and properties to represent and store data."

Comparison - Neo4j

First commit 2002
Language Java
Type Property graph
Pluggable backend No
Query language Cypher and Gremlin
License and price Community edition - GPL 3, free
Enterprise edition - AGPL 3, 20k a year
Created by Neo4j, Swedish company. HQ in Silicon Valley
Community Large - books, events, training, IRC, Slack
Time to first hello world 10 minutes

Comparison - Titan

First commit 2012
Language Java
Type Property graph
Pluggable backend Yes - Cassandra, HBase, BerkeleyDB, Amazon DynamoDB
Query language Gremlin
License and price Apache 2, free
Created by Aurelius, startup which got acquired by DataStax. DataStax's HQ is in San Francisco
Community Medium - Google group
Time to first hello world a few hours

Comparison - Cayley

First commit 2014
Language Go
Type RDF (triple) store
Pluggable backend Yes - LevelDB, Bolt, PostgreSQL, MongoDB, in-memory
Query language Javascript, with a Gremlin-inspired graph object
License and price Apache 2, free
Created by Ex-Googlers that were part of Freebase and Google Knowledge Graph
Community Small - Google group, IRC, Slack
Time to first hello world 1 minute

Agenda

  1. Use cases for graph databases
  2. Advantages of graph databases
  3. Which graph database is good for me?
  4. Play time with Neo4j!
  5. Play time with Cayley!

Neo4j Demo

Agenda

  1. Use cases for graph databases
  2. Advantages of graph databases
  3. Which graph database is good for me?
  4. Play time with Neo4j!
  5. Play time with Cayley!






Quads

character:ice-king "has a crush on" character:princess-bubblegum .

character:ice-king "has a crush on" character:marceline-abadeer .

Subject                  Predicate           Object

Find everyone that Ice King has a crush on

g.V("character:ice-king").Out("has a crush on").All()


      {
        "result": [ {
            "id": "character:marceline-abadeer"
          },
          {
          "id": "character:princess-bubblegum"
          }
        ]
      }
     

Find everyone that have a crush on Princess Bubblegum

g.V("character:princess-bubblegum").In("has a crush on").All()


      {
        "result": [ {
            "id": "character:ice-king"
          }
        ]
      }
     

cayley load --config=cayley.cfg --quads=db.nq

Find all the haters

g.V().In("hates").All()

Find all the haters

g.V().In("hates").All()


      {
        "result": [
          {
          "id": "character:lumpy-space-princess",
          },
          {
          "id": "character:bmo",
          },
          {
          "id": "character:marceline-abadeer",
          },
          {
          "id": "character:finn",
          },
          {
          "id": "character:lady-rainicorn",
          },
          {
          "id": "character:princess-bubblegum",
          },
          {
          "id": "character:jake",
          }
        ]
      }
     

Find all the haters (and tag who they hate)

g.V().Tag("name").In("hates").All()


      {
        "result": [
          {
          "id": "character:lumpy-space-princess",
          "name": "character:ice-king"
          },
          {
          "id": "character:bmo",
          "name": "character:ice-king"
          },
          {
          "id": "character:marceline-abadeer",
          "name": "character:ice-king"
          },
          {
          "id": "character:finn",
          "name": "character:ice-king"
          },
          {
          "id": "character:lady-rainicorn",
          "name": "character:ice-king"
          },
          {
          "id": "character:princess-bubblegum",
          "name": "character:ice-king"
          },
          {
          "id": "character:jake",
          "name": "character:ice-king"
          }
        ]
      }
     

Who hates Ice King?

g.V().Has("hates", "character:ice-king"").All()


    {
      "result": [
        {
        "id": "character:lumpy-space-princess"
        },
        {
        "id": "character:bmo"
        },
        {
        "id": "character:marceline-abadeer"
        },
        {
        "id": "character:finn"
        },
        {
        "id": "character:lady-rainicorn"
        },
        {
        "id": "character:princess-bubblegum"
        },
        {
        "id": "character:jake"
        }
      ]
    }
     

Find all haters that lives with BMO

Find all haters that lives with BMO

haters = g.V().In("hates")

lives_with_bmo = g.V("character:bmo").In("lives with")

haters.And(lives_with_bmo).All()

Find all haters that lives with BMO

haters = g.V().In("hates")

lives_with_bmo = g.V("character:bmo").In("lives with")

haters.And(lives_with_bmo).All()


    {
      "result": [
        {
        "id": "character:finn"
        },
        {
        "id": "character:jake"
        }
      ]
    }
     

In the pipeline

Cayley Demo

Learn more about Cayley

Videos

Thank you!

Website: oren.github.io

Feedback: orengolan@gmail.com

Slides from this presentation: Here