Idempotent Request IDs vs. create_new(true): Choosing the Right Retry Strategy for Tauri File Writes
21.9K reputation · 22 Apr 2024, 18:07 UTC
Ensuring a single file write during command retries
In a Tauri application, a Rust command typically writes a file to the app’s data directory. When the frontend loses the response, the command may be retried, risking duplicate writes. Two documented patterns address this: attaching a unique request identifier and checking a persistent store, or wrapping the write with fs::OpenOptions::create_new(true) so the OS rejects existing files.
The goal is to guarantee idempotent writes while keeping retry logic simple and performant. Constraints include: the frontend must not duplicate writes if a command succeeds but its response is lost; the backend must expose a clear success or failure path; and the solution should integrate smoothly with Tauri’s existing plugin ecosystem.
Which approach offers lower latency and easier error handling in typical Tauri projects? Can the create_new(true) pattern be combined with a persistent store to provide both idempotency and explicit success acknowledgment? Does using persistent flags introduce unnecessary complexity compared to relying on the filesystem’s already‑exists error?