Build just this flow: when a policy is sold, an async install gate builds the account/COPE structure and activates the policy; then servicing and FNOL/claims. Advance the maturity stage to add the install gate, then claims media + audit, then carve out claims.
Two mechanisms here: the event bus (async facts — events announcing something that already happened — via the outbox → Pub/Sub/EventBridge → push-subscription, deduped on event_id) AND the install-gate FIFO work queue (ordered commands — instructions to do something, processed in order — Cloud Tasks / SQS FIFO) — they are not the same thing.
MarkedAsSold from the bus (deduped on event_id) and writes an install_job row (status PENDING) to Cloud SQL.policy_id so the case installs exactly once, in order.account_structure built? underwriting clean? broker valid?account_structure + cope_location rows, flips the policy row to ACTIVE, sets install_job=DONE, and writes an outbox row → the relay publishes PolicyActivated.ops_task row, puts the state-filed temporary cover in effect (binder coverage), and emits InstallGateFailed; transient errors retry, and a poison message (one that keeps failing on every retry) lands in the dead-letter queue for a human.claim row (status OPEN) linked to the policy; photos/docs upload to object storage, only their storage keys (reference IDs, not the files) in claim_media; an outbox row → FNOLReceived on the bus.claim; the governed, redacted outcome is written to the decision_log/rag_document store (embedded in pgvector) — closing the loop back to underwriting.| Direction | Contract | Who |
|---|---|---|
| Consumes | MarkedAsSold {policy id, premium snapshot} | Pricing |
| Emits | PolicyActivated, InstallGateFailed, FNOLReceived | Servicing, ops queue, RAG |