Cats-Actors
Cats-Actors 🐱
is a functional programming-based actor system derived from
Akka v2.6.21.
It is available under the Apache 2.0 License on GitHub: https://github.com/suprnation/cats-actors
Description
The following text taken from the project README (original author: Mark Galea) introduces Cats-Actors, its main goal and benefits.
Introduction
Actors are the fundamental units of computation in the Actor Model, encapsulating state and behavior. They interact exclusively through asynchronous message passing, ensuring their state is accessed sequentially.
How Actors Communicate
- Message Passing: Actors communicate by sending messages to each other, which are queued in their mailboxes and processed one at a time.
- Actor References: Actors use unique references (
ActorRef
) to send messages.
Actor Lifecycle
- Creation: Actors are created by other actors, forming a hierarchy. Root actors are created by the actor system.
- Running: In the
RUNNING
state, actors process messages defined by a receive method. - Stopping: Actors can be stopped, entering the
SHUTDOWN
state, and can perform cleanup tasks. - Restarting: Actors can be restarted by their parent, with
preRestart
andpostRestart
methods for cleanup and reinitialization.
Supervision and Fault Tolerance
- Supervision Strategies: Define how to handle actor failures, ensuring system robustness.
- Fault Tolerance: Isolating state within actors and handling failures through supervision provides a robust framework for building fault-tolerant systems.
For more details, refer to the Wikipedia page on the Actor Model.
Cats-Actors is a library designed to help developers build highly concurrent applications using functional programming principles. It is a fork of Akka 2.6.x, created before the Akka project adopted the Business Source License. The library has been modified to use modern functional programming tools like Cats and Cats-Effect, making it easier to write safe, efficient, and scalable code. Cats-Actors allows you to manage multiple tasks simultaneously without the complexity of traditional threading, making it ideal for applications that need to handle a lot of operations at once.
Why Should I Use Cats-Actors?
- Functional Programming Principles
- Cats and Cats-Effect Integration: Supports immutability, pure functions, and referential transparency.
- Fibers: Offers lightweight concurrency for efficient, scalable applications.
- Simplified Concurrency Model
- High Concurrency: Achieves high concurrency with minimal overhead and complexity.
- Fault Tolerance and Supervision
- Supervision Strategies: Robust, functional programming-based supervision strategies.
- Functional Error Handling: Makes error handling expressive and easier to reason about.
- Modularity and Composability
- Composable Effects: Enables modular and reusable complex workflows.
- Type Safety and Expressiveness
- Type Classes and Higher-Kinded Types: Provides expressive and type-safe code, reducing runtime errors.
- Fully Typed Actors: Ensures that actors are fully typed, specifying the types of messages they can receive and reply with, enhancing type safety and reducing runtime errors.
- Unique Features
- Most Comprehensive Actor Implementation in the Functional Space: Cats-Actors implements
become
/unbecome
,supervision
, andwatch
in a functional way, making it the most comprehensive actor implementation in the functional programming ecosystem.
- Most Comprehensive Actor Implementation in the Functional Space: Cats-Actors implements
Cats-Actors leverages functional programming and the Cats and Cats-Effect libraries for a more efficient, maintainable, and expressive framework for building concurrent applications.
Contribution
Since Akka’s license change, I have been eager to contribute to an actor library that takes advantage of the elegance and robustness of functional programming. I am a top contributor to Cats-Actors, which is actively used to power backend components in production at SuprNation.
So far my contributions have been focused on specific core features, such as the ask pattern, the Finite State Machines (FSMs) and the test kit.
What sets Cats-Actors apart from the traditional Akka approach is its commitment to a purely functional paradigm. This provides not only a safer and more predictable architecture, but also stronger guarantees around immutability and referential transparency, leading to fewer bugs and easier reasoning about code. The result? Greater concurrency and fault tolerance, which we leverage to drive real value in production.
Being part of the Scala ecosystem and contributing to projects that advance the use of FP in real-world applications is something I am truly passionate about.