Crate eventually

Source
Expand description

A library providing components to build event-sourced applications.

The eventually crate provides base abstractions to design your application domain using Domain-driven Design, using the Aggregate trait, and provides a set of nice utilities around those core abstractions: EventStore, Repository, Subscription and Projection.

§Event Sourcing Primer

Event Sourcing is an architectural pattern which requires domain entities’ (in ES lingo, Aggregates) internal state to be mutated and persisted as a list of Domain Events, rather than serializing the whole state to the database (as you would do with a typical CRUD architecture).

Events are persisted in an Event Store: an ordered, append-only log of all the events produced in your domain.

Events can be retrieved from an Event Store through Event Streams, stream of chronologically-ordered events.

The state of your Aggregates can thus be rebuilt by streaming all the Events back in the application, as they happened in time, to build the latest version of the state.

This architectural pattern brings in a lot of interesting goodies:

  • Auditing: never need to guess what happened in your system, thanks to the Event Store, you have a list of all the Events that have been committed during time.
  • Time-machine: travel back in time, by setting the state of your service to a specific point in time, thanks to the Event Store; useful for debugging purposes.
  • Projections: create read-optimized models of your Aggregates as needed for you business operations, continuously, every time new Events are committed to the Event Store.
  • Concurrency Handling: Event-sourced application make extensive use of Optimistic Concurrency to handle concurrent-writes scenarios – concurrency conflicts and state reconciliation can become part of your Domain!
  • High Performance, High Availability: thanks to the append-only Event Store and the use of Projections, you can write highly performant and highly available services that handle an intense amount of traffic.

More information about this pattern can be found here.

Modules§

aggregate
Module containing support for the Aggergate pattern.
inmemory
Module containing utilities using in-memory backend strategy.
optional
Module for the Aggregate extension trait using an Option state.
repository
Module containing Repository implementation to retrieve, save and delete Aggregates.
store
Module containing support for the Event Store.
subscription
Module containing support for Subscriptions to Events coming from the Event Store.
sync
Module containing the synchronization primitives used by the library.
versioning
Module containing support for Optimistic Concurrency using Versioning.

Structs§

AggregateRoot
An AggregateRoot represents an handler to the Aggregate it’s managing, such as:
AggregateRootBuilder
Builder type for new AggregateRoot instances.
Projector
A Projector manages the state of a single Projection by opening a long-running stream of all events coming from the EventStore.
Repository
Implementation of the Repository pattern for storing, retrieving and deleting Aggregates.

Traits§

Aggregate
An Aggregate manages a domain entity State, acting as a transaction boundary.
AggregateExt
Extension trait with some handy methods to use with Aggregates.
EventStore
An Event Store is an append-only, ordered list of Events for a certain “source” – e.g. an Aggregate.
EventSubscriber
Component to let users subscribe to newly-inserted events into the EventStore.
Projection
A Projection is an optimized read model (or materialized view) of an Aggregate model(s), that can be assembled by left-folding its previous state and a number of ordered, consecutive events.
Subscription
A Subscription to an EventStream which can be “checkpointed”: keeps a record of the latest message processed by itself using checkpoint, and can resume working from such message by using the resume.
Versioned
Data type that carries a version for Optimistic Concurrency Control.

Functions§

spawn
Spawns a new asynchronous task, returning a JoinHandle for it.

Type Aliases§

AggregateId
A short extractor type for the Aggregate Id.