Skip to content
· 116 min watch
Carmel Eve By Carmel Eve Software Engineer II
Ian Griffiths By Ian Griffiths Technical Fellow I

Discover Reaqtor, an open-source, scalable event processing service based on Rx, used in Microsoft's Cortana & Office 365. Learn about its unique features.

About this talk

.NET Oxford

The Reactive Extensions for .NET (Rx) is one of the most influential technologies to have emerged from the .NET ecosystem. (Its influence on other platforms has been so pervasive that its origins in .NET are sometimes forgotten.)

The team that created Rx did not rest on their laurels: they used Rx as the basis for developing a distributed, reliable, and extremely scalable event processing service. Reactor, as it was then called, has been integral to some of Microsoft's most widely used services for many years, including Cortana and Office 365, but although Microsoft has talked in public about it a few times, it has never been available for use outside of Microsoft—until now.

On May 18th 2021, Bart de Smet, made Reaqtor (its new name) open source, as a .NET-Foundation-sponsored project.

This talk will explain what makes Reaqtor different from other high-scale event processing systems. It will also show some of the foundational components that have been released as part of this, most notably 'Bonsai', a mechanism for serializing computations based on .NET's expression tree system, and which is central to how Reaqtor works.

Read the transcript

Introduction: Reaqtor goes open source

Carmel Eve: Yeah, so hi everyone, welcome. I'm Carmel Eve. I was just saying, I'm a software engineer at endjin, and Ian is, he's our technical fellow. We're gonna talk about a project that we've been involved in for about four or five years, but as Ian will go through in a minute, it's been around for a lot longer than that. So for those of you that may have missed the announcement, on the 18th of May, Project Reaqtor went live. So as of last month, the code which supports the running of the project has been open sourced.

It's under an MIT license, which means it's free to use for non-commercial purposes and research. And we've also launched the reaqtive.net site, and that contains a detailed history of the project. It's a lot of documentation, there's a few talks, demos and blogs that we've produced to go into more detail about certain aspects of the project. But I guess it's worth kind of discussing, like, who is this for?

What is a Reaqtor-shaped problem?

So Reaqtor is a stateful, reliable and distributed stream processing platform, and we've spent quite a lot of time over the past few years kind of ruminating on what exactly is a Reaqtor-shaped problem. So Reaqtor extends Reactive Extensions, or Rx, which are a great feature of .NET which enable sort of reactive query processing. And Reaqtor involves this reactive model to enable reliable and long-running queries using persistent storage. And these stateful queries can survive restarts, machine maintenance and any failures, and can even, like, be completely migrated between machines.

But yeah, so using this durability and reliability, we're able to support queries that can run for days, months, even years. And it also allows us to stream a huge amount of, a huge volume of data by distributing that processing. So we can distribu... we can stream this data incredibly quickly and simultaneously run loads of queries. And so using this technology, we're able to continuously analyze large volumes of data over a really long period of time, and we can execute loads of queries over that data simultaneously and efficiently. That's actually to the point that this entire platform can be run on a Raspberry Pi.

Some of the use cases that we've discussed over the years for this, like, large-scale data processing include telecommunications and IoT sensors. I've also talked about tracking of vessels worldwide and personal assistant technologies. But we're really excited to see what else the community comes up with.

A tour of the reaqtive.net site

But without further ado, here is the reaqtive.net site. So from this site, we can link out to a kind of intro talk on what is Reaqtor, some of which we'll cover in this. You can also download an ebook which runs through a brief history of the project and how we got to where we are, and we've got links to various blogs that kind of delve into topics in more detail.

We can also see kind of the different layers of the solution. So Nuqleon contains the primitives which support this kind of processing, and then Reaqtive is built on top of those primitives, and that is the part of the project which kind of evolves the classical Rx model to support this processing. And then Reaqtor is the platform built on top of Reaqtive, which enables this stateful and reliable distributed processing. We also have some demos and some blogs and some talks.

But if we go into the demo section, we can actually link out to some .NET Interactive notebook based demos. So the demo I'm looking at now is one for displaying real-time vessel location data on an interactive Bing map, and this demo is one that Ian will go through a few versions of later on in this talk. But everything contained in this repo is the stuff that has been open sourced, and it is the same code that underpins much of what runs Bing, Cortana, and so Microsoft's personal assistant technology. And the journey to getting it open sourced is one that's been going on for quite a long time, but I'll let Ian talk about that in a bit more detail.

The history of Reaqtor

Ian Griffiths: OK, thanks. So if you've been following .NET development for a while, you may already be aware of Reaqtor, because Microsoft's actually been talking about it in public for almost a decade now. So Microsoft's Channel 9 site, where they have interviews of people working inside of Microsoft, recorded a few interviews early in Reaqtor's history with Bart De Smet. So Bart is a principal software development engineer at Microsoft, and he's the brains behind Reaqtor.

And in these interviews almost 10 years ago, he presented a vision for how the basic principles of the Reactive Extensions for .NET, Rx, could be extended into a service platform for persistent, reliable, long-running and highly scalable event-driven processing in the kinds of applications Carmel's just been describing. And he called this system he was describing Reactor, although back then it was spelled with a C rather than a Q. And Reactor was always a central part of the vision, of the original vision for the Reactive Extensions.

So although Rx has been widely adopted in the years that followed, and not just in the .NET world but also as ports to other languages, the Rx libraries that we have today were only ever meant to be one piece of the jigsaw. So as you might know, Rx originally emerged from a group at Microsoft called the Cloud Programmability Team. That was their remit. And the Rx libraries that we widely use today, they only work within a single process, so they're kind of bound to whatever process you're running them in. But they were designed to provide a well-founded representation of how streams of information could flow between multiple layers of an application that could be distributed across many computers.

Reaqtor inside Microsoft: Bing, Cortana and Office 365

So if you saw those early sneak previews in those interviews, then if you're anything like me, you would have been disappointed that they weren't then followed up with a publicly available release. You might even have presumed that the technology was just abandoned. But actually, that's not the case. Several groups inside Microsoft have been using it for many years. So as Carmel said, it's behind Bing, Cortana, Microsoft's digital assistant, and that was the first place where it kind of proved its scalability. So it was used to support tens of millions of concurrent persistent queries.

And this, it's... excuse me, it's used if you ask Cortana to notify you when certain interesting things have happened. So for example, if you ask to be told when traffic conditions have changed, meaning you've got to leave earlier to meet your next meeting, it's Reaqtor that powers that. But it's also used inside bits of Office 365 to provide lots of services that need to respond to changing information from a variety of different sources.

So Reaqtor has been successfully deployed inside of Microsoft in several different ways, but for a variety of reasons, the team behind it never managed to find a way to get the actual platform itself publicly available. It was only ever used sort of as an internal feature of something else.

How endjin got involved

However, about four years ago, endjin, which is where Carmel and I work, approached Microsoft to see if they would let us use Reaqtor. So we had a customer who operates a large broadband network, and they needed to perform intelligent monitoring of literally millions of devices. And we realized that this Reaqtor thing that we'd heard Microsoft talking about would actually be a great fit for this, because we knew it could easily support tens of millions of concurrent monitoring queries. So it would be possible for every single customer router in this broadband network to get its own private monitoring, but in a way that was able to take into account system-wide states, such as the overall health of the exchange a customer's connected to, and so on.

And that's really important when it comes to having the right response to a fault, you know, for customers having problems. Do you send a van out to them or to the exchange? Because you don't want to send 20 engineers out to the customer sites when it turns out that the exchange is on fire. So those sorts of things, it's useful to have the ability to process events at scale across the system as a whole, but also to be able to focus in on individual things, and Reaqtor is very good at that.

And Microsoft agreed to share the code with us to help us work with it, and the long-term goal was that if we could prove that it was viable for customers outside of Microsoft to use it, they would work out a way to get it released. So inside endjin, we built various systems that host Reaqtor in Azure and prove that it can be used outside of the very specialized internal Microsoft environments that it's been used in in the past. Now, it's taken a while to get all the pieces aligned, but thanks to a great deal of effort on Bart De Smet's part, and support from the .NET Foundation, today the core code that makes up Reaqtor is now available, as Carmel said.

What is not in the repo

Now, it's worth just clarifying... excuse me, let's get faster on the mic there. It's worth being clear about what is not available, so not available in the repo today. So to host Reaqtor, you need to provide it with an environment that provides various specialized persistence and communication services, particularly if you want to scale out to millions of queries. Now, Microsoft couldn't share their own implementations of that, because they were tightly bound up to particular service environments like Bing or Office.

So you won't be able to download the repo, build it and then instantly deploy an industrial strength service in minutes, because there's many different ways to actually deploy Reaqtor. And so it's more of a toolkit for building Reaqtor-based services rather than being one service. So as Carmel said, you can run Reaqtor on a Raspberry Pi, and that requires quite a different approach to hosting compared to running it on a compute cluster with hundreds of machines in it. So the bits in the repository that are available now are the parts that are common to all those environments.

Now, because Reaqtor has been used in lots of different environments in lots of different ways over the years, the code base has seen a lot of extensive refactoring to make it very, very flexible. It can be applied in all sorts of different ways, but it does also mean it's a bit tricky to approach the code base. It's not obvious where to start. It's not at all obvious how to take all of these features and combine them together into something useful.

So we're going to start by talking about the concepts behind Reaqtor, and sort of why it's like it is, what makes it distinctive. And then later on, I will show you one route in to the repo that gives you a way of actually getting things up and running to get started. But a lot of those demos that are in the repo are kind of on the complex side, so we're going to start with some more sort of principles based illustrations. So with that, I'm going to hand you back to Carmel, who's going to talk about the fundamental model that underpins everything in Reaqtor, so that's the Reactive Extensions model, Rx.

What is Rx?

Carmel Eve: Yeah, so clearly, in order to be able to understand Reaqtor, we first need to take a quick look at classic Rx. And the underlying concept behind Rx is the representation of streams of information, and the easiest way to describe it, I think, is by using a comparison with collections. So in a normal collection, you have a set of values, and when you want to read the next one, you go and ask for it, usually by iterating through the collection. So this is a pull model for data processing.

In Rx, however, instead of a collection you have an observable, and instead of iterating through it, you subscribe to it, and this tells the observable that you want to listen to any values that it produces. So this is a push model, where instead of pulling items, they are pushed at you whenever they're ready. And so you obs... you subscribe to an observable using an observer. Observables have a Subscribe method to which you pass an observer, and when that observable produces a value, it will pass that value to the OnNext method of any observers that have subscribed.

Once the observable has finished producing values, it will call the OnCompleted methods of all the listening observers, and this will tell those observers that it won't be producing any more values. Or if the observable produces an error, it will call the OnError method, and that will notify all of the observers which are listening that an error has occurred.

