Propose Event Sourcing for Billing
This is ADR 21, proposing that billing move to event sourcing so every invoice has a complete history. Disputes currently take support hours of digging through logs. I'd like comments here before we take it to the architecture review on the 20th.
Adocs/adr/0021-event-sourcing-for-billing.md1 of 2
Files Changed
docs/adr/
docs/adr/0021-event-sourcing-for-billing.md
Markdown · Click a line number to comment · Tap a line to comment@@ -0,0 +1,27 @@
Added: # 21. Event Sourcing for Billing
Added:
Added: Status: Proposed
Added: Deciders: Billing, Platform
Added:
Added: ## Context
Added:
Added: Billing state lives in mutable rows across invoices, payments, and adjustments. When a customer disputes a charge, support can't tell how an invoice reached its current state, and finance rebuilds the history by hand from application logs. Last quarter that took about 140 support hours.
Added:
Added: ## Decision
Added:
Added: We will move billing to event sourcing. Every change becomes an immutable event in a billing_events table, and the current state of each invoice is a projection built from its events. The existing invoices, payments, and adjustments tables become read-only projections.
Added:
Added: Events are stored as JSON with a type field.
Added: Projections are rebuilt from the start of the log on every deploy, so a fix to projection code applies to all history.
Added:
Added: Customer name, email, and billing address are copied into each event, so a projection never needs to call another service.
Added:
Added: ## Consequences
Added:
Added: - Every invoice has a full history, which answers disputes directly.
Added: - Auditing is simpler, since events are never changed or deleted.
Added: - The team will need to learn event sourcing. We will run a training session in January.
Added:
Added: ## Rollout
Added:
Added: All billing writes move to the event store in one release, behind the billing-v2 flag.
docs/adr/README.md
Markdown · Click a line number to comment · Tap a line to comment@@ -2,5 +2,6 @@
| ADR | Title | Status |
| --- | --- | --- |
| 0019 | Postgres for the Search Index | Accepted |
| 0020 | One Repository per Team | Superseded |
Added: | 0021 | Event Sourcing for Billing | Proposed |