public> heroku addons:add neo4j

Hello Graphistas and Rubyists!

Now Heroku has become a language polyglot platform , we’re happy to announce that we’re enhancing the NOSQL ecosystem for Heroku customers and users by releasing the Neo4j-Graph Database Add-On. The Neo4j-Graph Database Add-On became “public” this week, so it’s available to all registered beta-testers of the Heroku PAAS platform. This is the first step in our efforts to provide hosted Neo4j Servers to a number of PAAS providers. And the Neo4j Add-On is currently available for free with the test plan, which we think is pretty cool.


What is a Graph Database ?

A graph database is a type of NOSQL datastore suited for interconnected data. It stores its content as nodes connected via relationships, both of which can have any number of properties (this particular model is known as a property-graph). Graph databases have constant time query characteristics for local data access, which is independent of data set size. They are a perfect fit for storing object networks but don’t rely on fixed schemas, so highly dynamic domains are more than welcome (in both dimensions – properties and connections). In terms of scalability, Neo4j currently scales up well since graphs tend to require far fewer writes than traditional RDBMS to achieve the same informational goals. Neo4j scales out reasonably too (especially for reads) through master/slave replication (where slaves are writable). An instance of Neo4j can handle billions of nodes and relationships on a single machine typically surpasses other technologies (like RDBMS) when executing the graph equivalent of multi-join queries.

Provisioning a Neo4j Server instance

For the Heroku Neo4j Add-On, we’ve created our own hosting infrastructure on AWS EC2 instances co-located in the same region (us-east). As a Heroku user, you can add Neo4j to your application by simply issuing the following command:

> heroku addons:add neo4j:test

A Neo4j Server will then be provisioned for your application (with currently generous amounts of RAM). You may visit the heroku page for your add-on to see the following information.

Neo4j Add-On Settings

Most of this connection information is also available via
> heroku config.
The first link points to the Neo4j Web Administration UI which allows you to visualize and manage certain aspects of your graph database. The second link (REST-URL) is used by your application to connect to the Neo4j Server. (Please note that unlike the Neo4j Server available from, this setup requires a username and password for basic authentication). The Backup & Restore feature allows you to pull the current content of your database anytime (suspending the server meanwhile) and replacing the available content with alternative data-sets. For your convenience, we began to provide datasets and will add more of them in the future so that you can start to explore larger graphs right away. Please note that for saving capacity, we suspend idle instances after 24 hours of inactivity. The first request of a suspended instance will take longer than usual as the instance has to be resumed.

Your First Application

The simplest setup for an application using the Neo4j-Server would be using a REST library like rest-client. Anyways, the usage with rest-client would look like this.
irb> p JSON.parse(RestClient.get ENV['NEO4J_URL'])
Remember that instances of Neo4j are suspended after periods of inactivity, so the first call to an instance may take a little longer than normal as the instance is resumed. A gem like neography encapsulates all the low-level details of the API and provides a clean object-oriented way of interacting with the Neo4j-Server.

# i_love_you.rb 
require 'sinatra'
require 'neography'
neo =['NEO4J_URL'] || "https://localhost:7474")

def create_graph(neo)
# procedural API
me = neo.get_root
pr = neo.get_node_properties(me)
return if pr && pr['name']
neo.set_node_properties(me,{"name" => "I"})
you = neo.create_node("name" => "you")
neo.create_relationship("love", me, you)


get '/' do
## object-oriented API
me = Neography::Node.load(neo, 0)
rel = me.rels(:love).first
you = rel.end_node
"#{} #{rel.rel_type} #{}"

(J)Ruby Server Side Extensions

The Neo4j Heroku Add-On contains one more new piece of functionality that can be added to the Neo4j-Server: the ability to extend behavior of the server in other languages than Java. Since we want to support efficient execution of code written in dynamic programming languages like Ruby, we’ve provided a means to move code to the server where it is executed performantly close to the underlying database. We employ JRuby on the server to run rack-applications packaged as ruby gems (for easier management versioning). Those rack applications can use gems like neo4j.rb to access Neo4j directly without any intermediate or remote layers. This allows a more granular, batch oriented domain level REST API to your front-end providing (or consuming) all the information that has to be exchanged with the graph database in one go. A simple example of an application split into a persistence back-end and a front-end hosted on heroku is available on the Heroku documentation page. We also made the sample code available on github.

Documentation Galore

Everything you read here and even more details are available on our Heroku Neo4j Add-On documentation page.