Akka - why is it that messages are not guaranteed to arrive (after being send)? What is the failure rate for messages?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Akka is a toolkit and runtime for building highly concurrent, distributed, and fault-tolerant event-driven applications on the JVM. Akka uses the Actor Model to abstract away the complexity involved in writing such applications. Despite its robust design, Akka does not guarantee that messages sent between actors will always arrive. Understanding why this is the case, and estimating the failure rate of message delivery, requires a deeper look into Akka's architecture and the principles underpinning distributed systems.
Why Messages May Not Arrive
- At-most-once Delivery Default: Akka's default delivery guarantee is "at-most-once," which means that messages won't be delivered more than once, but might not be delivered at all. This model is primarily chosen for performance reasons, as guaranteeing delivery would often require additional overhead - both in terms of time (latency) and resources (bandwidth, memory).
- Network Issues: In distributed systems, messages are sent over networks that can be unreliable. Network failures, such as broken connections or lost packets, can lead to undelivered messages.
- Actor Failures: Actors in Akka can fail due to reasons like exceptions thrown during message processing. If an actor dies after receiving a message but before successfully processing it, the message might be lost if it's not persisted or handled correctly by a supervisor.
- No Buffering by Default: Akka does not buffer messages by default. If an actor gets overloaded and can't process messages quickly enough, sent messages might get dropped, especially during high-load scenarios.
- System Crashes: In cases where the entire system (or part of it) crashes, in-flight messages can be lost if they are not persisted. This scenario can be mitigated by distributed data and persistent actors, though it adds to system complexity.
Failure Rate for Messages
The failure rate for messages in Akka inherently depends on various factors including network reliability, system load, the robustness of the hardware, and the design of the application. There's no fixed failure rate that can be universally applied; instead, the failure rate can be minimized through design choices like:
- Using additional modules such as Akka Persistence, which helps in dealing with actor state recovery and therefore indirectly stabilizes message delivery by persisting actor state.
- Implementing robust error handling and supervision strategies for actors.
- Employing strategies such as "at-least-once delivery" by using tools like Akka Persistence or custom solutions to store and retry message delivery until it is confirmed.
Technical Example
Suppose we have two actors, Sender and Receiver, residing in different parts of a distributed system. The sender is sending messages to the receiver over a network that occasionally drops packets.
In this example, the Sender actor sends a "Hello, Receiver!" message to the Receiver. This simplistic scenario doesn't take into account message loss due to network issues or system failures.
Enhancing Reliability
For enhancing message delivery reliability in Akka:
- Akka Persistence: Can ensure that messages are persisted and can be resent in case of actor failures.
- Acknowledge Pattern: Receiver can send back an acknowledgment to the sender upon receiving a message. The sender retries sending the message until it receives an acknowledgment.
Summary Table
| Feature | Description | Impact on Message Delivery |
| At-most-once delivery | Default delivery guarantee where messages are not redelivered on failure. | Increases potential for message loss. |
| Network Reliability | Depends on the underlying hardware and network infrastructure. | Critical factor in delivery success. |
| Actor Supervision | Strategies to manage and recover from failures. | Minimizes message loss due to actor failures. |
| Message Persistence | Ensuring messages are stored until they are confirmed received. | Reduces message loss during failures. |
In conclusion, while Akka provides powerful abstractions and models for building distributed systems, it operates under the constraints inherent to distributed communication and computing. Understanding these limitations is crucial for effectively designing and deploying resilient Akka applications.

