Breaking Boundaries: Actor Models in Edge Software Accelerate Innovation

Philip Hooker
thin-edge.io
Published in
4 min readJul 24, 2023

The actor model in release 0.11 of the open-source thin-edge.io project enables pre-built components to be easily configured, extended and combined into IoT specific agents, simplifying edge software development and maintenance.

When creating edge software, developers often face challenges in building systems which can handle simultaneous operations. These complexities include managing concurrency, ensuring scalability, handling communication and synchronisation between components, addressing fault tolerance, and maintaining modular and re-usable code.

Object orientated programming (OOP) solves a range a challenges in software development, but does not inherently solve the challenges around concurrent operation. Shared mutable state is common, which can lead to data races and inconsistent behaviour when accessed concurrently by multiple threads or processes. OOP’s reliance on shared state and direct object references can introduce complexities in managing synchronization and ensuring thread safety.

thin-edge.io is built using Rust, a programming language that focuses on tackling memory and concurrency challenges. Unlike OOP languages, Rust enforces strict rules and performs compile-time checks to handle shared mutable states, ensuring both memory and thread safety. However, coordinating distributed software components in the cloud and edge environments adds complexity to synchronization.

The actor model, implemented in release 0.11 of thin-edge.io, solves the challenges associated with concurrency by adopting an approach that simplifies programming, provides clear communication and isolation mechanisms, supports scalability and fault tolerance, and promotes modular design.

The actor model adopts the philosophy that everything is an actor, which is similar to the OOP philosophy that everything is an object. An actor is a computational entity that can perform certain actions concurrently when it receives a message. These actions include sending messages to other actors, creating new actors, and determining its behaviour for the next message. The actor model allows for the parallel execution of these actions without a fixed sequence.

Actor model design outline

In the context of thin-edge.io the actor model provides several benefits:

Firstly, it offers modularity, allowing actors to be understood and implemented independently. Each actor’s behaviour is determined by how it reacts to messages in different states. This modularity enables easy implementation, testing, and packaging of actors.

Secondly, the model provides flexibility in connecting actors, as long as they can interpret each other’s messages. Actors can be substituted by others that offer the same services, maintaining message compatibility.

Thirdly, observability is enhanced in the actor model. The behaviour of actors can be fully observed by tracking the stream of messages they receive and send. Any state change can be traced back to a message, facilitating logging, persistence, auditing, and cloud forwarding.

Lastly, the actor model promotes testability. Actors can be tested in isolation or in combination with others, exercising them with different input messages while verifying their output. Peers can be simulated to create various scenarios, enabling comprehensive testing of the system, including interactions with the clock and file system.

Furthermore, as thin-edge.io leverages Rust it adds robustness into the actor model. Messages can only be sent if the recipient understands them. I.e. the compatibility between the messages sent and the actor’s ability to process them is checked during the compilation process.

So, when there are already existing frameworks available for Rust, why does thin-edge.io have its own implementation of the actor model?

According to Alice Ryhl’s description, actors can be implemented directly using Tokio, which provides the necessary components such as asynchronous tasks and in-memory channels. The challenge lies not in the implementation of the actor processing loop itself, but rather in how actors are constructed, connected, and spawned.

However, existing Rust actor frameworks like Actix primarily focus on abstracting the actor life cycle and providing methods to handle different message types at each stage. While this may seem helpful, it introduces constraints on the interleaving of message reception and emission, as the framework tightly controls the life cycle. The Handler trait in Actix allows defining reactions to specific inputs, but it lacks flexibility in sending spontaneous messages or deferring reactions arbitrarily.

Additionally, Actix distinguishes between the Actor and its Context, but tightly couples them together. An Actix actor cannot be used without an Actix context and runtime. Even with these dependencies, creating actor contexts, instances, and establishing their connections requires an additional layer built on top of Actix.

Therefore, thin-edge.io has its own implementation to address these issues and provide a more flexible and interconnected mesh of actors, tailored to its specific requirements.

We chose to design thin-edge.io actors using Tokio instead of Actix. Tokio offers essential components like asynchronous tasks and in-memory channels. We prefer the simplicity and flexibility of actors defined with asynchronous methods, rather than being constrained by a framework’s predefined life cycles. Our goal is to provide a systematic and flexible approach to instantiate and connect actors, allowing various communication patterns without restrictions on message types, quantities, targets, or response times.

As IoT software developers, we understand the necessity of pushing the boundaries and discovering new horizons. Through incorporating the actor model, thin-edge.io has assimilated its core benefits of modularity, flexibility, observability and testability. When combined with Rust’s robustness, it can revolutionize your development practices and empower you to achieve unprecedented success in the fast-paced realm of edge computing!

Read more at https://github.com/thin-edge/thin-edge.io/blob/main/design/thin-edge-actors-design.md

--

--