Hot and cold observables

There are also two different types of observable, hot or cold observables. And so a hot observable will produce values whether or not anything is subscribed, and this means that if nothing is listening, any values that are produced will be lost. And this is compared to, or it's said to be similar to, sort of old style TV broadcasting, where if you didn't catch a TV program when it was first streamed, tough, you'd missed it. Whereas a cold observable doesn't start producing values until something's subscribed. So this is more similar to modern, current on-demand TV, where you just go and press play when you're ready.

So using Rx, we're able to represent streams of information as and when that information is available, and this type of reactive processing opens up really great possibilities for streaming and processing real-time data as and when it's produced. For example... Ian, let me...

Demo: live ship data from AIS

Ian Griffiths: Yes, sorry, just scrabbling to share my screen again. Right, and the thing I just tried to run didn't run. There we go, that's better. Right, so there is a theme to the demos we're going to show you, and that theme is AIS, the automated information system, which is a system which, as I'm sure you've already worked out by looking at the messages scrolling past, tells you about where ships are on the ocean right now. So what we're looking at right now is a live information feed. It's a bunch of messages coming past, which is exactly the sort of thing that Reaqtor is good at dealing with.

So this feed is showing me individual radio messages being broadcast by ships out in the sea around the Norwegian coast. Why Norway? Because Norway's government makes this feed available for free, so it's a handy thing to demo with. So the messages here tell us things like where the ship is, how fast it's going, which direction it's pointing, so all the information about where it is. And this is something that most ocean-going vessels are required by maritime law to have. Most countries in the world with big ports, you've got to have this so that they can see where ships... can see where one another are.

Position reports and name reports

Now, one thing to notice about this is there's two different kinds of message flying past you, if I just stop it by selecting some text here. Most of these are navigation reports, reporting the location, the speed, the heading and those sorts of things. Less often, we get these messages that tell us the name of the vessel. And that split is going to become important later on, because we're going to end up showing these things on the map, and we want to combine the location and the name data together into one thing, but they're actually broadcast separately.

And the reason for that is to conserve radio bandwidth. These things are operating on a relatively bandwidth constrained frequency, and so they want to send as little data as possible, and ships don't change their names as often as they move. Not unless there's some convoluted tax dodge going on, at any rate. So generally speaking, you don't want to send the name out all that often. So they often only advertise their names every few minutes, but they advertise their location often several times a minute. So this is the raw data.

Consuming AIS messages with classic Rx in a notebook

So now let's look at how we might consume this using classic Rx. To begin with, we're not going to dive straight in with Reaqtor, we're going to go for a simple Rx model. So I've got a .NET notebook here. So I'm using Visual Studio Code, and I've got the notebook extensions installed and the .NET Interactive plugin, which lets me use notebooks that have C# code in them, or F#, or a mixture of C#, F# and JavaScript if you want that.

We've got two of those in here. So this #r just says add a reference to a package from NuGet. In this place, I'm adding in a couple of libraries that endjin has written and makes freely available, and you can get the source code for this on GitHub. These are libraries for working with these AIS messages that ships broadcast. So if you want to parse the messages that come out of feeds like this, these libraries will do that for you. So then I'm going to bring in a bunch of namespaces. So the System.Reactive ones, those are for Rx, and everything else is because I am working with AIS.

And then we're going to create one of these objects. This is the thing that knows how to connect to the kind of feed that the Norwegian government supplies, so that's the IP address of their service and the port numbers. This basically is going to connect, when we tell it to start, it's going to connect to that Norwegian data service and fetch messages from it. And then we wrap that in this thing, which presents those messages as an Rx observable. So this thing, the receiver, just speaks the low level network protocol. This receiver host wraps that in the ability to actually deliver the messages through Rx.

Drawing ships on a Bing map

So what are we going to do with a bunch of messages where ships tell us where they are? Well, we're going to draw them on a map, obviously. So this is actually an HTML cell that loads up the Bing Maps control. Here it is, and I will zoom in on Norway, because the Norwegian government only report the location of ships in their own waters, not the rest of the world. So that's ready to go.

Now we have to do a few things to make it possible for the C# code to send messages to the JavaScript that controls that map. So we have to basically register a communication channel between those two different bits of the notebook, because all the .NET code runs in one process, all the JavaScript code runs in a different one. So what we're basically doing here is saying, well, actually, there's a kind of message, a kind of command, I'd like my C# code to be able to send to JavaScript. And this has got just all the information we need: the longitude, latitude, the direction that vessel's going, its unique identifier, name and color and so on.

So this just registers that, so we have a communication channel to let C# update the map. Here's the other half of it. This, you'll notice, is a JavaScript cell, and this one says if anyone sends a vessel position command, please invoke this handler. And that then calls into a helper on the map that will draw the ship on the map or update its position.

So with all that... excuse me, with all that in place, we can now get to the heart of the matter, which is some Rx code. So remember, I had this receiver host, which defines a Messages property, which is an observable. So this is a source of events. It's actually an IObservable<IAisMessage>, so it presents each AIS message that comes out of that Norwegian server and makes it available.

Now, before I go into this in detail, I'm just going to show you the processing that we're actually going to do. So the messages that come in from the raw feed, as you will recall, some of them report the location of the ship, some of them report the name. So here I've drawn that mixture of messages. I'm using color coding to say which vessel it is, so the vessel with that unique ID 1234 is in blue, and most of the messages it sends are going to be location messages, but occasionally it's going to report its name.

And likewise, we've got some from another vessel, 7977, all in green. So we get this sort of mixed message type. What we would like is an output that combines that information. So what I really want is to know vessel ID 1234, with name the Foobar, is at this location. I want to kind of combine these things together, and we're gonna use Rx to do this.

Grouping messages by vessel

And the way this is gonna work is that we will first of all group the messages by vessel. So Rx offers a GroupBy operator. That's a standard LINQ operator, conceptually exactly the same thing as group by over a database table, but obviously these aren't database tables. The data sources we're working with here are observable streams of events. So when you do a group by, you specify the group criteria, which in this case will be the unique vessel ID.

So for every new vessel ID that we see, the Rx GroupBy operator is going to emit a new observable source. So it basically gives me a source of sources. I get a new source out for each distinct vessel, so we get these distinct queries represented by these lines here. So here you can see I've split out all of the blue ones, and here all the green ones, and however many vessels there are, you'll get that many things coming out of the group.

So then what we want to do is, within each of these, just combine the latest pieces of information. So every time we get a new message, I want to report the location and the name using whatever the last one I've seen of each is. So we can't do that until we've seen one of each kind, but as soon as we've had both the location and the name, we can emit that information. And then the same thing is going to happen on the green one. And once we've seen one of each message type for any given vessel, any further messages that come in can just be combined with their relevant predecessor, and we end up with the name and location combined into a single object. And then we flatten these back down into a single stream when we're done, and this is the information that we can then feed on to the map.

The Rx query: GroupBy and CombineLatest

So that is what this code here is doing. We take our raw source of all the messages, we group them by MMSI. That's the unique identifier, that's the maritime mumble something identifier. I can't remember what the other two letters stand for. So we're going to build an output stream from this. We take from the group items, we take each group. So each group that comes out of here, remember, is going to be a nested observable, so the type of this group thing is an observable of grouped observables. So for every distinct identifier we get a new one of these, and that's represented by this range variable here.

And then for each of those, we extract substreams representing all the navigation data, that's the location, speed, heading, and also a separate stream with all the things representing the name. And actually, I didn't show this on the previous slide, but there's a third type of message which tells us what kind of a vessel this is. Is it a tanker, is it a passenger vessel, is it a fishing vessel, those sorts of things. So within each of the streams in a group, we get these three substreams split up by type, and then we just combine them back together with Rx's CombineLatest operator. So this says, for those three streams, please give me an item that just spits out a tuple with the latest item it's seen from each of those streams.

And then we flatten all of those back down into one big unified stream. So this is all per group, and then this flattens it back out, sort of ungroups it again after we've rejigged it. And what we get out is a single stream reporting the vessel ID, navigation data, name and type. So I'm going to run that. This defines the query, but we have to subscribe before things start happening, so nothing's actually running yet. This just describes the processing that we want.

This colors everything in nicely, so this just says what kind of ship it is and decides what color to paint it on the map. And then we can actually hook things up. So we have the stream now in the form that we wanted, because we run it through that Rx query that massages the data into the right shape. And remember, each item out of there is going to be a tuple, so this just destructures that back into its component parts: vessel ID, navigation data, name and type.

And then we wrap that up in this command, because we're going to send this over to the map. So we're going to use that commanding mechanism where we can send the message from C# to JavaScript, so that that can then update the map with the data that we want, and pass that callback to Subscribe. So when events start coming out of the source, they'll end up on the map. Now, as it happens, our receiver doesn't actually do anything until you tell it to go, so nothing will happen until I click this button.

Ships gradually appear on the map

But when I do, as long as I didn't forget to click one of the other go buttons on the map, we should start seeing... oh, there we are. There's some ships, there's some more ships. They will gradually start to appear, and gradually is the operative word here, because it does actually take a little while. Sorry, clicked the wrong thing. Because remember, it can't tell us the information on the map until it's got everything it needs. It needs the name, the location, the MMSI, the type. It needs everything before it can show it on the map.

And so what's gradually happening is these ships are all transmitting their location data pretty rapidly, so we probably have already received all the location data from all the ships, but we've only seen, you know, a small fraction of their names so far. So the longer I leave this, the more ships will gradually appear on the map. So it gradually builds up a picture of everything, and eventually it's able to show me everything in Norwegian waters. Now, I've not listened to the news today. Did Norway declare war on us, or was that one just lost? That doesn't look like... well, maybe that's Norwegian water. So let me stop this now, because I'm gonna move away from this and talk about something else. So let me shut that down so we don't bother the Norwegian government more than we have to.

What does Reaqtor add to Rx?

So I'm on the wrong slide here. Right, so that was the Rx version of the demo. So the question is, what does Reaqtor add to the picture? Because all of that was done with Rx, so we don't need Reaqtor, right? So this is a waste of time, thanks for coming. Or, well, maybe we do. So the biggest obvious problem that we had with that demo was that it takes a while for it to build up the state that it wants. So it can't start reporting information on the location of the vessel until it's also acquired all the other pieces.

Now think about what would happen if I shut down the notebook. If I run it again, I'm back to square zero. It's gonna gradually build all that state up again. Now, that's OK for a demo, but if I'm running a service, that's more of a problem. What happens when I wanna, you know, upgrade the machine? What happens when I wanna move over to a new machine because I need to update Windows or Linux or whatever on the host system? What if I want to deploy an update to my app? Do I have to chuck away all the state and start again?

