ActiveGraph: Does Rails want or need an answer to graph databases?

Hey All,

I just wanted to start a discussion based on some recent experiences I had in playing around in trying to build a Rails based implementation of the ActivityPub specification.

I want to quickly preface this by saying that one of my main motivations in trying to do this was precisely because I feel like a pretty crappy developer and having a read through the specification this seemed at first glance like something that would push me to become a better developer in the process because many decisions are already made for me and all I had to do in my mind was translate the spec into Ruby / Rails conventions.

However, I super quickly ran into some problems of how the hell do I actually model this data using ActiveRecord. I know it is possible because one of the more popular implementations of the specification is in fact a Rails application.

So I mean it isn’t some impossible task to go and look at the schema.rb file and reverse engineer one way of approaching this. I explored a few different ways of approaching this including this new pattern coming to Rails 6.1 but it feels like what I actually want is to use a graph database (standard disclaimer that as a junior developer I am likely totally wrong here and am extremely open to someone pointing that out).

So while this question comes from a somewhat selfish need I think it would be reasonable to say that there are entire swaths of applications where graph databases do make a lot of sense and I don’t know that Rails has a good answer for them yet.

I want to point out that gems do exist but only really at the level of here is a one to one relationship between this gem and this particular variety of a graph database (afaik).

My questions are:

  • Should we think about making graph databases a more comprehensive part of the Rails story / experience?
  • I feel like many of the major flagship Rails applications out there (Shopify, Basecamp and Github) all have elements of things like “activity feeds” and need to do them at scale. Is everyone just using ActiveRecord for this? Any patterns or guides on how they approach this?

Lastly, if anyone is feeling particularly generous and wanted to point me in the right direction of explaining how they might think about modelling things from something like the ActivityPub or ActivityStream specifications in a “Rails way” I would be incredibly open to any of your thoughts in the hope that I might learn something new :slight_smile:

Cheers!

Mark

P.S Paging @Brian_Underwood1 / @Brian_Underwood not sure if you’re currently on here but you seem like a man who has spent many many years thinking about this exact problem. Would love your thoughts if you happen to see this.

6 Likes

I’m not familiar with ActivityPub, so it would be useful to have a more specific idea of what sort of database entities / structure you’re thinking about. I’m sure almost everybody who’s done this has used a relational database, though.

Graph databases are great when you need to load a complex or deep structure (like, going across many tables) as part of your query. I also personally find Neo4j (the main thing I have experience with) nice to work with as it provides the benefit of schemalessness with the benefit of having the ability to query for relationships (unlike MongoDB). I would love to see more official Rails support for graph databases. I think that the world at large is still coming to grips with what Graph databases can give them in opposition to how well established relational database have become because they have decades of development behind them. But having maintained the Neo4j gems for a number of years I know how big of a challenge it would be. You couldn’t really use ActiveRecord at all, so it would be a whole different effort.

2 Likes

Actually, it seems somebody does something pretty close to it:

"It tries to follow API conventions established by ActiveRecord and familiar to most Ruby developers but with a Neo4j flavor.”

http://neo4jrb.io/

Yeah, that’s the code that I maintained for a number of years :grin:

What I was responding to (and I might have misunderstood the original question) was that it would be very hard to take the ActiveRecord library itself and create an adapter for Neo4j (in the same way that there are adapters for PostgreSQL/mySQL/SQLite). But yeah, the activegraph gem was designed to work very much like ActiveRecord but taking advantage of the strengths of Neo4j

2 Likes