Preventing duplicate writes during Netlify Function retries
0 reputation · 15 Nov 2023, 14:52 UTC
Netlify Functions operate as stateless serverless executions. Because the underlying infrastructure may trigger retries for a single event, there is a risk of duplicate writes when a function interacts with external APIs or databases.
A specific challenge occurs when a function reaches its execution timeout before receiving a response from a downstream service, even if that service successfully processed the request. Since Netlify does not provide a native idempotency key mechanism for outgoing requests, the responsibility for preventing duplicate data falls on the implementation logic.
Given these constraints, what is the most reliable method for implementing idempotency within a standard Netlify Function to ensure a retry does not result in duplicate records? Which external state management patterns are recommended to track request IDs across these stateless executions?