No commit activity in last 3 years
No release in over 3 years
Event sourced aggregate root implementation with concurrent writer and snapshot support
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.9
>= 0
~> 4.2.1
~> 10.0
>= 0

Runtime

 Project Readme

SnapshotAggregateRoot

An extension of https://github.com/arkency/aggregate_root with support for concurrent writers.

Usage

Snapshots

Snapshots are created automatically as required by the #store method. Implementations of this class must implement 2 methods.

  • #build_snapshot
  • #apply_snapshot(snapshot)

Optionally Implementations may also override

  • #snapshot_threshold - Override how often snapshots are taken
  • #requires_snapshot?- Provide a custom implementation for when snapshots a required

Concurrent Writers

In order to be safe for current writes snapshot aggregate root exposes a #with_write_context(stream_name, event_store:) method. This method loads the aggregate, applies the block, then stores the events within a mutex so that only one concurrent writer can execute the block. Event handlers are triggered after the command is complete

The entire command handler for a snapshot aggregate root should be executed within this block eg.

  def apply_command(command)
    SomeAggregate.new.with_write_context(command.aggregate_id) do |aggregate|
      aggregate.do_command(command)
    end
  end