Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An Event Sourcing runtime with WebAssembly & embedded event store

License

NotificationsYou must be signed in to change notification settings

thalo-rs/thalo

Repository files navigation

Thalo — Event sourcing runtime for wasm

Crates.ioDocumentationMIT OR Apache-2.0StargazersLast commitDiscord

Important

Thalo is currently unmaintained.
New projects are advised to useSierraDB andkameo_es, which together are the successor to Thalo.

Thalo is an event sourcing runtime that leverages the power of WebAssembly (wasm) throughwasmtime, combined withsled as an embedded event store.It is designed to handle commands using compiled aggregate wasm components and to persist the resulting events, efficiently managing the rebuilding of aggregate states from previous events.

Key Features

  • Wasmtime Integration: High-performance, isolated aggregate computation using WebAssembly.
  • Sled Event Store: Fast, reliable embedded database for event storage.
  • Actor-Based Aggregates: Efficient, lock-free management supporting over 10,000 commands/sec.
  • Projections: Projections to handle interested events with an at-least-once gaurantee.
  • LRU Caching: Fast aggregate rebuilding with optimized memory usage.
  • Streamlined State Management: Automated reconstruction of aggregate states from events.
  • Multi-Language Support: Compile aggregates to wasm, enabling diverse language use (currently Rust supported).
  • Event Relaying: Events can be relayed to external services (redis streams, etc) with an at-least-once guarantee.

Prerequisites

  1. Rust: Latest stable version of the Rust programming language.
  2. Thalo: Required for building aggregates to wasm.
    • Install with:cargo install thalo_cli
  3. Thalo Runtime: Required for running the Thalo event sourcing environment.
    • Install with:cargo install thalo_runtime

Thalo can be started by runningthalo-runtime.

For a list of supported arguments, usethalo_runtime --help.

Writing an Aggregate

An aggregate is a regular rust crates which exposes the type implementingthalo::Aggregate with thethalo::export_aggregate! macro.

thalo::export_aggregate!(Counter);structCounter{ ...}impl thalo::AggregateforCounter{ ...}

It can then be compiled with the thalo cli.

$ thalo build counter -o ./modules

Thethalo build command is essentially a wrapper aroundcargo build,handling wasm specifics including converting the resulting binary to a wasm component.

Thalo will automatically load all modules within this the./modules directory, and use them to handle commands.

You can restart the thalo runtime and you should see a message saying our counter was loaded from themodules/counter.wasm file.

$ ./target/debug/thalo-runtimeINFO: loaded module from file file="modules/counter.wasm"

We can now send commands to this module with thethalo execute command for testing.

$ thalo execute counter abc123 Increment'{"amount":10}'Executed with 1 events:    Incremented  {"amount":10}
Counter Example
use serde::{Deserialize,Serialize};use thalo::{events, export_aggregate,Aggregate,Apply,Command,Event,Handle};export_aggregate!(Counter);pubstructCounter{count:u64,}implAggregateforCounter{typeCommand =CounterCommand;typeEvent =CounterEvent;fninit(_id:String) ->Self{Counter{count:0}}}#[derive(Command,Deserialize)]pubenumCounterCommand{Increment{amount:u64},}implHandle<CounterCommand>forCounter{typeError =Infallible;fnhandle(&self,cmd:CounterCommand) ->Result<Vec<CounterEvent>,Self::Error>{match cmd{CounterCommand::Increment{ amount} =>events![Incremented{ amount}],}}}#[derive(Event,Serialize,Deserialize)]pubenumCounterEvent{Incremented(Incremented),}#[derive(Serialize,Deserialize)]pubstructIncremented{pubamount:u64,}implApply<Incremented>forCounter{fnapply(&mutself,event:Incremented){self.count += event.amount;}}

Understanding Event Sourcing

Event sourcing is a design pattern in which changes to the application state are stored as a sequence of events. Instead of storing just the current state, event sourcing involves persisting the full series of actions taken on the data. This allows for:

  • Complete State History: Every change is recorded, enabling full traceability and audit trails.
  • Easy Reversion: The ability to revert to any previous state by replaying events.
  • Complex Event Reconstruction: States can be rebuilt or projections created by processing the event log.
  • Improved Scalability and Performance: Decouples data commands from updates, often leading to better system performance.

Event sourcing is particularly useful in systems where understanding the history of operations is crucial, such as financial systems, order management systems, and other domains where auditability and traceability are important.

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 theexamples directory, or chat on theDiscord server.

Examples

Examples can found in theexamples directory.

Contributing

🎈 Thanks for your help improving the project! As we don't currently have a contributing guide, you can ping us on theDiscord server or open an issue.

License

This project is licensed under theMIT ORApache-2.0 license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submittedfor inclusion in Thalo by you, shall be licensed as MIT, without any additionalterms or conditions.

About

An Event Sourcing runtime with WebAssembly & embedded event store

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp