User Tools

Site Tools


schnittstellen:idempotency

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

schnittstellen:idempotency [2026/10/14 15:26] – created adminschnittstellen: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 "Idempotency-key" it is basically an identifier to the request, according to which, an application should decide if it should run the business logic again or simply return the cached response from a previous request. To counteract this, a decently new HTTP header has been developed, called an "Idempotency-key" it is basically an identifier to the request, according to which, an application should decide if it should run the business logic again or simply return the cached response from a previous request.
 +
 +Heres a Diagram to visualize this:
 +
 +<uml>
 +@startuml
 +'https://plantuml.com/de/activity-diagram-beta
 +
 +start
 +:Request arrives with Idempotency-Key: key-xyz;
 +
 +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't match)
 +            :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
 +
 +</uml>
 +
 +And another Diagram to show how and what could go wrong with ERV BE PartnerAPI as an example:
 +
 +<uml>
 +@startuml
 +'https://plantuml.com/de/sequence-diagram
 +
 +title "Idempotency demonstration with PartnerAPI example"
 +
 +note across: Without Idempotency -- Retry = Saved twice
 +
 +client as "User/Client" -> server as "Server": POST /private/bookings {policy data}
 +server -> db as "Database": Persist Policy Data
 +note over server: Server crash / Timeout before sending response!
 +client --> client: Timeout -- no response recieved
 +client -> server: POST /private/bookings (RETRY)
 +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 /private/bookings { Idempotency-Key:key-abc }
 +server -> db: Persist Policy Data + save key-abc + response
 +note over server: Server crash / timeout!
 +client --> client: Timeout
 +client -> server: POST /private/bookings { Idempotency-Key:key-abc } (RETRY)
 +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
 +
 +</uml>
  
 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

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki