A Letter Regarding Native Graph Databases
Join the DZone community and get the full member experience.Join For Free
it’s fun to watch marketers create artificial distinctions between products that grab consumer attention. one of my favorite examples is diamond shreddies. shreddies , a whole wheat cereal, has a square shape and was always displayed as such. so an ingenious advertiser at kraft foods thought to advertise a new and better diamond shreddies . it’s a fun twist that got people’s attention and some consumers even proclaimed that diamond shreddies tasted better though they obviously ate the same old product.
such marketing techniques are also used in the technology sector — unfortunately, at a detriment to consumers. unlike kraft’s playful approach, there are technical companies that attempt to “educate” engineers on artificial distinctions as if they were real and factual. an example from my domain is the use of the term native graph database . i recently learned that one graph database vendor decided to divide the graph database space into non-native (i.e. square) and native (i.e. diamond) graph databases. obviously, non-native is boring, or slow, or simply bad and native is exciting, or fast, or simply good.
problem is: there is no such thing as a native graph database.
on the concept of native computing
let’s look at the definition of “native” when applied to data as taken directly from wikipedia’s native computing article:
applied to data, native data formats or communication protocols are those supported by a certain computer hardware or software, with maximal consistency and minimal amount of additional components.
i’m not claiming that wikipedia is an authority on this subject, but this is a baseline definition we can work with for the purpose of this letter’s argument. from wikipedia’s definition, it follows that a native graph database is a graph database that represents the graph (i.e. data) maximally consistent with the underlying hardware. currently, all commercially-available hardware follows the von neumann architecture . under the von neumann architecture, the memory subsystems are represented as a sequential memory space. moreover, in said memory systems, sequential access is significantly faster than random access. realize this for yourself by writing a very large array into ram and then comparing sequential vs. random access times. if you are too busy, read pathologies of big data as the author has done the comparison for you on different types of memory systems. if you are regularly working with non-trivial amounts of data, you most definitely should read the pathologies of big data article.
next, the purpose of any database is to retrieve a query result set by navigating the memory hierarchy and sequentializing memory access as much as possible. how the data is laid out in each of these memory systems, i.e. the data format, data structures and caches, explains many if not most of the differences between database systems. as an example, consider columnar databases . these relational databases store tables by columns (not rows) which makes it possible to quickly compute aggregates over columns because data access is sequential. that’s why they outperform their row-oriented counter parts on analytic queries.
we conclude that a database system is native if the data formats and structures it uses effectively sequentialize memory access across the memory hierarchy for the targeted type of workload.
embedding a graph in a 1-dimensional space
let us now apply the concept of native computing to graph databases. graph databases need to efficiently execute arbitrary graph traversals . a graph traversal is a restricted walk over the graph, moving from one vertex to its adjacent vertices via a selected set of incident edges. without making any assumption on the type of traversal to be executed, it follows that a graph database needs to store vertices, their incident edges and their adjacent vertices in close proximity in the memory systems in order to sequentialize memory access (see scalable graph computing: der gekrümmte graph ). however, those vertices have other adjacent vertices which makes it impossible to keep everything sequential (save in the most trivial graph topologies).
consider the small graph on the left. pick any vertex. linearly write down that vertex, its edges and its adjacent vertices. with that initial choice made, it becomes increasingly difficult — and ultimately impossible — to add the other vertices, their edges and adjacencies into your linear list without pulling adjacent vertices apart. what you are attempting to do, and what every graph database needs to do, is to topologically embed a graph into a 1-dimensional space. there is a branch of mathematics called topological graph theory which studies such graph embeddings for arbitrary spaces and graphs. unless the graph has no edges or forms a linear chain, there is no (strict) embedding into a 1-dimensional space. hence, for all but the simplest graphs there exists no native data representation on typical von neumann computers which require sequential memory layout.
we conclude that there is no such thing as a native graph database for current computing systems.
approximations to embedding a graph in a 1-dimensional space
without a perfect mapping, the best that can be achieved is an approximation. thus, the layout of a graph in sequential memory turns into an optimization problem. the question then becomes: “can we lay out the graph sequentially so that most vertices have their neighbor close by?” for any given graph layout in memory, we can define the distance between two adjacent vertices as the absolute difference in their (sequential) memory addresses. then, we define the objective function as the sum of distances of all adjacent vertex pairs. the optimal graph data layout is the one that minimizes this objective function. unfortunately, this optimization problem is np-hard , which means that the best we can hope for in practice are approximations (unless p=np ). even those approximations are pretty expensive to compute. for example, in my research on disk-oriented graph layouts (see disk-oriented graph management ), i propose an approximation method based on hierarchical clustering which took hours to calculate on graphs with 100s of millions of edges and requires that the graph structure remain fixed. a static graph structure is not an option if you need to update the graph in real-time (i.e. the typical use-case for a graph database). there is a vast trove of research on the subject of optimal graph embeddings, which i encourage you to read if you are interested in the fascinating world of hyper-dimensional manifolds , but let me conclude here that this problem is difficult, far from solved, and an area of active research.
we conclude that a graph database should be judged on the tradeoffs it makes concerning computational/memory complexity and the quality of its graph embeddings.
titan’s approach to embedding a graph in a 1-dimensional space
let me illustrate the tradeoff choices that the graph database titan has made in embedding a graph into a modern computer. titan internally represents a graph as an adjacency list . this means it stores each vertex with all of its properties and incident edges in one sequential list. this has the benefit that titan can access all edges and their properties with one sequential scan. in fact, titan uses a more sophisticated variant of the adjacency list format where edges are stored in a user-defined sort order. for each vertex, an offset index is built that allows for fast retrieval of subsets of the incident edges that fall within a given sequential range. we call these indices vertex-centric indices and they significantly speed up graph traversals on large graphs which have vertices with many edges — so called supernodes (see a solution to the supernode problem ). the downside of vertex-centric indices is that they require building index structures, keeping edges in sort order, and each edge is stored twice. this, in turn, requires more complex data structures and regular compactions of the data files after updates to the graph. once off disk, titan maintains the sorted adjacency list format in ram using binary search instead of building index structures to acknowledge the slightly more favorable random access times of ram. this allows the cpu to effectively prefetch data on traversals. we see that titan expends additional storage space and computation to achieve a more sequential representation of the graph for quicker data retrieval.
once vertices are co-located with their incident edges, the next problem is, how should vertices be co-located with their adjacent vertices? vertices are laid out sequentially in random or guided order. with random order there is no data locality between adjacent vertices but its trivial to compute and leads to balanced partitions in distributed environments. alternatively, titan provides a “guided order” mode which allows users to plug-in a heuristic function that tells titan which partition block a particular vertex should be assigned to or which other vertex it should be close to. while titan handles all of the logistics, the “intelligence” of the allocation is in the heuristic function. we believe that for some graphs it is pretty easy to come up with a good heuristic function with enough domain knowledge. for instance, the facebook graph can be effectively partitioned using user geography as a heuristic (see balanced label propagation for partitioning massive graphs ). this is not surprising since users who live close by are more likely to be friends on facebook. heuristic partitioning works well on some graphs, but requires more computation on update and is prone to imbalances in distributed deployments if not used carefully.
to conclude, the next time somebody tries to sell you a “native” graph database, be sure to reference this letter and ask them how they lay out their graph throughout all the sequential memory layers and decide for yourself the optimality of their embedding (both on disk and in memory)
the intention of this letter was to point out the challenges that all graph databases are facing, vindicate titan from its miscategorization by vendor marketing, and to ensure that the public is properly educated on the topic at hand. all arguments presented are based on generally available computer science knowledge. please comment on hacker news if you find the argument flawed, lacking a proper citation, or wish to discuss the thesis at greater length. moreover, if you are interested in this area of technology, please join aurelius’ public mailing list and participate in helping us develop the next generation of graph technologies.
dr. marko a. rodriguez provided editorial review of this letter in order to make the presented argument more concise, supported with images, and easier to consume for the general reader. pavel yaskevich provided astute points regarding the interplay between cpu caches and ram.
Published at DZone with permission of Marko Rodriguez, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.