Idempotency and retries
It's always safe to retry these calls:
| Call | Idempotent on | Replay returns |
|---|---|---|
POST /tax/documents | entityId + sourceSystem + sourceDocumentId + direction | 200 with the same document (Unchanged). New content replaces it until committed. |
POST /tax/documents/{id}/credits | The credit's sourceDocumentId | The same credit |
POST /tax/documents/{id}/commit | Document id | The committed document |
POST /fx/locks | Pair + business date + source | The same lock (200 instead of 201) |
POST /certificate-requests/resale | Entity + vendor + PO + region | The open request |
PUT /entities/{id}/customers/{code} | Entity + code | The party |
| Messages | The same keys as the REST equivalent, plus the inbox's message id | No duplicate effects |
So the rule for callers is: use your own stable ids (invoice id, bill id, credit memo id) as sourceDocumentId,
and retry on network errors, 5xx and 409 concurrent_update.
What counts as "the same content"
A replay is recognised by a content hash of a canonical form of the request (ContentHash in the Application layer):
null members are left out, member order doesn't matter, and amounts compare by value (100.00 equals 100). So:
- Adding an optional member to a contract doesn't turn replays of existing documents into changes, as long as callers that don't know it leave it out.
- Hashes carry a version prefix (
v1:). Rows stored before it still match their replays.
Races
Two different requests that race for the same thing are serialized by the database, not by luck:
| Race | Guard | Loser gets |
|---|---|---|
| Two credits against one invoice | The invoice's row version (each credit bumps credit_version) | 409 concurrent_update; the retry sees the winner's credit and is checked against what remains |
| Two resale requests for one vendor + region + PO | Partial unique index on open requests | The winner's request (200) |
| Two first-time upserts of one customer or vendor | Unique index on entity + type + code | 409 concurrent_update |
| Two locks for one pair and day | Unique index on pair + date + source | The winner's lock (200) |