Appendix G: Write-forward cache
An order and its full-state event in one transaction, carried to Kafka by Debezium and applied to Redis by a Camel route behind a version guard, with the dual write and a guardless replay as comparisons.
examples/ag-write-forward-cache/ stores each order and its event in one PostgreSQL transaction, publishes the event through Debezium Connect, and applies it to Redis. GET /orders/{id} reads Redis only. It accompanies Appendix G.
It uses Quarkus, Hibernate ORM with Panache, Flyway, the Debezium Outbox extension, the Quarkus Redis client, Camel Kafka, PostgreSQL, Debezium Connect, Redis and OpenTelemetry to the LGTM stack.
(cd examples/domain-model && mvn -B -q install)
cd examples/ag-write-forward-cache
mvn -B verify
./verify.sh
What to observe
- Lag, not disagreement. The cache trails each commit by a few hundred milliseconds and never holds an order PostgreSQL does not.
- No database fallback. With Connect stopped, a committed order is a 404 from the cache.
- A cache loss is repaired by replay. A restarted Redis is refilled by a new consumer group reading both topics.
- The guard matters. A replay of older events after newer ones leaves cancelled orders cancelled.
Infrastructure
Kafka, PostgreSQL, Connect, the LGTM stack and Redis from examples/_infra, a one-shot container that creates the two order topics with one partition, and order-service on port 8080. The compose project is edp-ag.