A PR with changes around invoice posting through an HTTP handler and an in-memory result store appeared in the service. After the update, complaints started coming in about rare duplicate writes and unstable behavior when parallel requests with the same key are sent. We need to review the diff and find problems in the after version.
POST /invoices/post handler accepts JSON with the fields invoice_id and amount.Idempotency-Key header.Idempotency-Key and the same request body, the service must return the previously saved result without reposting the invoice.after into a Go module.go test -race ./...
Idempotency-Key to POST /invoices/post.-race.1.24net/httpPOST /invoices/post{"invoice_id":"inv-1","amount":120}Idempotency-KeyStore state must be protectedUse line comments to explain the problem, its impact, the fix and how to test it.