That's obviously not ideal, but that is kind of where you end up if you use regular Rx for this. Rx does not provide any means of keeping track of, storing the state that is embedded in a subscription of that kind. There's a whole lot of stuff that's going on there that's essentially locked inside Rx's head. You can't interrogate a subscription and say, tell me all of the subqueries your group by clauses have emitted. You can't walk up to it and say, give me all of the latest values that all of your combine latest operators have collected so far. So if you want to move to a new server, you basically reset your position, which is not very good.

Persistence: long-running stateful subscriptions

So this is one of the big things that Reaqtor enables. Reaqtor adds in a persistence model. Reaqtor makes it possible for us to walk up to a subscription and turn that whole thing into a serializable blob that represents the current structure and internal state of the whole query. And that enables us to then store that somewhere, so we could then shut down the machine it's running on and restart the same query running somewhere else. So it provides the ability for subscriptions to outlive any particular machine, which is not a thing that regular Rx can really do.

So this is what we mean by long-running stateful subscriptions. So Microsoft have got subscriptions in some of their Reaqtor-based services that have literally been running for years, and you need this ability to persist things for that to work. This is also actually very important to the reliability elements of Reaqtor. So you can use this same facility to provide robustness in the face of failure. So I described how we migrate things deliberately from one machine to another for planned maintenance purposes, but what if a machine just crashes?

Checkpoints, replay and reliability

Well, what we actually do is that when Reaqtor is running, every minute the services will store a checkpoint. They will basically run this same persistence thing and just store the data in case the machine then fails. Now, it's not the whole story, because the obvious question then is, well, what happens to all the events that came after the last checkpoint? And actually there's a whole story around that as well. So there's an ingress and egress mechanism managing how data comes into and out of Reaqtor instances, and essentially data sources have to be able to replay everything that had happened since the last checkpoint. So you need to have a source that can do that.

And also on the egress side, there are mechanisms to avoid duplicate emission. But with those things in place, we can rely on the fact that Rx is inherently a deterministic model, and so we can just rerun stuff. So when you do get a crash, some other machine will come up and take over, and it can basically just replay everything from where it got to. So these are some of the things that Reaqtor gives us on top of the basic Rx model. And with that, I'm now going to hand back over to Carmel, who will show you some of this stuff in a bit more practical detail.

Stateful queries: operator state is persistent

Carmel Eve: So yeah, one of the big things that distinguishes Reaqtor from classic Rx is the ability to run long-running stateful queries. But what does this mean in practice? What does it mean to store the state of a query? Let's use the Take operator as an example. So in this, we'll assume that the observable stream acts like a queue, where items are processed once and they're removed from that queue. So using normal Rx, if we apply the take operator to a source, we would just take the first eight items in that stream.

However, if you restarted the process halfway through taking those items, the observer will be reapplied to the stream and you would again take the first eight items. This would mean that all of the state from the items that were previously processed would be lost, and the first eight items from somewhere part way through the stream would be processed. When using Reaqtor, as Ian was saying, a key feature is that operator state is persistent. The Reaqtor engine generates these checkpoints regularly, and the checkpoints record where in the stream you have reached and the operator's state at that point. So this means that when the engine is restarted, you can restart processing from where you left off, and not only this, but preserving operator state means that operations such as take will not be reapplied.

Demo: checkpointing an in-memory query engine

So let's look at a demo of how this works in Reaqtor. So this is running an in-memory version of Reaqtor, and this is what a lot of the demos which are in the Reaqtor code base will do. But here, so I've got a demo which is in two parts, part one and part two, and when we start this program, we will run whichever one of these parts we have supplied the argument for. So first we'll be running part one. Oh, and I've just closed the program, right, from the program. But yeah, so after we've run part one, it will then shut down the process completely.

So in part one of this demo, we first recover the query engine. At this point, no subscriptions will have started in the query engine, so nothing will happen when it starts up. But we then get a definition of the timer observable. So this definition just defines an observable which will create an item at a given interval. We also define the console output observer, and with this observer, any values which are passed to the OnNext method of the observer will be written onto the console. So using the timer definition, we can create a current speed observable, which gets the current speed at an interval of every second, and then we take the first eight of those.

So this get speed method is actually just generating a random number, which could represent the speed of a car, but this could be anything. It could be sensor data from an IoT device, it could be an event from a telecommunications hub. But so once we've defined this observable, so this is, as Ian was showing in the previous example, this is just a process definition, so no work is actually going to happen until something subscribes. So then we subscribe our console output observer, meaning that the items which are pushed by this current speed observable will be written out to the console. We then wait for 4.3 seconds, we checkpoint and we unload the engine.

So if I run this, we should see, hopefully it opens on the right of the screen, we should see... has it taken over my... do I hide... oh no, it just means... never mind. Apparently it needs to rebuild. But we should see that the first five items from this observable are written out to the console. Yeah, there it is. So once these five items have been written out, we will then checkpoint and unload the engine. So at this point, everything is shut down and the state has been saved, and back in the code we can see that we are writing this state out to disk.

So I'm now going to run part two of the demo, so I'll change that to part two, save here, and again we load the state. So currently we're going to run both parts of this demo on the same machine, but because this state has been written out to persistent storage, this could be run on a completely different machine, as long as that machine had access to the state. So this is how we support machine migrations or updates and all of that. So again, we will recover the query engine from that state, wait five seconds, checkpoint and unload.

It really isn't liking it, sorry. I'm not sure what's going on with my keyboard. Oh, and we've lost that. But we can see that the next three items have been written out to the console, and then the OnCompleted method has been called. So sorry, my computer is freezing. But yeah, so unlike in normal Rx, instead of the operator being reapplied, we have continued as if the restart never happened. So this means that queries can move between separate processes and machines, and the current state is written out to storage, so processing can continue throughout machine restarts, maintenance and all of that.

Reaqtor also gives assurances about reliability, which means that you can be sure that no state will be lost throughout those restarts, and run Rx-like queries but with predictable and repeatable results. So yeah, with this you can create queries which can run for days, months or even years without worrying about, you know, engine restarts and loss of data, or unpredictable results due to these restarts. And this extremely long query support is what supports things like Bing, Cortana and some of the other use cases we've already described.

Break

And so at this point, I think we're going to take a minute break, so I'll be, say, five to, and come back with some more shipping database demos. So yeah, see you all soon, thank you.

Ian Griffiths: Yeah, so we'll have a ten minute break, and then we'll... yeah, as Carmel said, well, let's start on the hour maybe, so just over ten minutes, and everyone feel free to unmute and chat or get a drink. I'll be back in a minute.

Audience member: I am curious, there was a... I saw a method called, saying, pay no attention to the man behind the curtain. What was that all about?

Carmel Eve: It's because, so, that's Reaqtor running in memory, so it needs to do some setup. So it'll define a query engine and define a few inbuilt operators in that, and there is some setup that needs to happen. But I thought, you know, better to hide the in-memory stuff. So I can quickly, if I go in here, I'll see if I can find the... yeah. So these URIs kind of relate to things that the Reaqtor code base knows about. So these are things which are defined inside of Reaqtor which will do specific things. So the URIs are kind of how observables and observers are represented within the Reaqtor code base, and this is how they get serialized and passed over the wire. And this is something that Reaqtor will know about, so when it sees this URI, it will know what to create kind of inside of the processing engine.

Audience member: Well, when you mentioned before about the... you can run it on the Raspberry Pi. I've got, like, a stack of Raspberry Pis here which I've got a Kubernetes cluster running on, and I feel like I just need to play with this now. Yeah, I'll get this running on it. I'm not using it for something, it's just sat there.

Carmel Eve: I do, I think that's one of the really powerful things about it, is that you could sort of push it... so you can run it on these, like, very low power devices, so you can push it right down into the edge. So when we're talking about the IoT sensor data, some of the things we were talking about is whether you could run it kind of closer to the sensors and kind of run these queries over a period of months, so you wouldn't have to keep going down into wherever the sensor is to, like, collect more data off it, and you could just do the kind of accumulation of queries at point. So yeah, that's sort of one of the things to talk about, quite exciting use case.

Questions from the first half

Ian Griffiths: So I was just going to quickly go through a few of the questions that have been asked. I know how it's done a reason they're going to done a good job of answering some of them, but people may have missed them, so I was going to go over a few things. So someone asked, when we say Reaqtor supports persisting the state, does that mean that Reaqtor gives us something serializable and we have to persist it? So yeah, Reaqtor doesn't actually implement the fundamental persistence mechanism, because it's making the assumption that you've probably got a database or something of that kind that you're going to use to actually do the storage. So it doesn't come with a built-in database. It says you decide how to store this stuff, and you provide an implementation of a suitable interface for that. So yeah, when we say it's doing the persistence, what we actually mean is that it's getting it into a form that can be serialized, and then you decide what to do with that.

Where was the console output observer declared?

Someone then asked, where did you declare the console out observer? Now, that's possibly a more interesting question than is immediately obvious. So one of the things we've not really talked about is the query engine, which is the thing that provides the environment in which all these subscriptions run, and typically in a server based Reaqtor system you would have multiple query engines. The query engine can be configured in many, many different ways, and actually, by default, it knows almost nothing. The only thing the query engine intrinsically understands is how Rx works at the very lowest level. It knows what observables and observers are, and it knows about checkpointing and things like that.

But it doesn't, for example, know what select is, or group by, or combine, or any of those things. None of them are actually fundamental features of the query engine. The way it works is that when you start up a query engine, you decide, as part of your hosting environment setup, you decide what operators are going to be available to it. Now, there's a standard set. Rx, sorry, Reaqtor comes with a whole bunch of standard ones. All the standard Rx operators are available to you, and if you wish to, you can load them into the query engine, but you're not obliged to. You can choose the exact set of operators that you want.

And so part of the setup of hosting Reaqtor, whether you do it in memory, whether you're doing it on an edge device, or whether you're doing it as part of a server farm, part of the setup you go through is telling it which operators are available for use. And so we had to do that to make things like select and timer and so on available, and that's at the same point that we add in things like an output operator. So that's how that happens.

Carmel Eve: So yeah, so I was saying that we're running Reaqtor in memory here, and yeah, so that URI that we saw in the code is the same as this one, and then we have told our in-memory version of Reaqtor that that means a console output observer. If I go in there, it's very simple. Anything that is passed to the OnNext method, it prints out as on next, and then it prints out on completed or on error. So yeah, but as Ian was saying, it depends on your Reaqtor implementation exactly what you tell it that it needs to know about. Because we're running in memory, we've just defined the operators we actually need. But yeah.

