DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Join us tomorrow at 1 PM EST: "3-Step Approach to Comprehensive Runtime Application Security"
Save your seat
  1. DZone
  2. Data Engineering
  3. AI/ML
  4. On Scaling Graph Databases

On Scaling Graph Databases

Oren Eini user avatar by
Oren Eini
·
Jul. 18, 12 · Interview
Like (0)
Save
Tweet
Share
8.26K Views

Join the DZone community and get the full member experience.

Join For Free

yesterday i talked about graph databases , outlining what they are and how they work. one of the interesting things about this series is that in many cases, i am posing a question (to myself), trying to answer it, then go and find out what other people do.

when thinking about scaling scenarios for a graph database, i had the following scenario in mind, a graph of nodes that is spread across multiple servers, where each member in the graph may reside on any machine in the system. the following diagram demonstrate what i am thinking about, each rectangle represent a different machine in the system:

image

why is this important?

a single machine solution is obviously a barrier to scaling (and safety, but that is another concern. in a graph database, having relations between the node is the point , that makes sharding a bit more complicated, because unless you store the entire graph on a single machine, you are forced to query across machine boundaries. and you can’t store a graph in a single machine, for the simple reason that it is unlikely that you can limit a graph to be that small. think about the implications of six degrees of separation for graph databases and it will be clear what the problem is. in real world graphs, everyone is connected to everyone.

the problem with breaking the entire graph across machines is that now it is much more expensive to do graph traversals. the following query, which previous run on a single machine:

new graphdatabasequery
{
   sourcenode = ayende,
   maxdepth = 3,
   relationstofollow = new[]{"as known as", "family", "friend", "romantic", "ex"},
   where = node => node.location == ayende.location,
   searchorder = searchorder.breadthfirst
}.execute();

now need to touch 3 different machines. worse, it isn’t the number of machines that impacts that, but the spread of graph nodes across machines in the system.

after spending some time thinking about it, i came to the conclusion that i can’t envision any general way to solve the problem. oh, i can think of several ways of reduce the problem:

  • batching cross machine queries so we only perform them at the close of each breadth first step.
  • storing multiple levels of associations (so “users/ayende” would store its relations but also “users/ayende”’s relation and “users/arik”’s relations).

the solution most likely to be successful is limiting the depth of cross machine node searches. in many cases, that is acceptable, i think. if we put the depth limit on 3, we can still give pretty good answers in a reasonable time frame. but the only way this can be made to work is with good batching support.

the algorithm may look like:

public ienumerable<node> distributedtraverse(node sourcenode, int depth, string relationtofollow, func<node, filter> predicate)
{
    if(depth == 0) // feeling defensive
        yield break;
        
    var related = getrelatednodes(sourcenode.shardname, relationtofollow, predicate);
    
    foreach(var result in related)
            yield return result;
        
    if(depth == 1) // don't even bother asking down the line
    {
        yield break;
    }
    
    foreach(var relationsbyshard in related.groupby(x=>x.shardname))
    {
        var shard = getshardproxy(relationsbyshard.key);
        var results = shard.batchedquery(sourcenodes: relationsbyshard.toarray(), depth - 1,relationtofollow, predicate);
        foreach(var result in results)
            yield return result;
    }
}

this give us a maximum amount of (depth * number_of_machines_in_cluster) – depth remote calls: with a depth of 3 and 3 machines in the cluster, we would have a max of 6 calls.

with that theory out of our heads, let us examine how real world graph dbs tried to resolve this issue…

neo4j (which seems to be pretty much the default for graph dbs) doesn’t handle this currently, there are some hints that they intend to offer cluster wide replication, but nothing about design or implementation details. neo4j does offer write-master/read-slaves approach for scaling out, which is really nice, but even that approach is limited at one point, and in this post, i am focusing on what happen when you go beyond that point.

flockdb (which is what is used by twitter) does include, as part of its design goals: “horizontal scaling including replication”. however, flockdb isn’t trying to solve the problem outlined above, indeed, graph traversal is a non goal for it.  flockdb is more about finding one level of relations very fast than anything else.

in summary, i believe that while you can shard a graph database, it place a very lot limit on the type of graph walking queries you can make. now, just to give you an idea, neo4j, for example, appears to be able to routinely handle billions on nodes on a single machines, so you might no need to scale higher than that..

Graph (Unix) Database Scaling (geometry) Machine

Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Iptables Basic Commands for Novice
  • Upgrade Guide To Spring Data Elasticsearch 5.0
  • Key Considerations When Implementing Virtual Kubernetes Clusters
  • How To Use Terraform to Provision an AWS EC2 Instance

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: