Thalo
Event sourcing framework for building microservices.
Overview
Thalo is an event-sourcing framework for building large scale systems based on the following patterns:
It's designed to be modular with additional crates implementing most functionality.
Official Crates
Core
- thalo - Core framework.
- thalo-testing - Test utils for thalo apps.
- thalo-macros - Macros for implementing traits. This can be enabled in the core crate with the
macros
feature flag.
Event stores
- thalo-postgres - Postgres implementation of
EventStore
. - thalo-inmemory - In-memory implementation of
EventStore
. - thalo-filestore - Filestore implementation of
EventStore
.
Event streams
- thalo-kafka - Kafka implementation of
EventStream
.
What is Event Sourcing & CQRS
Event sourcing is a way of storing data as an immutable sequence of events. Events are facts that occured in your system and cannot be undone.
Put simply, event sourcing is: f(state, event) -> state
Rather than the traditional state-oriented approach, your data consists of small events which occur in your system, and your models can be built by replaying these events one by one to compute read models.
A common example of event sourcing is accounting. Your bank balance is the sum of all your transactions (aka events). Another example you're likely familiar with that uses event sourcing is Git scm.
What are the benefits?
-
Scalability
Event sourced systems can operate in a very loosely coupled parallel style which provides excellent horizontal scalability and resilience to systems failure.
-
Time Travel
By storing immutable events, you have the ability to determine application state at any point in time.
-
100% Accurate Audit Logging
With event sourcing, each state change corresponds to one or more events, providing 100% accurate audit logging.
-
Expressive Models
Events are first class objects in your system and show intent behind data changes. It makes the implicit explicit.
-
Separation of Concerns
Commands and queries in your system are independent of eachother. This allows them to be scaled & developed independently.
What are the down sides?
As with anything in the tech world, everything is about tradeoffs. There are some reasons not to use event sourcing in your system including:
-
Eventual Consistency: With the separation of concerns comes eventual consistency in your system, meaning your data may not be up to date immediately, but eventually will become consistent.
-
High Disk Usage: With all events being stored forever, disk usage will grow overtime. Though there are solutions to this such as snapshotting.
-
Event Granularity: Sometimes it can be difficult to judge an appropriate size for events. Having them too small may not provide enough data, while large events may slow down your system.
Resources
Here are some useful resources on event sourcing & CQRS:
- https://microservices.io/patterns/data/event-sourcing.html
- https://moduscreate.com/blog/cqrs-event-sourcing/
- https://medium.com/@hugo.oliveira.rocha/what-they-dont-tell-you-about-event-sourcing-6afc23c69e9a
Why
With Rust being a younger language than most, the ecosystem is lacking Event Sourcing & CQRS frameworks. Many of which are abandoned, or just not feature rich. Thalo aims to provide a backbone and some core crates to build robust event sourced systems.
ESDL - Event-sourcing Schema Definition Language
Defining aggregates, commands and events are recommended to be done in the ESDL schema language.
This allows for more readable aggregate definitions and provides code generation to generate events, command trait and custom types compatible with Thalo.
An example of an .esdl
can be found in examples/bank-account/bank-account.esdl
.
Examples
Examples include:
- bank-account: a bank account aggregate built with an ESDL schema file.
- protobuf: a gRPC client & server for sending syncronous commands.
All examples can be seen in the examples
directory.
Getting Help
As Thalo is in pre-release, the API is not stable yet. If you'd like to get started using Thalo, you can checkout the examples directory, or chat with us on our Discord server.
Contributing
Release Schedule
Thalo doesn't follow a fixed release schedule, but as the project is in pre-release and active development, you can expect commits on a near daily basis, and version updates evey few days.
License
This project is licensed under the MIT OR Apache-2.0 license.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Thalo by you, shall be licensed as MIT, without any additional terms or conditions.