Spark, threads and transports

Ian Griffiths: Great. So then, what was the next thing? Someone asked, how is this different from Spark? We've got a section coming up on comparing it with other technologies, so I'm going to defer that till then. Can you control the amount of task threads you can spawn from SubscribeAsync? It doesn't really work that way. There's a scheduler model inside of Reaqtor, which is actually very similar to the Rx scheduler model, if you're familiar with that. So it's actually controlled at the query engine level. You get to configure the scheduler that it's supplied with, and you can tell it how you want it to run.

So again, it's sort of a matter for the hosting environment to decide. If you want to have, you know, one thread per CPU core, if that makes sense, you can do that. If you want to have more, you can do that. If you want to have fewer, it's up to you. So it's not controlled at the subscribe level, it's controlled by how you can... right, I think that may have been an accidental unmuting. Cecil, did you mean to ask a question, or is that... right, I'll carry on.

When running multiple processes in a distributed way, what is the transport that is used to transfer the messages slash events between different components? Again, that's actually a hosting environment decision, because there isn't one right answer for everyone. So the way that Bing does it is to use Bing-specific things. The way that Office does it is to use Office-specific things. We do it over some Service Fabric based mechanisms. We know that Microsoft has in the past, I think, used ZeroMQ in some implementations. Again, it's an implementation choice. There's lots of different ways you could do it.

Rewinding state and virtual time

Any thoughts on whether it would be possible to rewind state? Actually, yes. endjin's Reaqtor as a service offering, which I'm going to show you kind of in the next demo, one of the things we can do is what we call virtual time mode. It's not exactly rewinding, but you can configure the scheduler to run in a way that is not real time, so we can do what-if queries over historical data. So it's not exactly rewinding, but we can go back and replay old events.

So this can be very useful if you're building systems where you're trying to derive analytical insights and possibly automated actions based on information flowing into the system. It's very useful to be able to experiment and say, OK, I wonder if this idea for a query is going to recognize the types of problems I want to identify. We have a way you can write the query, run it over historical data where you know something interesting happens, and see if it responds in the way that you want. So sorry, lots of people keep dropping their mics.

So yes, there is some control over the ability to virtualize time, but there isn't direct support for just rewinding a thing that's already happened. That would be harder, but replaying is absolutely a thing that we have a facility to do already. Right then. Looks like Rx is used under the hood. Yes, that's... we've already covered that.

Extending Reaqtor with custom operators

Can we extend Reaqtor like we can IQueryable with arbitrary extension methods? Yes and no. So yes, you can define custom operators. You've got to install them in your query engine, but Carmel already just showed you the code for doing that. Can you do it with extension methods? Not extension methods alone, because as I'm about to show you, how things work when you are consuming Reaqtor from outside of the service that hosts it, there you kind of need the service to have the same world view that your client has. So if you've defined a client side extension method, that's not automatically available in the service, because the service won't have a copy of your DLL, is what it boils down to.

But if you control the deployment of the service, then you can customize it however you like. You can write custom operators, you can customize pretty much anything, and you can rewrite queries as they come through the system as well. There's a whole mechanism for saying, OK, well, the query came in like this, but we're going to completely change how it works internally, for reasons of maybe distributing it across multiple nodes in the compute farm, or because we know we can handle that more efficiently by replacing this thing with other things. There's all sorts of stuff you could do, and if it's your implementation, then you have control over that.

Hopefully you can replace Spark and Flink. Well, it doesn't do everything Spark does. I mean, Spark does a whole bunch of stuff around dealing with data where it sits in data lakes, and so Reaqtor is very much focused on the event handling stuff. But possibly Flink. So I think we've caught up with the questions. All right, so I'll take more questions at the end, but let's get on with the next piece.

Demo: Reaqtor as a service

So let me share my screen. Hopefully you can all see VS Code. So we're back on theme with another AIS demo, but this one is going to use Reaqtor as a service. So you'll notice I've got things like gRPC and protobuf and the Reaqtor client libraries that I'm loading up this time, and that's because I am actually going to have this notebook connect to a service hosting Reaqtor. Now, actually, the service is running on my desktop. We normally deploy it to Azure, but I want to be able to show you certain things happening inside of the implementation, so I'm going to show you things in Visual Studio that's attached to it right now as a debugger, which would be harder to do if it was running up in a Service Fabric cluster in Azure.

So it's still outside of this particular notebook's process, so just to prove that, I'm going to grab the process ID that all this code's running in, and we'll come back later and verify that that's not the one that's actually running the query. So let's load up a bunch of namespaces to make this work.

The reactive client context

So here's where we're going to attach to the server. Now, because I'm running this locally, I've basically turned off security, and I'm just attaching directly over HTTP with no authentication whatsoever, because that's the easiest thing to do for local debugging. The interesting thing here is what we end up with is this context object. So if you're consuming Reaqtor as a service from the outside, the way you do that is through a reactive client context of some kind. So ReactiveClientContext is a type defined by the Reaqtor libraries, and this is kind of our derived version of it that knows how to talk over our communication channels to our implementation. But the base class is common to everything. You actually, in fact, use the same base class even if you're using Reaqtor in process, as you will see later.

So this, you can kind of think of it as being a bit like the DbContext in Entity Framework. It's a thing that exists in your process, but which represents some sort of service that runs elsewhere and gives you the ability to work with the entities and services that that particular remote thing does. But obviously DbContext is for relational databases, whereas this is for Reaqtor.

Structural typing with property URIs

So the next thing we're going to do is tell Reaqtor about the shape of the data we're working with. Now, I don't want to go into too much detail on this, but one of the challenges when you start working across process boundaries, and where you have a deployed service and you have client code, is you want the client code to be able to define its own types for working with things. And in the last demo, where I was using pure Rx, I was just using tuples to represent the stuff that came out of my restructuring query. But inside of Reaqtor, we normally do it slightly differently.

Reaqtor has this structural typing model, where the actual type of the object is not necessarily relevant, or doesn't have to be relevant, and instead you focus on the identity of individual properties. And so what we've done here is we said, well, I mean, I'm using this type called vessel position, but what matters is it has a property whose URI is this thing here, so vessel tracking longitude, and this one, vessel tracking latitude. Now, in my code, I can refer to these things by the C# property names, but when this gets sent over the wire into the service, it essentially gets translated into a form where these URIs are what matter.

And this gives us a way of defining custom types locally that don't actually... excuse me, don't actually have to be shared with the service implementation. And that's as much as I'm going to say at this point. There's a degree of complexity, and there are good reasons behind this to do with independent evolution and versioning, but that's as much as I'm going to say now.

Getting data in with Event Hubs

So in the Rx demo, I just fed data straight out of our AIS observer into our query, but here, obviously, I've got Reaqtor running as a service. How am I going to get data in to that service? Well, we're going to use Event Hub. So I've actually got an Event Hub instance provisioned up in Azure, and my AIS receiver is going to dump its data into that, and then our Reaqtor instance is going to make that available as an observable source. And I've already configured our service to know that this particular URI represents a particular Event Hub up in Azure, so we can just refer to it by name, and that gives us an observable of Event Hub notifications of, in this case, AIS message.

And actually, we don't really care about the Event Hub notification wrappers, and so we're going to use a select just to pick out the body, so we end up with an observable source of AIS messages. So one of the reasons for using Event Hubs is they actually give us the replay support that we need to get reliability in the face of restarts. Remember I said earlier that checkpointing does a lot of the work, but you do need to be able to replay events that have come in since the last checkpoint, and Event Hubs make that pretty straightforward to do. So that's one reason to use them.

What is an IAsyncReactiveQbservable?

Now, you may have noticed I've been saying these are observables of this and that and the other, but if you're looking at the screen, you might have noticed it actually says IAsyncReactiveQbservable, which is a mouthful. What is that all about? Well, let's start with the Q. This is connected to the fact that Reaqtor is spelt with a Q, and the logo is a great big Q. This also relates to IQueryable. So this indicates that this observable isn't necessarily local, that it's a thing that is based on expression trees instead.

So in .NET, in normal kind of collections of things, we have IEnumerable of something, but we also have IQueryable of something, and the IQueryable is typically used to represent things that are probably elsewhere. The most common use case is for, like, Entity Framework and things like that. It represents a collection of things that's actually on a completely different server. So whereas an enumerable is generally in memory, these things are often remote, and it's the same distinction here. This is a Qbservable because, although this object here that this variable refers to is an object in our process, the thing that it actually represents is in a totally different process, out in our hosted service, hence the Q.

And that means that when we do things like a select statement, this argument here, it's not actually a method, it's actually an Expression of Func of something. And if you're familiar with the expression tree stuff in .NET, what that means is that when the compiler encounters this, it actually builds an expression tree that describes that expression. So it's not generating a method, it's generating an actual expression. And if you've watched those Bart De Smet videos from almost 10 years ago, you might be wondering, is that a Bonsai tree? And yes, it does indeed turn into a Bonsai tree when it gets sent over the wire.

So the significance of the Qbservable is that these are essentially like avatars for the stuff that's actually happening elsewhere. What about the other stuff? Well, the reactive signifies the fact that this isn't plain Rx, this is the Reaqtive flavor of Rx. So it has support for a bunch of things that plain Rx doesn't, such as the ability to walk the structure of a subscription, which is necessary to support things like serialization. And the async bit means that this is presenting an async style API. So when we subscribe, we're gonna call SubscribeAsync rather than Subscribe, and that's important because when we subscribe, that's actually going to go and talk to the back end. It's a slow asynchronous operation, so we want to be able to await it. But conceptually, it's still just a source of events, so it still has the same fundamental concept as an IObservable<T>. It just signifies some things are happening slightly differently under the covers.

Output and the query

So that's the input side. What about output? Well, typically we might use something like an Azure Event Grid to push data out of the other end of our query, but we're not going to do that today. The reason I'm not going to do that is I want to show you some stuff happening inside the debugger, and so I want to keep it all internal. So instead, we're going to use a custom observer type that our server implementation registers as a standard observer, which just dumps stuff to our diagnostic log output. So I'm defining an observer, well, actually an IAsyncReactiveQbserver, but conceptually an observer of type string, that will just render whatever output we feed into it.

So we have our source, we have our sink, we now need to write the query that's going to bind it all together, and this should look kind of familiar. So our source, which reads stuff out of Event Hub as an observable sequence of AIS messages, is exactly the same concept as the original Rx demo. The execution model is different, but the concept is the same. And so we can use the same LINQ operator, group by, on the unique vessel ID. So exactly the same thing as before: we first of all split it into one stream per vessel, and then within each vessel stream, we separate out the navigation messages (these are the ones that tell us where the vessel is, how fast it's moving, which way it's pointing) and the ones that tell us about the name.

