A Survey on Graph Databases for Java Developers
Join the DZone community and get the full member experience.Join For Free
graph databases were also discussed in my previous entry about nosql databases. two other valuable surveys about graph databases are a post in readwriteweb and a page in dbpedias . while they are from the top view by conceptual and framework sides respectively, here i mainly start from the bottom view by looking at their manipulations and functions. in addition, this entry covers more products than them.
this post was originally authored by jasper pei lee
in graph theory, a simple graph is a set of nodes and edges. while this definition is fundamental, graph databases usually add types and attributes on both nodes and edges to make themselves more descriptive and practical in use. at least, graph databases are expected to support fast traversal — this is the reason why we do not simply use tabular databases like hbase or cassandra to store all the edges (join operation is expensive).
we say graph databases are one of four major categories of nosql
databases. also, seven products are listed in the category of graph
. we discuss each of them in detail in this entry, mainly from the perspective of how to use them as a java programmer.
1. neo4j (neo technology)
neo4j may be the most popular graph database. from the name we know neo4j is particularly developed for java applications, but it also supports python . neo4j is an open source project available in a gplv3 community edition, with advanced and enterprise editions available under both the agplv3 as well as a commercial license.
the graph model in neo4j is shown in figure 1. in simple words,
- property (key-value pair) can be added to both node and edge;
- only edges can be associated with a type, e.g., “knows”;
edges can be specified as directed or undirected.
given the name of a node, if you want to locate this node in the graph, then you need the help of an index. neo4j uses the following index mechanism: a super referencenode is connected all the nodes by a special edge type “reference”. this actually allows you to create multiple indexes if you distinguish them by different edge types. the index structure is illustrated in figure 2.
neo4j also provides functions such as getting the neighbors of a specific node or all the shortest distance paths between two nodes. notice that for all of these “traverse” functions, neo4j needs you to specify the edge types along paths, which is handy.
there is no need to install neo4j as a software. we can simply import the jar file to build an embedded graph database, which will be persisted in your disk as a directory. the documentation of neo4j looks complete. there is no limit about the maximum number of supported nodes in free version.
- although we can manually add a property on nodes with key “type” to annotate the type of node, it is better to provide native support for node types in api to make the graph model more general. also the problem comes when a node has multiple types.
the index mechanism by adding new edges manually by user seems
strange and not convenient. it is better to follow what the current
relational db does: users say “create index on a group of nodes”, then
here is another entry about how to get started with neo4j in java:
2. infinite graph (objectivity inc.)
is a graph
database from objectivity, the company behind the object database of the
same name. the free license can only support up to 1 million nodes and
edges. infinitegraph needs to be installed as a service, which behaves
like traditional db such as mysql. infinitegraph borrows the
object-oriented concepts from objectivity/db, so each node and edge in
infinitegraph are objects. specially,
- all node classes will extend the base class basevertex;
all edge classes will extend the base class baseedge.
in the example page shown in http://wiki.infinitegraph.com/w/index.php?title=tutorial:_hello_graph! , suppose person is a node class and meeting is an edge class. this is the code for adding an edge between two nodes:
person john = new person("john", "hello "); hellographdb.addvertex(john); person dana = new person("dana", "database!"); hellographdb.addvertex(dana); meeting meeting1 = new meeting("ny", "graph");
infinitegraph also provides the visualization tool to view the data. the edge generated by the above code is visualized in figure 3. compared with the graph model of neo4j in figure 1, infinitegraph supports nodes with different types/classes. note that the property key-value pairs in neo4j can correspond to member variables in classes of infinitegraph.
- it is fine to install as a service, but should make the configuration simple.
since nodes and edges can be user-customized objects, i suspect the
performance will be harmed for huge graphs when we enjoy the
flexibility. remember nosql databases should always keep high
performance to make themselves compelling.
: my experience of getting started with infinitegraph on win 7 64-bit os is not smooth. the configuration shown in
seems not complete, which makes the java programs keep throwing “
….dll: can’t find dependent libraries
” error. then i checked the dependency of that dll file using
the error “modules with different cpu types were found” tells me
probably infinitegraph does not support 64 bit os. finally, i switch to
ubuntu 64-bit os, finding that infinitegraph only provides versions for
redhat/suse linux os.
3. dex (sparsity technologies)
dex is said to be a high-performance and scalable graph database, which is attractive for nosql applications. the personal evaluation version can support up to 1 million nodes. the current version is 4.2 and it supports both java and .net programming. note that the old version 4.1 only supports java and is not compatible with the new version. until today nov. 24, 2011, the documentation for new version 4.2 is not complete yet, and it is very hard to find a start example for the new version on the web. the migration file here will be very helpful to write programs based on old version examples.
figure 4 shows the architecture of dex, which explains why dex can
achieve a high performance. the native c++ dex core is the key. in the
, the team shows some exciting applications based on dex:
- bibliographic exploration : a use case of dex by storing all dblp data ( demo );
- twitter loaded into dex : the 4.5 billion graph;
wikipedia loaded into dex and query
: obviously better than neod4j.
dex is also portable, and you only need a jar file to run. not like
neo4j, the persisted database of dex is only a single file. dex java api
is easy to use, and class
can provide nearly all the operations you need. to make dex stronger, following weak points are expected to be eliminated:
- better to raise the limit for personal version to 1 billion nodes;
- more complete documentation with fine examples;
transplant the graph algorithms on old version to the new version in the near future.
here is a
about how to deploy your graph with dex.
4. infogrid (netmesh inc.)
infogrid calls itself as a “web graph database”, so some of its
functions are oriented to web applications. figure 5 shows the whole
framework of infogrid, and graph db seems not a dominating component.
infogrid has some applications in
project, which is supported by the same company. i suspect infogrid is
only used in the internal of netmesh, because of the following weakness:
- the newest java api at here is incomplete and sometimes confused;
- the tutorial at here is not written in a clear and formal way.
for the first step example at
while it is not hard to read overall, but the enums such as taglibrary,
tag, tag_label and taglibrary_collects_tag make me really confused.
these enums seems embedded in the model, and why is that? it looks like
this example is used in the internal projects of netmesh to serve for
some specific application but who knows.
5. hypergraphdb (kobrix inc.)
hypergraphdb is an open source data storage mechanism with its implementation based on berkeleydb database . the graph model of hypergraphdb is known as direct hypergraphs . in mathematics, a hypergraph allows its edge pointing to more than two nodes. hypergraphdb extends this further by allowing edges to point to other edges, so hypergraphdb offers more generality than other graph databases. figure 6 shows a hypergraph example with four edges, distinguished by different colors.
the tutorial of hypergraphdb looks complete. each node in hypergraphdb is called an atom, and operations like indexing and traversals are supported.
: although t
is written in a nice form, the same error “
….dll: can’t find dependent libraries
occurs on win 7 os. after i switch to ubuntu 64-bit, the sample program
throws exception “elfclass32 (possible cause: architecture word width
mismatch)”. that’s probably because hypergraphdb only supports linux
6. trinity (microsoft)
microsoft joined the competition just recently with the first release v0.1 of trinity (only allows for intranet access). from the introduction, trinity is a memory-based graph store with rich database features, including highly concurrent online query processing, aci transaction support, etc. trinity only provides c# apis to the user for graph processing.
since trinity package is not open to the outside of microsoft, we
cannot know too much details of it. but at least, the key features of
trinity are listed below:
- use hypergraph as data model;
applicable to be deployed in distributed mode.
the system architecture can be found
overall, it is hard to find any distinct advantages currently when we
compare trinity with other open source graph databases. however, since
trinity is still in its prototype stage, it is worth being noticed. in
is an ongoing project that looks like an ontology/taxonomy knowledge bases built on top of trinity.
links to a nice article about probase and trinity.
7. allegrograph (franz inc.)
allegrograph is a persistent graph database that purportedly scales to “billions of rdf triples while maintaining high performance”. although a rdf triple can be viewed as an edge, allegrograph is intended to build rdf-centric semantic web applications and supports sparql, rdfs++, and prolog reasoning from client applications including java programs. a free version of allegrograph rdfstore supports up to 50 million triples.
figure 7 shows an example of rdf graph. allegrograph appends an additional slot called “named graph” for each triple to make them as quads (but still call them triples for convenience). here are some assertions from figure 7.
subject predicate object graph robbie petof jans jans's home page petof inverseof haspet english grammar dog subclassof mammal science
to add a bunch of triples into rdf graph, allegrograph has facilities
to bulk load from both n-triples and rdf/xml files. overall,
allegrograph is ideal for rdf storage, but not for general graphs. the
documentation looks great. find introduction
and for java api tutorial, the
here and the
the overall comparison is shown in the table below. high-performance and distributed deploy are supposed to be supported by all products. “1m” means the corresponding graph databases can support 1 million nodes for free. rdf graphs can be viewed as a special kind of property graph. since hypergraph is the most generic form of graphs, a graph database supporting hypergraph should also support property graphs theoretically.
|free?||y||< 1m||< 1m||y||y||n||< 50 m|
tentative ranking :
which one is the best? the answer is usually “it depends”. although
it is always controversial to rank products with different
characteristics, sometimes we need to make a hard decision. i show the
following general rules based on my personal understanding:
- if you need to store rdf triples, go to allegrograph;
- for property graph, make neo4j and dex the first class citizen;
- for hypergraph, go to hypergraphdb.
Opinions expressed by DZone contributors are their own.