CRUD versus events
One ChangeOrderStatus command applied as a row update and as an appended event, with replay, history and an append-only guard.
Chapter 1
examples/01-crud-vs-events/ applies one command to an Order two ways. The orders row is overwritten; order_event gains a fact. It accompanies Events, commands and documents.
It uses Quarkus REST, Hibernate ORM with Panache, Flyway, PostgreSQL and OpenTelemetry to the LGTM stack. There is no Camel and no Kafka.
(cd examples/domain-model && mvn -B -q install)
cd examples/01-crud-vs-events
mvn -B verify
./verify.sh
What to observe
- The row keeps only the latest status.
GET /orders/{id}returns the Order with its currentOrderStatus. - The stream keeps every status.
GET /orders/{id}/historylists each status with its version and timestamp. - Replay equals the row.
GET /orders/{id}/replayedreturns the same JSON as the row. - An illegal move is refused. Sending PLACED to a PAID order returns 409 and
order_eventgains no row. So does cancelling a SHIPPED order. - The history is append-only.
UPDATE,DELETEandTRUNCATEonorder_eventfail inpsqlwith an append-only error. - Telemetry arrives. Grafana at
http://localhost:3000shows traces forcrud-vs-events.
Infrastructure
PostgreSQL and the LGTM stack from examples/_infra, plus the application container built from a UBI 10 Containerfile. The compose project is edp-01.