If you're paying very close attention, you'll have noticed this is not exactly the same query as last time. It's different in a couple of ways. We're not bothering with the vessel type in this example, because this particular demo is going to render stuff to diagnostic log output, so we're not going to color things in. And also, the way we invoke CombineLatest, it's structured a little bit differently, just for optimization purposes, but logically it's the same thing. So we group by vessel ID, we strip out the two kinds of messages, we combine them with CombineLatest, and then we flatten it back out again into this stream of vessel positions, reporting the position, the course over ground, the vessel ID and the name.

So let's run that. Now, at this stage, nothing is actually up and running in the service. So I am... sorry, I'm trying to catch these coughs before they happen, but they're sneaking up on me. I do apologize for coughing in everyone's ears. So we have defined the thing with the query we want, but because we haven't subscribed yet, nothing's actually happened. Nothing's even been sent to the service yet. It's only when we actually try to create the subscription that the whole thing gets sent over the wire to our service to get it up and running. So this is the point where things happen. And sorry, I just need to make sure that I've actually started the process that feeds stuff into the Event Hub.

Yes, I have, that's running. Good, so we can go with this. So I run this, and this is the point where it's going to try and create the subscription in our Reaqtor service, and that has succeeded. And the subscription ID is actually a URI, so the notebook is very helpful, it spits out all the properties for me. That's the URI identifying our newly created subscription. So that is now running.

Watching the query run in the debugger

So I'm now going to switch to Visual Studio, and annoyingly, we can't actually change the font size of this bit, so what I'm going to do is attempt to grab a screenshot of that so I can show you in a bit more detail by zooming in. So right, so this is the diagnostic event output, and you can see our logging observer has received a message. And that there is the vessel ID, that's the vessel's name, Symbol apparently, and this is its latitude and longitude, and the process ID, 81252.

I said I was going to demonstrate this is not running inside of the notebook process. Let's go back to the notebook and check what process ID this was running as: 5089. Definitely not the same one as the events coming in here. Furthermore, I want to show that these things are definitely independent. So what I'm going to do is find, in Task Manager, I am going to find the .NET Interactive host process. So that was 5892, dotnet.exe is the thing running my notebook, and if I just close the notebook, that process goes away. So the line that was highlighted isn't there anymore.

So that process has gone, but if I come back in here, I think we may have... there we go, still running. Yes, it was just in the middle of doing a checkpoint. The checkpoints take a little bit longer when running in this mode, because everything's hooked up to the debugger, so it runs a bit slowly. Normally checkpoints happen in less than a second, but they're a bit slower on this setup. But you can see it's still going.

Rebooting a node in Service Fabric

Now, the next thing I'm going to do is deliberately give it a brutal kick. So get that out the way. This is the Service Fabric Explorer for my local instance, and we have one application running here, our Reactor host, named before the Q came along, but never mind. And this is a rather stripped down version of it, because for the purposes of this demo, I wanted to be able to find the process that was hosting the query we'd set up, which is a lot easier if you've only got one query engine running. Normally you'd have a few, because you want to distribute the load across all of the nodes in the compute farm. You normally have at least as many query engine hosts as you've got nodes in your cluster, sometimes more. In this case, for simplicity, I've just created the one, so I know for certain that it's running inside here.

Now, you can see that Service Fabric has actually created three instances of this logical query engine host, and the reason it does that is we've configured it to have a couple of hot standbys ready in case something bad happens to the node that it's running on. So we've got node 0 is hosting our primary, but it's spun up a couple of other ones. It started the process, done all the initialization, but it simply hasn't told it to go yet, and so these are ready to step in at a moment's notice if anything bad happens to that node there. So let's make something bad happen to that node there.

I'm going to come in here to the list of nodes, and I'm just going to say please reboot node 0, which is where our query engine primary is currently running. And if I just... oh, it's refreshing itself, not quite there yet. Refresh it again. Oh, there we go. Right, so now the primary's on node 1, and it's apparently trying to put the secondary back on node 0, which is an interesting choice, since node 0 is rebooting, but hey, it doesn't matter. We've got a second secondary ready to go, and we've got a primary here, and so it's still running.

So now if I come back in here, it's still merrily spewing out lots of names. So we haven't had the problem that we have with the notebook, where when you restart it, it takes ages to build everything back up again. It's left right in, because of the statefulness that we talked about. So I'm just going to quickly verify that it is running on a different process. So let me just make a bit more space here, so we can see these two side by side. So the one on the left was the one from earlier, process ID 81252, and then if I scroll over, after I rebooted, 29536. So you can see it has successfully migrated the service from one node to another, and it's just picked up from where it left off. So this illustrates the principle of being able to recover from failures.

Inside the Reaqtor repo

So that is essentially the low level version of doing all this with Reaqtor, but what about the actual Reaqtor repo itself? The next thing I'd like to show you is something that's actually in the code base, because everything we've shown you so far is a little bit removed. The reason we have held off until now is that the demos in the Reaqtor code base are a bit more complicated. They're mostly written by Bart, and he wanted to illustrate all of the moving parts so you could see exactly what was happening, which makes them a little tricky to understand.

So here, did I already load this? No, I didn't. Let me quickly fire up Visual Studio. So when you download the repo, you can just open up this All.sln. It doesn't require any complicated sort of setup of build scripts or environments. You can just either type dotnet build at the command line, or you can just open up the solution in Visual Studio. And it's obviously decided to open on a different monitor, so as soon as that gives me back control, I will show that to you.

Nuqleon, Bonsai and Reaqtive

But you can see here the layers that Carmel was talking about. So we've got Nuqleon, this is all the low-level stuff. Oh, it's come back, now I can show you this in Visual Studio, which will be better. So we have Nuqleon, which provides the kind of low level pieces. For example, this is where all of the expression serialization stuff is, so that's the Bonsai project that knows how to serialize .NET expression trees, and then the compiler service that provides a bunch of other expression handling that that relies upon. So all that stuff can be used in isolation. If you just want to teleport a .NET expression tree from one process to another, you could use these libraries without using any of the other stuff, because Nuqleon's kind of a layer beneath everything else. It doesn't have any dependencies on the higher level stuff.

Then, as Carmel said, Reaqtive is kind of the replacement for Rx, or the successor to Rx. So if I come in here and look at the Reaqtive.Linq project, you can find all the operators in here. So All, Any, Buffer, GroupBy, that's what I was using earlier. This is where they are actually implemented, so you can find the code for that if you want to poke around. But the goal I had for now was to show you how you can actually get up and running with some of the samples.

The Shebang samples

So if you go into the Reaqtor folder, there is a samples folder inside this, and inside that, a good place to start is the entirely unhelpfully named Shebang folder. So what is Shebang, and why is it called Shebang? It's as in the whole shebang. So as we've heavily hinted, you have to provide quite a lot of things to the query engine before it will agree to do anything for you. You have to tell it exactly which Rx operators you'd like to have available. You have to provide it with some sort of checkpointing store. You have to provide it with a threading model, sorry, a scheduler, strictly speaking, and all those sorts of things, and it won't start until you've given it all the things it needs.

So the idea behind the Shebang project is to say, well, real applications obviously are going to want to decide how to implement all of those things, but if you just want to try this stuff out, then it's probably useful to have a thing that just gives you defaults for all of that. So Shebang gives you a whole load of in-memory implementations of all of the things that you will need to get an environment up and running. So that's what that's about, and that's a good place to go in if you want to start tinkering with Reaqtor and start running things.

So you'll notice that there are actually some Python notebooks in here. So a lot of the demos are Python notebook based. I'm actually going to use that, but before you open any of these, you must have built this solution, because these have references directly into the bin folder. So nothing will work unless you've built the project in Visual Studio first. But once you have, you can then go and open up Visual Studio Code in that Shebang app folder and open up one of the Python notebooks.

Demo: Bart's self-hosted AIS notebook

And hey, it's yet another AIS demo, but this one shows you a bit more of what's going on inside of Reaqtor. So as before, it's going to load up endjin's freely available AIS parsing libraries. So Bart wrote this as his version of our original demo. He's changed a few things. Most of the setup is done with functions rather than just newing up the objects, and then it runs everything all at once at the end. The Bing Maps integration works pretty much the same way as ours does, so we have, in this JavaScript cell, a thing that says, I'm going to handle the vessel position commands and update the map with them. Here's the map itself. Let me just scroll down, make sure that loaded OK. Yes, it did, good.

And then this loads this Shebang app thing, so that it has an easy way of creating a fully configured, if rather artificial, query engine. So then this enables Bart to write these helpers. He's got this WithNewEngine method. This takes a function that you supply, and it will invoke that function, but before it does that, it will create a brand new query engine, and it passes in the client context to you. Now, remember from the previous demo, the client context is the means by which you control a Reaqtor instance, and you can actually get hold of one directly on a query engine object. That's what's being passed in here.

So this creates a query engine, configures it with a bunch of standard default operators for you, gives it, you know, the bare minimum that it needs to live, and then it calls your function, passing in that query engine. And then when you're done, it generates a checkpoint, and that will cause the query engine to write the checkpoint state into the store provided. And by the way, the Shebang thing also provides an out of the box in-memory implementation of this state store, so you don't have to write one. And it also provides the thing that enables you to feed events into the engine from the outside, and to extract events the engine has generated and get them back out again. So that's what this ingress egress manager is all about. So basically, this is the minimal way of running something in the query engine.

And this method does it all again, but rather than creating a brand new engine, this one creates an engine by recovering from whatever the last checkpoint was in the store. So let me just run this so that those methods are available. It also has a way of writing out the store to disk, so you can go and poke around in there if you're curious. This next thing just checks that all of that's working. So this just spins up the query engine, creates a timer, lets it run for a few seconds, so you can verify the things actually working, and then shuts down again.

So if you want to, you can then persist the thing out to disk. I'm not going to show you that, because it's basically a bunch of base64 strings inside an XML file. It's not particularly easy to understand, so I'm not going to go into detail on that, but that's just an implementation detail of how this whole Shebang memory store works. This verifies that we can load that file back in and recover the state. Now, actually, the timer is still running, but you can't see it, because this demo doesn't plumb things through to the notebook in quite the right way. Anyway, that doesn't matter, because we're now going to go and do the thing we want it to do.

Ingress and egress pipes

So having established that we are able to create a query engine in memory, and this is all living inside the .NET Interactive host process, having established that that's working, we now do the stuff like before for hooking up the AIS events to the map. So we need to get hold of the .NET Interactive notebook object that lets us send messages into JavaScript. So we've got that. Then we define the data model types to tell Reaqtor the shape of our data. Now, Bart made this a bit more complicated than my one, but I mean, conceptually it's the same thing. Ultimately we're going to produce these things as the output, so that's what's going on there.

