cluster-event-sourcing

main

akbashev/cluster-event-sourcing

Cluster System Event Sourcing

An event sourcing framework implementation for Swift distributed Cluster System.

Usage

Documentation: TODO

  1. Currently there is no default store providers, so you need to create one and conform to EventStore protocol. This could be any class, actor and etc.
  2. Install plugins. ClusterJournalPlugin wraps store into singleton, so singleton plugin also should be added (and order is important!).
let node = await ClusterSystem("simple-node") {
    $0.plugins.install(plugin: ClusterSingletonPlugin())
    $0.plugins.install(
        plugin: ClusterJournalPlugin { _ in
            SomeStore()
        }
    )
}
  1. Make distributed actor EventSourced and define the handleEvent(_:) function. Register the actor with the journal in init:
distributed actor SomeActor: EventSourced {

    // Some custom events for actor
    enum Event {
        case doSomething 
    }
    
    distributed func doSomething() async throws {
        try await self.emit(event: .doSomething)
    }
    
    distributed func handleEvent(_ event: Event) { 
        switch event {
        case .doSomething:
            // update state
        }
    }
    
    init(actorSystem: ClusterSystem, persistenceId: PersistenceID) async throws {
        self.actorSystem = actorSystem
        try await actorSystem.journal.register(actor: self, with: persistenceId)
    }
}

Description

  • Swift Tools 6.2.0
View More Packages from this Author

Dependencies

Last updated: Sun Jan 18 2026 11:16:22 GMT-1000 (Hawaii-Aleutian Standard Time)