Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add idempotency middleware #226

Merged
merged 5 commits into from
Dec 9, 2021
Merged

Add idempotency middleware #226

merged 5 commits into from
Dec 9, 2021

Conversation

nanuuki
Copy link
Contributor

@nanuuki nanuuki commented Dec 8, 2021

This adds basic idempotency middleware for POST endpoints:

  • only the idempotency key is stored, so the payload is not examined when checking the received idempotency key and hence only 409 can be returned (key already used). A 422 response would require storing the payload.
  • there are 3 supported "databases" (see README for configuration):
    • local: in-memory, single instance only, mainly for testing purposes
    • shared: use the same db as main app
    • redis: use a separate Redis instance
  • keys expire after 1 hour, meaning the same key can be used after >1 hour after previous usage
  • key is expected to be sent in the Idempotency-Key header (OpenAPI spec has been updated accordingly)

Resolves #185

@nanuuki nanuuki requested a review from latenssi December 8, 2021 13:26
@nanuuki nanuuki force-pushed the feature/185-add-idempotency-key branch 2 times, most recently from 4061adc to 9623ac0 Compare December 8, 2021 13:28
openapi.yml Show resolved Hide resolved
@nanuuki nanuuki force-pushed the feature/185-add-idempotency-key branch from 9623ac0 to b5f27b6 Compare December 8, 2021 13:31
docker-compose.yml Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
@nanuuki nanuuki force-pushed the feature/185-add-idempotency-key branch from eef0508 to ab4a842 Compare December 9, 2021 11:23
handlers/idempotency.go Outdated Show resolved Hide resolved
handlers/idempotency.go Outdated Show resolved Hide resolved
Copy link
Member

@latenssi latenssi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, nice job!

Only thing requesting for attention is the panics in the http handler. I think we should avoid panicing once the service is running but if you think it is necessary in that particular circumstance then I am ok with it.

@nanuuki nanuuki merged commit 805978c into main Dec 9, 2021
@nanuuki nanuuki deleted the feature/185-add-idempotency-key branch December 9, 2021 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add nonce/idempotency key to requests
2 participants