Idempotency in Your API with DynamoDB
Is it safe to retry? For most APIs the honest answer is no, not without work. Any request that can be retried will eventually be retried against a handler that already succeeded, and unless you have designed for it, every retry applies the operation again. The retries are not hypothetical. A client times out and sends the request a second time. API Gateway gives up at its integration timeout and returns a 504 while the Lambda behind it keeps running and commits the write anyway, a case I covered in Part 4 of the Rust on Lambda series. An SQS or event-source trigger redelivers a message because delivery is at-least-once by default. The common thread is that at-least-once delivery is what you get for free; exactly-once is something you build. This post is about building it with DynamoDB conditional writes. ...