# Graph All The Things! ### With Node.js and Neo4j #### Aseem Kishore / Apr 2013
[![](/images/neo4j-lessons-learned/fiftythree-hp.png)](http://www.fiftythree.com/)
[![](/images/neo4j-lessons-learned/thingdom-hp-gasi.png)](http://www.thethingdom.com/)
[![](/images/neo4j-lessons-learned/zoomit-hp.png)](http://zoom.it/)
![](/images/neo4j-lessons-learned/calvin-hobbes-ignorance.jpg)
[![](/images/neo4j-lessons-learned/neo4j-viz.png)](http://www.neo4j.org/)
![](/images/neo4j-lessons-learned/thingdom-graph1.jpg)
![](/images/neo4j-lessons-learned/thingdom-recommendations.png)
![](/images/neo4j-lessons-learned/meme-camera-phone.jpg)
[![](/images/neo4j-lessons-learned/gasi.jpg)](http://gasi.ch/) Daniel Gasienica
[@gasi](https://twitter.com/gasi)
# So… ##   # Just what is a # graph database?
![](/images/neo4j-lessons-learned/GraphDatabase_PropertyGraph.png)
![](/images/neo4j-lessons-learned/relational-to-graph.png)
![](/images/neo4j-lessons-learned/meme-joins.jpg)
By definition, a graph database is any storage system that provides index-free adjacency.
 
This means that every element contains a direct pointer to its adjacent element and no index lookups are necessary.
# Querying
  1. Start somewhere
  2. Traverse elsewhere
# Querying in Neo4j
  1. Start somewhere
    • Root node
    • ID directly (file offset)
    • Lucene index
  2. Traverse elsewhere
    • Traversal APIs
    • Cypher patterns
    • Built-in graph algos (Djikstra, A*, etc.)
# Neo4j usage
  • Embedded mode (Java API)
  • Server mode (REST API)
  • Cypher query language (both)
# Our usage   ## **Node.js** + ## **REST API** + ## **Cypher**
[![](/images/neo4j-lessons-learned/thingdom-node-neo4j.png)](https://github.com/thingdom/node-neo4j)
# Neo4j editions
  • Community edition
    • Single instance
    • Offline backup
  • Advanced edition
    • Meh
  • Enterprise edition
    • Multi-instance cluster!
    • Online backup!
# Neo4j scaling
  • Master-slave replication
  • Cache-based sharding
  • Feature-based polyglot'ing
  • 64B limit on nodes, rels, props
    • But can be easily upped; just flipping some bits
    • 100 props/node (high) ⇒ 640M nodes
# Okay... ##   # Let's talk about # what we learned
![](/images/neo4j-lessons-learned/thingdom-graph1.jpg)
# What we learned
  • Unique, expressive relationship types
![](/images/neo4j-lessons-learned/thingdom-people-stats.png)
# What we learned
  • Unique, expressive relationship types
  • Cache stats where possible
![](/images/neo4j-lessons-learned/thingdom-graph2.jpg)
# What we learned
  • Unique, expressive relationship types
  • Cache stats where possible
  • Capture history through event nodes
![](/images/neo4j-lessons-learned/thingdom-graph3.jpg)
# What we learned
  • Unique, expressive relationship types
  • Cache stats where possible
  • Capture history through event nodes
  • First-class objects ⇒ nodes, not rels
![](/images/neo4j-lessons-learned/thingdom-graph4.jpg)
# What we learned
  • Unique, expressive relationship types
  • Cache stats where possible
  • First-class objects ⇒ nodes, not rels
  • Capture history through event nodes
  • Connected data ⇒ nodes, not props
![](/images/neo4j-lessons-learned/thingdom-graph5.jpg)
# What we learned
  • Unique, expressive relationship types
  • Cache stats where possible
  • First-class objects ⇒ nodes, not rels
  • Capture history through event nodes
  • Connected data ⇒ nodes, not props
  • Maintain linked lists for O(1) queries
# Neo4j Roadmap
  • Overhaul of indexing API
  • Relationship type grouping
  • Socket and/or binary protocol
  • Automatic sharding?
[![](/images/neo4j-lessons-learned/fiftythree-hp.png)](http://www.fiftythree.com/)
# Thanks!   ### Twitter: [@aseemk](https://twitter.com/aseemk) ### GitHub: [@aseemk](https://github.com/aseemk) ### Email: [aseem.kishore@gmail.com](mailto:aseem.kishore@gmail.com)   Questions?