Neo4jrb
Upcoming SlideShare
Loading in...5
×
 

Neo4jrb

on

  • 6,207 views

Introduction to Neo4j.rb - the Ruby wrapper of Neo4j. Also a quick introduction to Ruby.

Introduction to Neo4j.rb - the Ruby wrapper of Neo4j. Also a quick introduction to Ruby.

Statistics

Views

Total Views
6,207
Views on SlideShare
5,865
Embed Views
342

Actions

Likes
9
Downloads
122
Comments
1

9 Embeds 342

http://nosql.mypopescu.com 303
http://irr.posterous.com 19
https://twitter.com 13
http://www.techgig.com 2
http://static.slidesharecdn.com 1
http://fever.leehorrocks.com 1
http://player.microsoftpdc.com 1
http://schoolisbeat.com 1
http://blekko-webcache.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • good
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • I'm going to talk about one of the most popular graph databases - neo4j, and of course the ruby binding - neo4j.rb which I have written over the last few years.
  • Here is a photo of me playing the Brahms d-minor concerto with the swedish radio symphony. As you can see, it's an old photo. I don't do that much playing any longer but I still passionate about piano playing Another passion I have is Ruby. Why I'm I standing here talking about Neo4j.rb ? I fell in love with Ruby a few years ago and really wanted to learn it. The only way to learn is by reading/writing code. As it turns out I happened to know the people behind the Neo4j database and they suggested I would write a Ruby binding for it.
  • The left picture is actually a picture generated by the NeoEclipse – a tool for visualize the graph
  • Often you don't need to create your own search tree or index since the domain it self contains a search tree. For an recommendation algorithm it is enough to traverse only a limited number of node of a given distance from one node.
  • As you can see Neo4j.rb is like an Object Database except that it does not have a query language The two main benefits of the Graph Database are that it's natural to express the requirements in code (just like an Object Database) since often the real world is best expressed as a graph. You don't need to ruin model that the customer described by putting it in tables. The other benefit is the traversal pattern. As you saw in the previous slide it is easy to express algorithms for things like an recommendation engine with traversals. It is still possible to do this in SQL (since you only need two joins) but I think it is more natural expressed as traversals. Also the traversal speed will remain the same regardless of the depth of traversal or the number of nodes.

Neo4jrb Neo4jrb Presentation Transcript

  •  
  • Neo4j.rb The Benefits of Graph Database Andreas Ronge
  • Who am I ?
  • NoSQL The problem with SQL: not designed for
        • Accelerating growth of data
        • Huge clustered environments
        • Complex and evolving data models
    Choose the right tools - N ot O nly SQL
  • The CAP Theorem Can't achieve all three, pick two
        • C onsistency – all readers will see the same write
        • A vailability – tolerant of node failures
        • P artition tolerant – if lost interconnect between nodes
    Many NoSQL databases choose
        • Sacrifice consistency over availability
        • Eventual consistency instead of ACID (but not Neo4j)
  •  
  • What is Neo4j.rb ? Neo4j
      • A Graph Database written in Java
      • Accessible from a Java API, but also
        • HTTP/REST interface
        • Language binding - Python, Ruby, Scala, Groovy
        • Gremlin ./outE[@label='created']/inV/inE[@label='created']/outV[g:except($_)]
    Neo4j.rb
      • A language binding for (J) Ruby
  • A Ruby Crash Course
  •  
  • What is a Graph Database ?
  • Graph DB vs. SQL id name 1 andreas 2 peter id p1_id p2_id since 1234 1 2 2002 People Friends friend since: 2002 name: andreas name: peter
  • Graph DB vs SQL
  • Benefit 1 Domain Modeling
  • Benefit 2 No O/R mismatch
  • Benefit 3 Semi-structured information
  •  
  • Benefit 4 No Schema
  • DEMO TIME Does Thomas Andersson know someone [who knows]* called Agent Smith ? Benefit 5 Deep traversals
  • Neo4j(.rb) Features Neo4j
        • Embedded
        • ACID Transactions
        • Lucene Integration
        • Graph Algorithms
    Neo4j.rb
        • Object Oriented Mapping
        • “Drop in” replacement for Rails Active Model
        • Improved/extended API (lucene, rules, migrations,...)
  • Embedded Easier to install, deploy & test Is running in same thread as your application No network connection to DB needed No Database Tier
  • Another Ruby Crash Course Ruby Java
  • Transactions ACID
        • a tomicity, c onsistency, i solation, d urability
        • only write locks, no read locks
  • Object Oriented Mapping Neo4j and a Dynamic Language – A Perfect Match ! Ruby Class A Neo4j Node _class: Person name: andreas
  • How do I find things ?
    • Start from Reference Node
    • Graph as an Index
    • Use Lucene
  • Reference Node Find Thomas Andersson Neo4j.ref_node.outgoing(:root).first REF_NODE Thomas Andersson
  • Use the Graph as an Index A A B Neo4j.ref_node.outgoing('A').each {...} RefNode name andreas name anders name bertil
  • Lucene Full-featured text search engine Features
        • Phrase queries, wildcard queries, proximity queries, range queries and more
        • Ranked searching
        • Sorting
        • Date-range
        • Sorting by any field
  • Lucene in Neo4j.rb
  • NodeMixin Lucene Integration Declared properties DSL for relationship traversal Migrations Lists Cascade Delete Works with inheritance
  • Ruby Class Mapping: Relationships friend friend name andreas name peter name david
  • Incoming Relationship Same relationship different direction Same _class = Actor name = 'keanu' _class = Movie name = 'matrix'
  • Ruby on Rails/Active Record “drop in” replacement
  •  
  •  
  • A Common Problem I have a
        • System already in production
        • Huge database
    I need to
        • Change the structure of the database
    Solution:
        • Migrations
  • Migrations: Direct
  • Migrations: Lazy (Neo4j::LazyMigrationMixin)
  • Inheritance
  • Recommendation Engine Likes Likes Likes Recommend This 1 2 4 3 5 Bertil Caesar Adam
  • Example, Recommendation likes other_people 4 2 5 3 1
  • Included Graph Algorithms Shortest paths, Simple paths, Graph measures ... node1 node2
  • High Availability Online Backup - hot spare Read-slave replication Write master election
  • Neo4j – An Object DB ? Neo4j has very fast traversals
        • Avoids loading properties
    No need to declare two way relationships
        • A relationship has a start and end node
    Does have two ways of finding objects
        • Traversals
        • Lucene
    Optimized for Graph Algorithms
  • Conclusions: Benefits Express your domain as a Graph
        • Domain Modeling
        • No O/R mismatch
        • Efficient storage of Semi Structured Information
        • Schema Less
    Express Queries as Traversals
        • Fast deep traversal instead of slow SQL queries that span many table joins
  • When NOT use Graph DB Don't have a graph related problem ? Not too much changing requirements ? Easy to organized data into:
        • Tables, Documents or Key-Value models ?
    Few & well defined relationships in the domain ? Don't have SQL queries that span many table joins ? Many YES => maybe Graph DB not a good choice
  • When should I use a Graph DB ? Need to solve a graph related problem ?
        • Recommendations, Shortest path, Social Networks
    Have a complex and evolving data model ? Few mandatory and many optional attributes ? Big part of domain is expressed as relationships ? Have SQL queries that span many table joins ? Many YES => maybe a Graph DB is a good choice
  •