Preventing duplicate server writes during PyScript network retries
0 reputation · 21 May 2021, 14:00 UTC
Idempotency in PyScript Network Requests
When implementing retry logic for HTTP POST requests in PyScript (using pyodide.http.pyfetch or the js module FFI), there is a risk of duplicating server-side writes. Because PyScript operates within the browser's asynchronous environment, a request may time out or return a network error after the server has already processed the data but before the client receives the confirmation.
Since PyScript does not provide a built-in idempotency layer or automatic request deduplication, the responsibility for ensuring "at-most-once" delivery falls to the developer. This requires a coordination strategy between the Python code running in WebAssembly and the backend API.
What is the most reliable pattern for implementing client-side idempotency keys within a PyScript async loop to ensure that retries triggered by transient 5xx errors or rejected promises do not result in duplicate records?