ADR-002: Persist saga state and messages in Finance PostgreSQL
Finance combines EF Core saga storage with Wolverine PostgreSQL envelope persistence and transaction integration in its own database.
This architecture decision has been marked as superseded.
This ADR is Superseded. Finance orchestration now uses Azure Durable Task Scheduler as documented in ADR-001: Coordinate checkout with a persisted Order sagaDecision Recordv1.0.0ADR-001: Coordinate checkout with a persisted Order sagaFinance uses Azure Durable Task Scheduler (DTS) keyed by Order ID to coordinate asynchronous checkout work without ownin...Ownercommerce-fulfillment-teamOpen docs. It is preserved for historical context only.
1. Context & Problem
When Finance handles a checkout update, it often needs to save workflow progress and schedule follow-up instructions for other capabilities at the same time. If those two saves happened separately, a crash in between could leave workflow state updated without sending the next instruction, or vice versa.
Finance also requires its own isolated storage rather than accessing Ordering or Basket data directly. That storage must support reliable local workflow recovery without being mistaken for a shared domain store or a way to coordinate atomic transactions across external systems.
Note: This retrospective decision record has a superseded status and documents a historical implementation approach rather than a new deployment.
2. Business Value
- Eliminated local failure gaps: Saving workflow progress and outgoing follow-up messages together prevents partial updates during interruptions.
- Strong domain isolation: Keeping Finance data in its own store avoids coupling to Ordering or Basket internals.
- Lower maintenance overhead: Relying on built-in framework transaction and message persistence avoids bespoke, error-prone synchronization code.
3. How It Works
Finance keeps both its active checkout workflow records and its durable queue of incoming and outgoing messages in its own dedicated storage:
- Combined local updates: When a workflow step runs, changes to the workflow record and any resulting follow-up messages are saved together in a single local transaction.
- Conflict detection: Concurrency checks detect when two updates attempt to modify the same workflow record simultaneously, preventing silent overwrites.
- Clear external boundary: While local workflow updates and queued messages stay consistent inside Finance, downstream delivery to message brokers, Basket, Ordering, Notification, or email servers happens asynchronously outside that local boundary.
4. Trade-offs & Lessons Learned
- Local transaction safety vs. distributed guarantees: Combining workflow state and message storage closes internal dual-write failure windows, but cannot guarantee all-or-nothing execution or exactly-once side effects across remote services or email delivery.
- Storage availability & concurrency recovery: Making Finance’s store a runtime dependency means storage outages pause workflow progress, and conflict detections require handlers and operators to handle retries and recovery.
- Schema compatibility & inspection: Deployed code must remain compatible with stored workflow and message structures, and historical persistence scripts should not be assumed to reflect current runtime storage without checking the active model.
- Confidential data handling: Storing recipient details and message payloads requires confidential-data protection, with no specific retention or residency policy implied by the storage choice itself.
- Alternatives rejected:
- Saving workflow state without durable messages: Leaves incoming and outbound message processing exposed to failure windows.
- Custom dual-write logic: Requires complex, bespoke recovery for partial failures.
- Sharing Ordering or Basket storage: Couples Finance to external schemas and blurs data ownership.
- Treating local storage as a distributed transaction boundary: Cannot atomically commit remote messaging, external service side effects, or email delivery.
5. Technical Reference
Retrospective note: This ADR (status: superseded, dated 2026-11-03) records the PostgreSQL/EF Core/Wolverine implementation approach, not a new database deployment or an assertion about historical approval.
- Persistence & transaction configuration:
- Uses the Finance PostgreSQL database (
financedbresource provided by AppHost) for EF Core saga storage and Wolverine durable message envelopes. - When the Finance connection string is available, configures
PersistMessagesWithPostgresqlwith thewolverineschema and enablesUseEntityFrameworkCoreTransactions. - Transaction integration is conditional on the Finance connection string and must remain aligned with the actual EF Core and Wolverine persistence configuration.
- Uses the Finance PostgreSQL database (
- Model mapping & concurrency:
- Maps saga records through
FinanceDbContextandOrderSagaConfiguration. - Uses the PostgreSQL
xminrow-version token for optimistic concurrency andnumeric(18,2)for the saga total.
- Maps saga records through
- Boundaries:
- Covers Finance’s local saga and Wolverine-managed message envelopes only; does not create an atomic transaction with Kafka consumers, Basket, Ordering, Notification, or SMTP, and does not provide exactly-once downstream side effects.
- Historical inbox/outbox migrations are not a substitute for inspecting the current Wolverine-managed storage and EF Core model.