Graph traversal using UDF

I have edges of graph stored (to be more specific, the graph is bunch of trees aka forest) in aerospike. I want to do some basic traversal and find the root. This i can do in client level, by getting a parent until i reach a node which does not have a parent. But this incurs some unnecessary network latency.

Is it possible to somehow do this using a udf? Else I think this would be an awesome feature to have. Are there any alternative ways to do this?

Sorry, this is not possible. The UDF can operate on a single record in an invocation. Once its is invoked for a record, it cannot access other records. The basic reason why this is not allowed is that the record may be on a different node. We don’t want the UDF to do distributed transaction.

Don’t bother using a UDF to do this: simply do it with client side code. Between doing batch reads, and list operations in database ( for pushing edges onto lists efficientlys ), and doing the edge traversal in your app server, you’ll end up with a very efficient system.

If everything you can do fits into a single server’s ram, simply use a local data structure (edges, vertexes). Don’t bother with a database.

If you need multiple servers’ worth of storage, portions of the graph will be on different servers anyway. So making a network request is fine - and networks are faster than you think, if you use batches.

Do make sure you use batch reads. This means you can get the next set of edges with a single network round trip. If you want to build highly scalable ( instead of single-server-limited ) graph traversal, this is as good as it gets.