Here's the command that's going to be sent from C# to JavaScript to update the map. This is pretty much exactly the same as the one you saw earlier. Bart then defines an observer that can receive those commands and sends them to the JavaScript kernel for you. So what then? OK, so when I demoed our Reaqtor as a service implementation, I was using Event Hub to get stuff in, and I was using our diagnostic mechanism to get stuff out. Here, well, we don't have an Event Hub integration in the repo, so this uses the ingress egress manager to kind of poke pipes in the side of the query engine.

So this is saying, I'd like to create a couple of things that live inside the query engine, but which I can get access to from outside the query engine. So this ultimately ends up being sort of an observer that we can push events into that will then be available on the inside of the query engine through this name here. This one is creating a thing that is available through this name in the query engine that we can observe to get the processed events out of the query engine. So this is just how you plug things in and out of the query engine. So obviously in our implementation we have something similar, but we're creating things that let us connect up Event Hub and Event Grid and so on. This is just some diagnostic monitoring, I'm not going to talk about that.

Conforming messages and building the query

And now we start to get to the heart of the matter, three quarters of the way through the notebook. This is why I didn't start with this demo. So this takes the messages that our AIS library, the endjin AIS library, produces and just converts them into a slightly more uniform representation. So when we produce these, the actual concrete type might be different for each message. So if it's a navigation message, it'll be one class. If it's a name message, it'll be a different class. But Bart decided he wanted to have everything be the same type, with a sort of discriminator saying what sort of thing it is. So everything in his thing is this AIS message type. This is one of the ones he defined earlier. If I scroll back up in his data model, it's that thing there. So he's basically conforming everything to this type here.

And then, did I run that? Yes, I did. And he's got some cleanup stuff here as well that I'm not going to talk about. This hooks things into the client-side kernel, so this actually rigs up the output pipe that we created with the ingress egress manager to the kernel command observer that's going to forward these commands up to the map, ultimately. And then finally, we can actually create the query. So here he's using his WithNewEngine helper, and now remember, this thing starts a brand new engine, which will end up checkpointing its state into the store when our callback completes.

So what we do here is we are passed in a context by this helper, and this is our way of talking to the query engine. And so we ask to get hold of an ingress object. So this is again part of the helper mechanism. This, when applied to a context, gives you an IAsyncReactiveQbservable that represents the thing we created earlier from the outside. So this is the pipe that we're going to feed AIS events into the system through. This thing gets hold of the thing that represents that inside the query engine, so that's how the two things are tied together. So we already created the other half of that pipe, the bit that we can push events into. This represents the other end of that pipe on the inside of the query engine.

And this is the output piece. So earlier we created a pipe on the outgoing edge of our query engine, and we already have the bit of that that's outside the query engine. This represents the other end of that pipe on the inside of the engine. So we're now going to stitch these things together. So this logically has the same place as the Event Hub observable in my earlier thing. It's the thing that the events actually come in through, and this is the output.

And now this should start to look familiar. We have a source of AIS messages, we group them by unique vessel ID, then for each per vessel stream, we sort out the navigation messages and the name based messages, and we use CombineLatest to turn those back into pairs of things, and then flatten it back out into this thing here. This looks exactly the same as it did with the last demo, the difference being that we're now self-hosting the query engine. So I'm going to run that, and this all happens very quickly. It creates the engine, creates a subscription and then immediately shuts down, because this method doesn't hang around. So this will not have been running long enough to actually process any data.

Restoring from the checkpoint

So the next step is we save out our checkpoint to disk again, just for fun, and then we run it again, but this time with the WithExistingEngine helper. And remember, this creates a query engine that restores from the last checkpoint written out to that store, and it's going to pass us the context. And then we start up the process that's going to receive the messages that come out of the query engine and pass them on to the JavaScript side of things. This hooks up the actual AIS receiver to the thing that feeds data into the query engine, and we already created the subscription in the engine, so that should be good to go.

So as soon as we run this, it should actually start processing data. So I'm going to run this. It prints out some debug stuff. You can see information is coming in. So if I can scroll quickly up to the top, where's my map? There we go.

Boats are starting to appear, not colored in this time, because this query doesn't do the coloring in piece. It just looks at the name and the ID. I think that's now stopped, because it only runs for 10 seconds, but this demonstrates that you can run the whole thing inside a .NET Interactive host process. So this is the sort of bare minimum to do to get the AIS demo working without any extra supporting infrastructure. This is all using stuff that's purely in the repo, so that's a decent place to start if you want to look at what's there in the repo and say, OK, how do I actually get something up and running with this?

How does Reaqtor compare with other technologies?

So just a couple more things to talk about. People have asked about, hey, how is this different from Spark? So I'm gonna slightly rephrase that and ask the question, what else is out there that is like Reaqtor? How is it similar and how is it different? Now, I'm not going to go into huge amounts of detail here, because if you don't already know these systems, it probably won't help you very much, but it is worth just having an awareness of some things that are there that are kind of similar, and how they're different.

So the obvious contenders are all the things that come out of the Apache Foundation in this space. There is Apache Spark and Samza and Flink and Storm. So Spark is sort of the underpinning piece of this. It's kind of a distributed compute engine, and then a lot of people use that for SQL-like processing of data stored in data lakes, but you could also run event processing stuff on top of it. Storm provides a somewhat low level layer on top of that. Flink provides a slightly higher level of abstraction. So these are similar things. I'm going to talk about what makes them similar to and different from Reaqtor in just a minute, but right now let's just go over what's out there.

Siddhi is probably actually the closest thing to Reaqtor in the Java space, I would say, because it can be used in all sorts of different ways. And then there are some things that are already in the Microsoft world. So we have Azure Stream Analytics, obviously there to process streams of events. There's also Project Orleans and Akka.NET. These are both kind of actor based models that often get used in similar sorts of applications.

Technology stack: the JVM or .NET

So let's talk a little bit about these. How might we compare these to Reaqtor? Well, one way is to ask what sort of technology stack are they based in. And the things on the left and Siddhi are firmly in the Java world. So if you're running Apache Spark, it's running JVMs. If you're running Siddhi, it's a Java set of libraries, so you've got to be in a JVM to use that, so either using Java or Scala or some other language that can target the JVM.

Now, you might be thinking, well, hold on, don't people use Apache Spark from Python? And yes, they do. It is possible to drive Spark from the outside, from Python. You can do it from C# as well, actually. But if you want to do anything slightly out of the ordinary, if you want to customize it at all, or install your own code in there, or you just understand how things are working, you very rapidly are confronted with the reality that it is a Java based system. You can't really deeply understand Spark without having at least some knowledge of how it works at that level, in my opinion.

This is the Oxford .NET user group, so possibly you might not be that excited at the prospect of a JVM-based system, but maybe not. So that's one significant difference. Those are all in the Java space. The things on the right are more in the Microsoft world. So Orleans is .NET based, so is Akka.NET. Azure Stream Analytics, that's interesting, that one. Its edge based model is .NET based, so if you want to push out computation to the edge with that, you write that in .NET, but its server side model is actually JavaScript. So it's kind of two different things, really. So that's one way of looking at this. Do you want to be in a Java world or a .NET world or something else?

Computation model: actors or formal models

Another way we can look at it, though, is the computation model. How is it that we actually describe what it is we want to do? So in this way of looking at things, the two that sort of stand out as being a bit different from the rest are arguably Project Orleans and Akka.NET, both of which use the actor model, or something resembling the actor model. That turns out to be a contentious point. The Orleans team have stopped saying that they do the actor model, because they got bored of people saying, well, it's not really the actor model, it's sort of something different. We don't care, it's like, it is what it is.

But anyway, the basic thing is that the way you tend to implement your actual application logic is to write in some general purpose programming language, like C# or F#, and then these environments will host that and will enforce certain rules about how that code is run and how components interact. But the logic is basically code at the end of the day, written in a fairly ordinary language. Whereas pretty much everything else on this picture takes a more formal model.

So a lot of the stuff in the Apache Spark space, and also Siddhi for that matter, and actually Stream Analytics as well, it looks an awful lot like SQL, at least from a moderate distance. It's all modeled very similarly to the way that relational databases work, in that you have these kind of tabular-like sources of things, and you have operations like joins, grouping and so on across them. It's not an exact analogy, but it's heavily informed by that approach.

And one of the benefits of this approach is that if you have a formal model for how the data is processed, these systems are able to restructure what you've asked them to do. So if you're using Siddhi, for example, and ask it to evaluate a query, it has the option to rewrite that for you, because it knows the various different mechanisms you've asked it to use, it knows how they work, and it knows that it's able to restructure them and possibly distribute code in a different way. And Apache Spark does the same thing, even just with queries over data as well. So this is the advantage of having a sort of formalized data model and well-defined operators over that, as opposed to just the freedom to write whatever code you like.

Where Reaqtor fits: a formal but open model

So how does Reaqtor fit into this picture? Well, at the lowest level, it certainly has a formal model, which is the Rx model, but that's actually relatively simple. So that doesn't cover things like grouping, windowing, aggregation and so on. However, all of those things are available in the set of operators that are offered. So the Reaqtor code base provides all of those things: windowing, aggregation, filtering, grouping, and various other high-level operators for doing temporal joins and things. There's a whole load of stuff in there for doing that, but you're not obliged to use it.

It is entirely possible to write your own custom operators, and actually we did this at endjin once, for one particular project. We realized that we could improve the efficiency by defining our own custom operator that worked in a particular way, for a kind of combination of grouping and aggregation that wasn't working so efficiently with the built-in operators. You can do that, but then that raises the question, well, if you are able to arbitrarily customize what the operators do, does that not take away the ability to have this automated optimization?

But the answer to that is no, it doesn't, actually. You can still do it, because in Reaqtor, the thing that does the equivalent of the query plan, a component called the query coordinator, you have control over that. You can define what that does. So if you want to introduce custom operators, you can introduce the understanding of those operators to your query coordinator. So you kind of have, in some ways, the best of both worlds, in that you have this formal model, which is something that can then be optimized automatically, but it's not a closed model. You can extend it.

I mean, the downside of that is that extending it takes a lot of work to actually do it properly, so it's not easy, but it's arguably a more powerful model. So that's one way in which Reaqtor is quite different. Its non-negotiable formal bits are just Rx at the heart of things, and everything else is composable and customizable on top of that.

Options for reuse and hosting

Another thing we can ask is, how wide are the options for reusing these things? Most of these things in this list kind of take the assumption that you are going to run your computation in their world. So there'll be something running Akka.NET, or there'll be something running Apache Spark, some setup that does all of that, and it will then deign to run your query or your code or your subscription or whatever. It's not entirely true for all these things, you can use them in other ways, but that's sort of the primary model.

