schnittstellen:idempotency
Differences
This shows you the differences between two versions of the page.
| schnittstellen:idempotency [2026/10/14 15:26] – created admin | schnittstellen:idempotency [2026/10/14 15:34] (current) – add Diagrams admin | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| To counteract this, a decently new HTTP header has been developed, called an " | To counteract this, a decently new HTTP header has been developed, called an " | ||
| + | |||
| + | Heres a Diagram to visualize this: | ||
| + | |||
| + | <uml> | ||
| + | @startuml | ||
| + | ' | ||
| + | |||
| + | start | ||
| + | :Request arrives with Idempotency-Key: | ||
| + | |||
| + | if (Check key-xyz | ||
| + | in storage) then (Exists) | ||
| + | :Key found; | ||
| + | if (Key status?) then (completed) | ||
| + | :Status: completed; | ||
| + | if (Request hash | ||
| + | matches the | ||
| + | stored one?) then (Matches) | ||
| + | :Return cached response | ||
| + | (don't reprocess); | ||
| + | end | ||
| + | else (Doesn' | ||
| + | :Return 422 | ||
| + | Different payload | ||
| + | for the same key; | ||
| + | end | ||
| + | endif | ||
| + | else (processing) | ||
| + | :Return 409 Conflict | ||
| + | (still being processed); | ||
| + | end | ||
| + | endif | ||
| + | else (Not found) | ||
| + | :Atomic Insert key | ||
| + | with status `processing` | ||
| + | (UNIQUE constraint); | ||
| + | if (Insert suceeded? | ||
| + | (affected rows = 1)) then (Yes) | ||
| + | :Execute business logic; | ||
| + | :Save response + | ||
| + | update status to | ||
| + | `completed`; | ||
| + | :Return response; | ||
| + | end | ||
| + | else (No (duplicate insert) | ||
| + | :Return 409 | ||
| + | Concurrent duplicate; | ||
| + | end | ||
| + | endif | ||
| + | @enduml | ||
| + | |||
| + | </ | ||
| + | |||
| + | And another Diagram to show how and what could go wrong with ERV BE PartnerAPI as an example: | ||
| + | |||
| + | <uml> | ||
| + | @startuml | ||
| + | ' | ||
| + | |||
| + | title " | ||
| + | |||
| + | note across: Without Idempotency -- Retry = Saved twice | ||
| + | |||
| + | client as " | ||
| + | server -> db as " | ||
| + | note over server: Server crash / Timeout before sending response! | ||
| + | client --> client: Timeout -- no response recieved | ||
| + | client -> server: POST / | ||
| + | server -> db: Persist Policy Data AGAIN | ||
| + | server --> client: 201 CREATED | ||
| + | note across: Two different Policies with identical data were persisted! | ||
| + | note across: With Idempotency -- Retry is Safe | ||
| + | client -> server: POST / | ||
| + | server -> db: Persist Policy Data + save key-abc + response | ||
| + | note over server: Server crash / timeout! | ||
| + | client --> client: Timeout | ||
| + | client -> server: POST / | ||
| + | server -> db: Check key-abc, already exists, get cached response | ||
| + | server --> client: 201 CREATED (returns cached response, without actual change) | ||
| + | note across: Policy data is only saved once while Client still receives success response | ||
| + | |||
| + | @enduml | ||
| + | |||
| + | </ | ||
| But in what situation can a request be sent twice, usually after a request a user won't resend the request. | But in what situation can a request be sent twice, usually after a request a user won't resend the request. | ||
schnittstellen/idempotency.txt · Last modified: by admin
