How to Architect Reactive Apps & Services

Previously, I wrote about how the Web is a ghost town, and that we need more reactive software. Apps & services which are:

  • Highly Interactive
  • Always Current
  • Enable the Continuous Client

These all involve a resource (eg: a Web page) which is updated continuously in response to events. If we structure services correctly, we can get all three at once. As a bonus, phones can act as remote controls for our PC/Tablet/Fridge.

Each device pipes events to the user's representation in the cloud.

Each device pipes events to the user’s representation in the cloud.

To structure an app/service like this – in a hand-wavy way – build it around streams instead of request/response. The API consumes and returns streams instead of one-shot parameters and single responses.

The next step is to give users their own agent in the service which acts on their behalf, brokering all communication between the user’s devices and other entities.

Finally, clients must be written around the idea that standing queries (“news headlines containing ‘beet'”) return continuous results. Most values in the app can change over time. This is much easier since the rise of MV* frameworks. There’s a lot to gain by pairing RxJS with either of those two frameworks – as redundant as it may seem at first. Rx gives us the ability to easily perform queries on these streams, eg: getNewsHeadlines().filter(headline => headline.contains(‘beet’)). These queries transform the stream into new streams.

The proposal is to leverage the Actor model (or a variant, such as Virtual Actors), with reactive streams of communication between actors & clients. It is also worth looking at Event Sourcing, the fancy consultant’s name for what is effectively journaling events (why not call it Event Journaling, people?). Event Sourcing is nice for achieving high-throughput and horizontal scale when writing services with a high write throughput. It also gives you auditing and debug logs as well as some nice testability for very cheap. That’s for another day.

I’m very excited about implementing some services which use this architecture (Actors + Rx). We have a few ideas which we would love to make a reality. Currently the best technologies to use (that I know of & would consider) in implementing this dream on the service side are:

And on the client side:

If only we could afford Xamarin… $2k per platform per developer. Microsoft, if you can hear me, please buy Xamarin and make it free.

Next time, I will write about our implementation of observable “Web streams” with an example app.