With the exception of Siddhi. Siddhi is very much designed to be a thing that can either be used as a feature of a platform as a service environment, or it can be used at the edge. So this is why I say Siddhi is probably the closest thing in the Java world to Reaqtor. Although it doesn't have the same flexibility of model, and it has a different set of underpinnings, it still has the same level of flexibility when it comes to reuse.

With Reaqtor, as we've mentioned, you can host it in lots of different ways. You can run it in a multi-node compute farm, you can run it on a Raspberry Pi. It can be run all sorts of different ways and configured in different environments, and it's designed very much to support that. And Microsoft have done this in the past. They had versions of Reaqtor running on Windows Phone. There's bits of Reaqtor that have run inside of Windows, and so on. So it is designed to be a thing that can run in all sorts of different places.

This does make the code base quite hard to approach, though. One of the reasons people have so far struggled a little bit to understand what Reaqtor is and what this code base actually contains is it is so flexible. There's so many different ways you can use it, it really isn't all that obvious what you've got and where to start. So it is a thing that makes Reaqtor powerful, but at the same time, it also makes it difficult to get started with. But I personally think that's a price worth paying, but it's a thing to be aware of. So that's another way it distinguishes itself from all these things. And I think that was everything I was going to say, so I'm going to hand over to Carmel now, because I've been talking for too long.

Summary and how to get involved

Carmel Eve: Yeah, so finally, I guess, just to kind of summarize. We've seen that Reaqtor extends classic Rx by adding the ability to support long-running and stateful queries. The platform enables us to continually process a huge number of events every second, and these can run over a period of years. Through this persistence and reliability, we can support planned maintenance, migrations and even completely unpredictable failures. Most of the examples we've shown are around the processing of shipping telemetry to track the whereabouts of vessels, but this long-running and high throughput processing allows us to support a huge range of complex and big data scenarios, most of which we've not even thought of yet.

So finally, I guess you sort of wanted to ask, what now? And you may have noticed, on my quick fly through the site earlier, that there was a tab for contribute, which is refreshing. Basically, there are loads of ways you can contribute. This ranges from initially just starring the repo on GitHub, and this tells us how many people are interested in the project. You also can help promote, so this could be blogging or demos or even speaking at your local user group. You can also contribute actively to the project, so that could be documentation or samples, or it could be actually making contributions to the code, and there's a load of issues on the GitHub repo which are a good place to start.

Finally, it could be you or your employer sponsoring the project. And we also have a Reaqtor Twitter account and a Slack workspace. So basically, in whatever capacity you are able, please get involved. And I think that's about it. So yeah, thank you all so much for listening. There's a few links on screen: the reaqtive.net site, and the Reaqtor repo, and the endjin site if you want to know more about us. But yeah, so if anyone's got any questions, please ask away. Thank you.

Questions and answers

Ian Griffiths: I'm just taking a look through the list of questions. Someone told me, Visual Studio zoom in, Ctrl+Shift+Plus. That works in VS Code. That sadly does not work in Visual Studio, but thanks for the suggestion. So, talks, demos. I was thinking Reaqtor would be a source for Orleans. Yeah, I don't know, either. Things could happen in that space. There's nothing there at the moment, but it's a possibility. And then Howard's saying some things that I will not attempt to reproduce. Right, OK, well, that seems to be... I've got to the end of the questions, there wasn't a whole lot more there. So OK, well, thank you very much, everyone, for coming. I hope that was useful and/or interesting. So yeah, I'll hang around for any further questions, but otherwise enjoy what remains of your evening.

How does persistence cope with changes to the query?

Please, special technical questions. So, how does persistence work in the face of changes to the query slash graph? Does it save all the intermediate results that it can reuse? Right, so this is possibly going to change, because there's an experimental feature in the code base. At the moment, persistence is at the granularity of individual subscriptions. So if you have something like we have, which is using higher order operators like group by that explode into many more observables, it's still treated as a single subscription. Because ultimately, that's the point into the system: you define the thing, you subscribe to it, and it lives until you unsubscribe from it later on. And so that whole thing gets serialized and deserialized.

And actually, that does have some performance issues for the sort of things that we're doing. It means that if anything changes in any of the individual subscriptions, the entire thing gets written out. But there is a feature currently in experimental state which does what is called per operator persistence, and that makes it possible for individual operators to have the kind of dirty or not changed bit managed independently. So inside of Reaqtor, each operator in the tree does maintain that information, so it knows whether it has changed or not. But the serialization, the checkpointing mechanism, presently doesn't use that. But there is a change coming that would enable that, once it gets kind of brought in.

So yeah. Is the write volume huge today? Well, it can't be more than four megabytes, because things stopped working at that point. Is it huge? It really depends on how much state there is. It's relatively efficient, what it writes out. There's actually not much data getting written out here. Actually, I've oversimplified things as well. There are some ways in which certain higher order operators can actually minimize some of this, so it's not quite as bad as I've made it sound. There are some mitigations against that. But yeah, it can get large for that style of query, but that's the thing that's actively being worked on.

Hosting Reaqtor on Kubernetes

If we wanted to host an on-prem Reaqtor instance on a Kubernetes cluster, how much work are we looking at? OK, so you would need to do all of the Kubernetes integration yourself. Easily months, probably over a year to get that, because there isn't any Kubernetes based support right now at all. So yeah, that would be a non-trivial project, I would say. Probably not lots of years, but probably more than a year would be my guess. So we've been working on this for, what, four, four and a half, five years, to flesh out all the bits. I mean, it's not been full-time work, but it's been, you know, it's been an endeavor to plug all the bits together. We also didn't have access to the source code at the time, so that made it a lot harder.

Audience member: I saw this come up and thought, oh, that looks really, really cool, but I just started at a place that's very on-prem, so yeah, no buying cloud services, unfortunately.

Expression as a service: why Reaqtor is high density

Panellist: One of the points, I think, that's also key to understand is the high density nature of Reaqtor. So if you think about a website, that's an App Service, or, you know, an IIS process. Think about a container, that's another unit of compute. Think about a function, that is, you know, a kind of a method or a small executable. Reaqtor is an Rx expression, you know, an expression tree. And so you're pretty much down at kind of that, like, atomic level of the minimum unit of compute that you can kind of have. And so it really is this kind of expression as a service, which is why it's high density, because you can have tens of thousands of these queries running inside a query engine, and then you scale out the query engines as your elastic units of scale.

Which is why... the whole reason that we started on this journey is because we were looking at a customer who had, you know, millions of broadband customers, and we were thinking, well, how do you essentially monitor each one of those customers? And so you start looking at things like, you know, actor frameworks, and managing a million actors is still quite a complex thing. And then there was a white paper around Reaqtor, it was actually around Service Fabric, and they were talking about the fact that in production they have 500 million queries or subscriptions running and being evaluated per second. And it's like, well, if they've got that running at planetary scale, we only need something 1/500th of the size in order to deal with our kind of national level problem.

And that's where it suddenly got very exciting, because it's that scale of things. It's that, yes, you can run your one query in an interactive notebook and do interesting things with it, but then you can take that query, run it and clone it out, and then monitor all the things with it, and that's where it gets really exciting. It's monitoring real world objects. And this is kind of where the technology came from, which is, how do you cost efficiently have high performance compute where you can monitor millions of real things, whether they are stock ticker prices, you know, airplane flights, people's travel plans of going to a meeting?

It's all of these kind of really complicated scenarios that, you know, if you were trying to scale those things out globally, would break the bank, but using this kind of technology makes it actually intrinsically affordable.

And I think, you know, in Carmel's talk a year or so ago, we talked about using Functions to go from a 45 node server cluster down to one Azure Function, you know, in order to process the same amount of data, and go from it taking 27 hours to it being near real time. That shows you kind of what you can do if you leverage the right technology. And this is going down to that micro level, then scaling back up again and saying, well, how do we monitor all the things? And that's where I think it gets really, really exciting. How do you monitor every boat? How do you monitor every broadband provider?

And what's really interesting is, you know, a lot of this work has actually kind of been built on each other. So the work we've done with AIS was actually based on a load of work that we did around RADIUS, which was a network protocol that, again, we had a day's worth of network traffic from, you know, millions of customers. I think it was about 40 gigs worth of data, and it's how do you effectively process that so that you can do this kind of analysis?

Virtual time and .NET Interactive as an IDE

And I think one of the demos that we're going to release soon is that original prototype that we built, that processed 40 gig of data in something like 90 seconds and showed all of the broadband faults across the network over a 24-hour period. And when you start looking at how you can process that amount of data that rapidly, it starts becoming a tool that an individual user can use. You know, so you're in your interactive notebook, you write your query, you run the query against these large data sets, you get the results, you know, being streamed to you as they happen.

And what was really interesting about that particular scenario was it was using virtual time, because all of those queries were based on temporal semantics, but we were doing it historically as a simulation. And the only thing that would be required to take that and turn it into a real thing is to swap it from going from historic data to a live data feed. And this is all really powerful. This is kind of why we've been kind of working with the .NET Interactive team, because .NET Interactive can become your IDE for building these kind of scenarios.

And so that's what I think is really powerful, is it's not working in Visual Studio. It's having little bits of craft here and there to kind of connect to your service, but then, as a domain user or a power user or developer, you can start doing interesting kind of, like, data science analysis over these complicated problems in a totally different way than I think we used to, historically.

Getting data into Reaqtor

Audience member: Can I jump in quickly? That AIS case sounds really familiar to me. I mean, I work in a Formula One team, and we have live and historic data that we process at very high frequencies, as you might imagine, and we've got to get from one place to another. One of the things that... like, I missed the beginning of the talks, I was in my community, but, well, I don't know, of course, it's what sort of infrastructure do you need? So Reaqtor is your subscription and your processing. What sort of infrastructure do you need to actually have the stream running that you're subscribing to? Is that it?

Ian Griffiths: It's sort of up to you. So this is both the strength and the difficulty with Reaqtor, is that you can use it more or less however you like, which at the same time means you may be kind of on your own for getting it working the way you want it to work. So we've done a few different ways of getting data into it, depending on the application. So I was showing you Event Hub in this case, but we've also fed stuff in more kind of basically mainlining into the system through a custom channel.

So whatever you want to do, it is technically possible. You just need to work out a way of ingesting it in a way that doesn't conflict with the basic rules of how things work inside of Rx. So if you have existing proprietary mechanisms for shuffling data around, it's not too difficult to accommodate those, because you can write custom ingress operators to make that work. So yeah, it depends, is the short answer, but yeah.

