At the NATS June Meetup in Boulder, CO, Steven Osborne and Charlie Strawn of Workiva present the Actor Model concept their team are using, and some of the work they are doing to connect NATS and Akka.
You can learn more about NATS at http://www.nats.io
4. Actor Model
The actor model is comprised of a system of actors. An actor is a primitive that
embodies
1. Processing
2. Storage
3. Communication
In an actor system everything is an actor. Actor people love the “one ant is no ant”
analogy: One actor is no actor - they come in systems.
5. Actor Model
When an actor receives a message it can
1. Send messages to other actors
2. Create new actors
3. Designate the behavior to be used for the next message it receives
This is the real key. The actor is always doing work reacting to some message.
6. Actor Model - Key points
● Actors can live anywhere.
● There is no shared state among actors. Let it crash.
● Each actor has an address at which it receives messages.
● There is a many-to-many relationship between actors and addresses.
● Messages are delivered at most once.
● Actors process messages serially.
7. Actor Model - Key points
● The model is inherently concurrent (yey!) so keep computation lightweight
and consistent
● Throughput is king
● Each actor processes messages serially - so avoid blocking (except for
unavoidable ops like I/O)
● The unit of concurrency is actor - so all computation within the actor is serial.
If the actor has too much work and needs more processing power it creates
and messages other actors.
8. Good synopsis...
If we’ve piqued your interest in actors but find our summary lacking content -
check out this video from Carl Hewitt - the original designer of the Actor Model.
https://www.youtube.com/watch?v=7erJ1DV_Tlo
Or just do the sane thing and search youtube for “the actor model”. It’s the first
one.
9. Akka
● Akka is Java/Scala library that implements the actor model. Akka is
especially well suited to an EventBus style implementation of pub sub. http:
//doc.akka.io/docs/akka/current/scala/event-bus.html
● 1-to-1 Message to Event
● Effective Akka
10. Ok, great, isn’t this a NATS talk?
NATS is clearly not an actor model - it’s a communication protocol. That being
said, it upholds many of the basic tenants embraced by the actor model.
● Decoupled sender/receiver (i.e. publisher-subscriber)
● Publishers and subscribers can live anywhere
● Messages are delivered at most once
● Lightweight and high throughput
11. NATS-Akka
Let’s take the low hanging fruit here - we should be able to connect NATS to an
existing actor model implementation. Better yet, let’s take the lowest of the fruit -
NATS connector framework (in Java) to Akka (also Java).
Lets combine the speed and simplicity of NATS with the speed and simplicity of
Akka.
13. Akka Clustering
● Akka has a built-in clustering module - but it’s based on complicated on
somewhat complicated tcp routing configuration.
● With NATS as the communication point between nodes - clustering akka is
simple.
14. Connecting to an actor system is cool, but...
What if the actor system was built on top of NATS?
Then multi-node would be a cinch. Setup would be quick. Message latency would
be low. Actor Systems could span languages (i.e. have java actors that interacts
with legacy apis, go actors to do some heavy lifting, and some rust actors to just
be awesome).
15. Let’s try it out
Demo!
https://github.com/sosborne/nats-actor/tree/actor
16. More work
● Actually implement akka clustering using NATS as the message transport
across cluster nodes
● Multi-node go nats-actor implementation
● More languages for nats-actor (maybe rust? Shameless plug…)