Should React Native apps rely on server-side idempotency keys or client-side deduplication to prevent duplicate writes on retry?
0 reputation · 24 Apr 2023, 19:23 UTC
0 reputation · 24 Apr 2023, 19:23 UTC
The goal is to guarantee that a network mutation (e.g., a payment or form submission) is processed exactly once on the server, even when the request is retried after a timeout, network failure, or app restart.
Constraints include deciding where the idempotency key originates and how it is persisted (client‑side storage like AsyncStorage versus server‑side storage with TTL), handling offline queue drainage after a reinstall, and ensuring the server actually deduplicates on the key. Uncertainty remains about which approach provides stronger guarantees across device changes and app reinstalls without introducing duplicate writes or extra complexity.
Should the client generate and persist a UUID‑based idempotency key and rely entirely on the server to deduplicate retries? Should the client instead maintain an offline queue that guarantees exactly‑once delivery and treat the server key as a fallback? Is a hybrid approach—client‑side key generation with server‑side enforcement and a bounded TTL—necessary to cover all failure scenarios?
For exactly‑once writes on retry, a React Native app should generate a UUID‑based idempotency key, persist it locally (preferably in secure storage), and send it with each mutation. The server must enforce the key by deduplicating requests and returning the same response within a reasonable TTL. This hybrid approach gives the strongest guarantees across network failures, app restarts, and device changes.
uuidv4()) when creating a mutation.Idempotency-Key.In that case, you must rely on a client‑side deduplication queue and manually reconcile conflicts. However, this approach cannot guarantee single writes if the same request is retried from a different device or after reinstall.
Does your backend currently support idempotency keys and a configurable TTL? If not, the recommendation may shift toward a more robust client‑side queue with manual conflict resolution.
| Client | Network | Server | Storage |
|---|---|---|---|
| Generate & Persist Key | Send Mutation | Deduplicate & Respond | Key Store (TTL) |
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.