Audience member: So something like a Kafka or a Rabbit message queue system, maybe?

Ian Griffiths: Yep, yep. And Microsoft have used ZeroMQ internally as well, so anything of that kind could in principle be made to work. So yes, and it's not a huge amount of effort to integrate. Getting it to perform and be stable is a slightly different matter, but yes, it's certainly absolutely possible.

Audience member: Thank you.

It depends: optimizing queries for the scenario

Panellist: I think "it depends" is a phrase you use a lot with Reaqtor, because everything you do is based on some kind of scenario, and you optimize everything for that scenario, especially if you're processing, you know, gigabytes of data and wanting to get performance out of it. Yeah, the query you write, you know, that AIS demo, it was very interesting, because we wrote it... yeah, paired and wrote it one morning in Rx. It's, oh, this is a beautiful query, it's really expressive, it's using all these high-level, you know, interfaces. So we've gone from a really compact binary protocol at the network layer up to expressing in terms of interfaces and C# records. It's like, this is beautiful.

And then kind of we showed this to Bart, and he kind of looked into the matrix and just went, yeah, that's got to be optimized, and then rewrote it completely because of the operator states. Because in order to make that, you know, checkpoint and restart, you know, in under 10 milliseconds, you kind of need to simplify all of those constructs. So what we did from an aesthetic and us understanding and solving the problem is fundamentally different from writing the high performance version of that. And that's the same with all C#, you know. If you're using Span<T> and things like that, you have to have a slightly different kind of programming approach than if you're just kind of reading data and not really worried about performance and allocation, and Reaqtor is very much the same.

It's, what's the behavior and taxonomy of incoming data? What kind of queries am I writing? Are they stateful and temporal, or are they, you know, or are they aggregating, or, you know? And that's part of the kind of evidence-based scientific method of testing the stuff and benchmarking it and trying it, and then once it, you know, hits all of your characteristics, then deploying it. And that's kind of the fun of it. It's like writing a SQL query and having to do your, you know, looking at all the query planning, your optimization.

What's fun is when you write that query, then scale it out to, you know, a million subscriptions for users, and it runs for 10 years, and you have to, you know, you have to make sure that this stuff is kind of optimized for all of those scenarios in terms of upgrading and patching and bug fixing and the like. So yeah, it's interesting, because there are so many different facets to these kind of queries, which on the face of it look kind of quite simple, but have lots of other, yeah, NFRs around them.

Large windows and operator state

Audience member: How do you optimize the state for something like, I want to say, the average value for the last day, and see if I'm higher or lower than that now? But then the state is potentially, you know, 24 hours of point data. I mean, is it shuttling it in and out when we save state, or is it going to have to write that whole graph every time I add one to it?

Ian Griffiths: If you genuinely want to sort of have a window where things drop out of one end of the window to the middle second as the thing moves along, then yes, you're gonna have to do that. If, on the other hand, you're prepared to live with a little bit of lower resolution and say, well, OK, what about if it was to the nearest minute, you could first feed it through something that's... there's the buffering and window operators that can kind of chunk stuff up by time unit, and then you could do a window over that, and you wouldn't have to have anything like as many values being held. So it sort of depends on the resolution you need, really, because if you fundamentally need it down to a very fine-grained level, there really isn't anything you can do beyond holding on to all the data.

Audience member: Right, so, right, the question was, well, does it have to keep rewriting that whole data, or is it intelligent about adding? Oh, OK, supposing I do have a buffer of the whole day, but, yeah, I've talked or whatever internally.

Ian Griffiths: So the reason I'm hesitating is that this is one of these things where, depending on how you structure the query, certain mitigations might be open to you. I suspect, though, this might be an occasion where actually writing a custom operator might be a useful thing to do, because it might give you a way of optimizing that. But I hate to give this answer, but it depends. There's several ways you can structure it, and there are trade-offs. What it doesn't have, though, what I can say is, there are no specific optimizations built in for that sort of thing. So it doesn't have any built-in notion of, for example, kind of a ring buffer type arrangement, where I can sort of peel bits off one end and tack them on the other. The serialization mechanisms at the operator level are currently all or nothing. So at the moment, given the current state of it, that's not a thing you could easily change. So yeah, it's trickier.

Audience member: If you had a delay of 24 hours as one part of your Rx query, it wouldn't be able to go back to your original data source or anything. It's gonna be keeping it inside Reaqtor for 24 hours?

Ian Griffiths: Well, you would find there isn't a delay operator, precisely because it would actually be expensive to make it work right, and so they don't want to encourage people to use it. And so yeah, it's not there. There are things you can sort of do to recreate it, but you're sort of then confronted with the actual cost of what it is you're doing up front, which is probably the right choice under the circumstances. So yeah, it's not magically going to find the best way of doing everything under every conceivable circumstance, and yes, if you've got very large windows that you're operating over, then that's not a scenario it's been particularly optimized for.

Audience member: Yeah. First, what support... if you are writing your own custom operator, what support is there for efficiently saving state?

Ian Griffiths: So this is starting to get into quite a deep technical dive, but essentially there's a notion of two different ways of writing out state. So it is possible to have things that put limited amounts of data into the checkpoint state, which is then essentially a pointer to something somewhere else. So that can give you a back door for doing it differently. So you end up with sort of write-ahead stuff into a different store, and then once you know that's in there, you can then say, OK, the checkpoint can now refer back to that, because the checkpoint data doesn't actually have to hold on to it.

You then make your life much more complicated during recovery. So normally operator state recovery is pretty straightforward. You're handed a bag, you pull the stuff out of it and you go. But if you want to do something more subtle like that, then, you know, you're going to pay a price for complexity. But it is a thing that I know has been done with Reaqtor. I personally haven't done it, but I've had conversations with Bart about that sort of thing, so I know there are ways around improving the efficiency of this sort of thing. But yeah, that's as much as I can really say at this stage.

Audience member: OK, thank you. Great presentation.

Ian Griffiths: Thank you.

Carmel Eve: I'm actually also... sorry, I'm actually also going to head off. I haven't eaten dinner yet, so I think I'll get something. But yeah, thank you so much, everyone, for listening, and yeah, please get involved. Thanks, bye.

Design notes, Pearls and the museum

Panellist: Thank you. There are... I did post some links to some of the docs on the site, which are kind of more like design notes, basically. So one of the things that we were very keen to do as part of this process was to get Bart to do a brain dump of all the ideas. Because if you read the little history of Reaqtor book, you know, essentially the history goes back to 2005 and shows all the projects that have either inspired or directly influenced Reaqtor. And so so much thought from so many kind of amazing people has gone into designing the system.

And so the documentation is not what I would call kind of documentation from a product perspective, but lots of it is basically, you know, if you look at the source code, there are Pearls, which are essentially kind of little samples of how different aspects of the framework work. There's a pretty impressive RxL sample, which shows kind of how to build Excel using components from Reaqtor, where the cell is essentially reactive. You know, Excel is basically a reactive graph, which is quite mind-blowing in itself. But there are also design notes on things like, you know, local storage, operator nuances and various aspects of that.

There's also a museum folder, which, you know, contains lots of projects or samples which are kind of for reference material only, if you wanted to design something like that, but it's more of a historical museum artifact. And one of the things that we were very keen to do as part of this project was to open source all of the history of Reaqtor as well, because so much time and effort and computer science went into producing it. And so as this had to go through the open sourcing process and the patent assignment, the legal review, we kind of decided to bundle everything together in that process.

So we had, you know, the application itself, the samples, the museum, the design notes, just so that it was there for posterity, and if anyone wanted to dig into it and look at the research and some of the fundamentals, they would have access to all of that knowledge. And that's kind of why it's under the Foundation as well, because this is, you know, fundamentally a very useful part of the .NET ecosystem, and hopefully it'll have a long life ahead of it.

Support from the .NET Foundation

Audience member: Sorry, have you found that they gave you a lot of support, like legal-wise and all this kind of thing, by being in the .NET Foundation?

Panellist: There was a long legal process to go through to get the code donated to the Foundation. Claire Novotny and the team were brilliant in helping us get set up with all the systems, and have been very supportive in trying to, you know, do marketing and things like that. Yeah, it's just been brilliant. You know, as a company, we kind of became a corporate sponsor a couple of years ago, because we were working on this, and we wanted to not only, you know, get Reaqtor birthed into the open source world, but we wanted it to live beyond that process.

And we also want to steer, you know, some of the design decisions going forward in .NET to support the evolution of Reaqtor. So, you know, the expression tree subsystem in .NET hasn't really been modernized for a good ten years. And so, you know, many of the operators in Reaqtor could do with, you know, support for async, or new tuples, or record types, or many of the other operators that now exist in .NET but that don't exist inside the expression tree system. And so we're very keen for that to be modernized, so that we can modernize Reaqtor and put in all these new constructs to make it even more powerful, and even more scalable and robust than it currently is.

About the presenters

Carmel Eve

Software Engineer II

Carmel Eve

Carmel is a software engineer and LinkedIn Learning instructor. She worked at endjin from 2016 to 2021, focused on delivering cloud-first solutions to a variety of problems. These included highly performant serverless architectures, web applications, reporting and insight pipelines, and data analytics engines. After a three-year career break spent travelling around the world, she rejoined endjin in 2024.

Carmel has written many blog posts covering a huge range of topics, including deconstructing Rx operators, agile estimation and planning and mental well-being and managing remote working.

Carmel has released two courses on LinkedIn Learning - one on the Az-204 exam (developing solutions for Microsoft Azure) and one on Azure Data Lake. She has also spoken at NDC, APISpecs, and SQLBits, covering a range of topics from reactive big-data processing to secure Azure architectures.

She is passionate about diversity and inclusivity in tech. She spent two years as a STEM ambassador in her local community and taking part in a local mentorship scheme. Through this work she hopes to be a part of positive change in the industry.

Carmel won "Apprentice Engineer of the Year" at the Computing Rising Star Awards 2019.

Ian Griffiths

Technical Fellow I

Ian Griffiths

Ian has worked across an extraordinary breadth of computing - from embedded real-time systems and broadcast television to medical imaging and cloud-scale architectures. As Technical Fellow at endjin, he brings this deep cross-domain experience to bear on the hardest technical problems.

A 17-time Microsoft MVP in Developer Technologies, Ian is the author of O'Reilly's Programming C# 12.0 and one of the foremost authorities on the C# language and high-performance .NET development. He's a maintainer of Reactive Extensions for .NET, Reaqtor, and endjin's 50+ open source projects.

Ian has created Pluralsight courses on WPF fundamentals, WPF advanced topics, WPF v4, and the TPL, and has given over 20 talks at conferences worldwide. Technology brings him joy.