ReactGraph Part 2: Remote evaluation of continuous queries

Investigation into bringing together graph and reactive computing. This is the second post in the series and deals with the remote evaluation of continuous queries.

What’s an IQbservable?

In my previous post I mentioned that Reactor is based on the IQbservable abstraction. Given the importance of this interface in the exploration for a graph store with both “pull” graph querying and “push” reactive computing capabilities, perhaps we should look at it a bit more closely.

The following table is often used in presentations to summarize the LINQ-related interfaces…

IEnumerable. Abstraction for pull-based behavior against a collection/data source (e.g. LINQ-to-object) IQueryable. Abstraction for remoting the pull-based behavior against a data source (e.g. LINQ-to-SQL)
IObservable. Abstraction for push-based behavior against a sequence of events (a stream) (e.g. Rx) IQbserable. Abstraction for remoting the push-based behavior against a sequence of events (e.g. Rx/Reactor)

The top row represents “pull” queries. Such queries consider the data in the collection/data source at the time of their evaluation/execution. If we want to consider changes to the collection/data source since the last evaluation, we have to submit the query again. The second row represents “push” queries, or continuous queries. Such queries consider changes to the data as those changes happen. They operate over streams of data instead of collections of data.

If I was to explain the above using code…

IEnumerable<Post> feed = savas
  .Friends()
  .Where(f => savas.Follows(f))
  .SelectMany(f => f.Posts().NodeValue<StatusUpdate>().OrderByDescending(p => p.DatePublished).Take(5))
  .OrderByDescending(p => p.DatePublished)

// savas.Friends() and f.Posts() are IEnumerables

The above LINQ expression will be evaluated against the in-memory data source. If we make savas.Friends() and f.Posts() IQueryables, then the same LINQ expression tree will be sent to the remote data source, where it might be transformed to some other query language (e.g. SQL), for evaluation. In both cases, we trigger the evaluation of the expression via an enumeration operation…

var result = feed.ToList();
// or
foreach (var post in feed) {
...
}

If we wanted to observe an information stream in order to receive notifications when something changes in the underlying data, we can write an Rx LINQ expression that looks similar to the above. Since we continuously observe for events, we don’t need to order the data, even though we could create a time-based window and re-order the events.

IObservable<Person> feed = savas
  .Friends()
  .Where(f => savas.Follows(f))
  .Select(f => f.PostStream().NoveValue<StatusUpdate>())
  .Merge();

// Friends() is an IObservable<Post>
// Person.PostStream() is an IObservable<Post>

The above LINQ expression tree represents a continuous query that, once subscribed to, will start emitting a stream of posts that make a user’s feed. When any of the friends create post an update, the subscribers will receive an update. Example:

feed.Subscribe(p => Display(p));

The evaluation of the query will happen against the in-memory observable streams. If the Friends() and Person.PostStream() returned IQbservables (notice the “Q” instead of “O”), then the same exact expression tree would be sent to a remote platform for continuous evaluation against the streams of events there.

 

Next: ReactGraph Part 3 – The Data Model

 

Savas Parastatidis

Savas Parastatidis works at Amazon as a Sr. Principal Engineer in Alexa AI'. Previously, he worked at Microsoft where he co-founded Cortana and led the effort as the team's architect. While at Microsoft, Savas also worked on distributed data storage and high-performance data processing technologies. He was involved in various e-Science projects while at Microsoft Research where he also investigated technologies related to knowledge representation & reasoning. Savas also worked on language understanding technologies at Facebook. Prior to joining Microsoft, Savas was a Principal Research Associate at Newcastle University where he undertook research in the areas of distributed, service-oriented computing and e-Science. He was also the Chief Software Architect at the North-East Regional e-Science Centre where he oversaw the architecture and the application of Web Services technologies for a number of large research projects. Savas worked as a Senior Software Engineer for Hewlett Packard where he co-lead the R&D effort for the industry's Web Service transactions service and protocol. You can find out more about Savas at https://savas.me/about

Share
Published by
Savas Parastatidis

Recent Posts

Digital Twin (my playground)

I am embarking on a side project that involves memory and multimodal understanding for an…

2 months ago

“This is exactly what LLMs are made for”

I was in Toronto, Canada. I'm on the flight back home now. The trip was…

9 months ago

AI is enhancing me

AI as an enhancer of human abilities.

10 months ago

“How we fell out of love with voice assistants”

The BBC article "How we fell out of love with voice assistants" by Katherine Latham…

1 year ago

Ontology-based reasoning with ChatGPT’s help

Like so many others out there, I played a bit with ChatGPT. I noticed examples…

1 year ago

Break from work

Hi all… It’s been a while since I posted on this blog. It’s been an…

2 years ago