---
id: ADR-ACC-BKS-008
title: Atomic configuration writes with provider calls before persistence
product_area: accounting
module: books
revision: 1
status: proposed
design_intent: proposed
source_sha:
  services-accounting: f47cb263875bbc0c5640fba7dae6785ec32695f8
  react-console: baf6dae382d6f41dce976c7f848667ccc37e076f
decision: >-
  Books commits or rolls back each configuration write as a database
  transaction. Rate filling calls the provider before persistence and outside
  that transaction; a provider quote is corrected by deleting it and filling
  again.
constrains:
  - SVC-ACC-BKS-books
  - WF-ACC-BKS-001
  - WF-ACC-BKS-002
  - WF-ACC-BKS-003
  - WF-ACC-BKS-004
  - WF-ACC-BKS-005
  - WF-ACC-BKS-006
origin: >-
  services-accounting docs/architecture/accounting-2.0/02-decisions.md#P-4
  (delete-and-fill, a reversible build decision)
alternatives:
  - option: Call the provider while holding the transaction.
    why_not: A slow or failed external request would prolong database locks.
  - option: Edit provider quotes directly.
    why_not: Editing would obscure which value actually came from the provider.
  - option: Persist before the provider read and compensate.
    why_not: >-
      The implemented provider operation is a read; delaying persistence avoids
      a separate undo flow.
consequences:
  - >-
    Rollback restores only the writes in the failed transaction, not previously
    committed work or consumer effects.
  - >-
    If persistence fails after a provider response, staff can request another
    fill.
  - Posting and other downstream effects have their own consistency boundaries.
supersedes: []
evidence:
  - >-
    services-accounting at f47cb263:
    modules/books/services/exchange-rates/fill-exchange-rates.ts (header)
  - >-
    services-accounting at f47cb263:
    modules/books/services/persistence/exchange-rates.ts:updateExchangeRate
---

# Atomic configuration writes with provider calls before persistence

## Context

Owned configuration collections must change together. Exchange-rate filling also needs an external read, whose latency should not hold configuration locks.

## Decision

Books commits or rolls back each configuration write as a database transaction. Rate filling calls the provider before persistence and outside that transaction; a provider quote is corrected by deleting it and filling again.

## Alternatives Considered

Call the provider while holding the transaction. A slow or failed external request would prolong database locks.

Edit provider quotes directly. Editing would obscure which value actually came from the provider.

Persist before the provider read and compensate. The implemented provider operation is a read; delaying persistence avoids a separate undo flow.

## Consequences

Rollback restores only the writes in the failed transaction, not previously committed work or consumer effects.

If persistence fails after a provider response, staff can request another fill.

Posting and other downstream effects have their own consistency boundaries.
