Snapshots
A stock ledger of 100,000 events loaded from a snapshot plus the events after it, written in the command's transaction, and the same snapshots taken by a Camel route on a timer.
examples/15-snapshots/ keeps the stock of three SKUs as streams of StockReceived and StockReserved events in PostgreSQL, loads an InventoryItemAggregate from its latest snapshot plus the later events, and writes a snapshot every N events. It accompanies Snapshots.
It uses Quarkus, Hibernate ORM with Panache, Flyway, Quarkus REST, SmallRye Fault Tolerance, Camel Scheduler and SQL for the comparison route, PostgreSQL and OpenTelemetry to the LGTM stack. There is no Kafka.
cd examples/15-snapshots
mvn -B verify
./verify.sh
What to observe
- A bulk-loaded stream is read in full.
SKU-1503has 100,000 events and no snapshot, and the first load replays all of them. - A command writes the snapshot. After a reservation the load replays 0 events, and it replays at most N-1 until the next snapshot.
- The snapshot is a cache. Deleting it, or changing its schema version, changes the cost of a load and never the state.
- A late snapshot is refused. The upsert will not replace a snapshot with an older one.
- The Camel route lags a burst. With the
camel-snapshotterprofile the tail passes N during a burst and is brought back by the next tick.
Infrastructure
PostgreSQL and the LGTM stack from examples/_infra, and inventory-service. There is no Kafka. The compose project is edp-15.