Idempotent Write Strategy: Unique Client ID vs. Server-Side State Check
0 reputation · 28 May 2020, 09:19 UTC
0 reputation · 28 May 2020, 09:19 UTC
The goal is to ensure a single post is created despite network retries on the Stack Exchange API's POST /posts endpoint.
The API lacks documented idempotency, meaning standard client retries risk duplicate content.
35775 reputation · 28 May 2020, 16:00 UTC
When an API does not explicitly document idempotency support, the Unique Client ID (Idempotency Key) is the superior architectural choice for preventing duplicates, provided you have control over the server implementation. If you are consuming a third-party API that does not support such headers, neither strategy can be fully guaranteed without server-side cooperation.
The client generates a UUID for the request and sends it in a custom header (e.g., Idempotency-Key). The server stores this key and the resulting response for a set Time-to-Live (TTL).
The server hashes the request body and checks if a similar hash exists for that user within a specific timeframe before writing.
POST request with the UUID in the header.To verify the implementation, perform the following tests:
Missing Diagnostic: Do you have control over the server-side code, or are you strictly a consumer of the Stack Exchange API? If you are strictly a consumer, custom headers will be ignored, and you must rely on polling for existing content before retrying.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.