-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat: add idempotency interceptor #4531
Conversation
4798d36
to
0b566a6
Compare
@mahendraHegde We are seeing the following error in the pipeline
|
@Cliftonz i think its a mistake of auto import, let me fix this |
f4bf5fb
to
8d253d7
Compare
@Cliftonz can you try now? |
Hi @mahendraHegde, thanks for the great work on this PR already. @Cliftonz and I have discussed a few additions to the idempotency implementation which we think will deliver significant short and long-term benefits to users of this feature, using Stripe API as a guide for these additional implementation details. These are changes that will be potentially breaking to add later, should a client begin to depend on the existing implementation detail. These additions are summarised below, with rationale in brackets.
If you could please include these updates in the PR alongside the other suggestions, we can move this through to include in the next release 😃 |
25eefcf
to
9d73164
Compare
@rifont i have fixed comments and added few comments, let me know your thoughts |
9d73164
to
89601f2
Compare
89601f2
to
40e5226
Compare
Hey @mahendraHegde, I've added a few last comments on the PR. Additionally, could you please test with your own API key via curl/Postman to verify the following scenarios and post screenshots in the PR description, as we had issues in practice with API key auth in the previous merge of the PR:
Lastly, we need to update the Idempotency docs PR (novuhq/docs#202) to reflect new behavior. Thanks again for your great work on this critical reliability feature. We're nearly there 🙌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @mahendraHegde 👋 thanks a lot for your contribution to Novu 🙌
I hope that I'm not too late for the party here 😄 left you a few suggestions 😉
…address review comments
@Cliftonz @rifont @LetItRock I believe i have addressed all review comments let me know if i missed any. |
@rifont The pipeline is failing due to bad container build all of the unit test have passed for this. |
I have verified the feature locally: Testing Snippet
Initial Request with key >
curl -v -X POST http://localhost:3000/v1/events/trigger \
-H "Authorization: ApiKey XXXXXXXXXXXXXXXXXX" \
-H "Idempotency-Key: 12341" \
-H "Content-Type: application/json" \
-d '{
"name": "sample",
"to": {
"subscriberId": "XXXXXXXXXXXXXXXXXX",
"email": "john@doemail.com",
"firstName": "John",
"lastName": "Doe"
},
"payload": {
"name": "Hello World",
"organization": {
"logo": "https://happycorp.com/logo.png"
}
}
}'
...
> Authorization: ApiKey XXXXXXXXXXXXXXXXXX
...
< HTTP/1.1 201 Created
...
< Idempotency-Key: 12341
...
{"data":{"acknowledged":true,"status":"processed","transactionId":"297b420f-8685-4545-b055-bea3e81e8841"}}% Replayed Request with key >
curl -v -X POST http://localhost:3000/v1/events/trigger \
-H "Authorization: ApiKey XXXXXXXXXXXXXXXXXX" \
-H "Idempotency-Key: 12341" \
-H "Content-Type: application/json" \
-d '{
"name": "sample",
"to": {
"subscriberId": "XXXXXXXXXXXXXXXXXX",
"email": "john@doemail.com",
"firstName": "John",
"lastName": "Doe"
},
"payload": {
"name": "Hello World",
"organization": {
"logo": "https://happycorp.com/logo.png"
}
}
}'
...
> Authorization: ApiKey XXXXXXXXXXXXXXXXXX
> Idempotency-Key: 12341
...
< HTTP/1.1 201 Created
...
< Idempotency-Key: 12341
< Idempotency-Replay: true
...
{"data":{"acknowledged":true,"status":"processed","transactionId":"297b420f-8685-4545-b055-bea3e81e8841"}}% Reused key >
curl -v -X POST http://localhost:3000/v1/events/trigger \
-H "Authorization: ApiKey XXXXXXXXXXXXXXXXXX" \
-H "Idempotency-Key: 12341" \
-H "Content-Type: application/json" \
-d '{
"name": "sample",
"to": {
"subscriberId": "XXXXXXXXXXXXXXXXXX",
"email": "john@doesmail.com",
"firstName": "John",
"lastName": "Doe"
},
"payload": {
"name": "Hello World",
"organization": {
"logo": "https://happycorp.com/logo.png"
}
}
}'
...
> Authorization: ApiKey XXXXXXXXXXXXXXXXXX
> Idempotency-Key: 12341
...
< HTTP/1.1 422 Unprocessable Entity
...
< Idempotency-Key: 12341
< Link: docs.novu.co/idempotency
{"message":"Request with key \"12341\" is being reused for a different body","error":"Unprocessable Entity","statusCode":422}% Initial Request with key >
curl -v -X POST http://localhost:3000/v1/events/trigger \
-H "Authorization: ApiKey XXXXXXXXXXXXXXXXXX" \
-H "Idempotency-Key: 12345" \
-H "Content-Type: application/json" \
-d '{
"to": {
"subscriberId": "XXXXXXXXXXXXXXXXXX",
"email": "john@doesmail.com",
"firstName": "John",
"lastName": "Doe"
},
"payload": {
"name": "Hello World",
"organization": {
"logo": "https://happycorp.com/logo.png"
}
}
}'
...
> Authorization: ApiKey XXXXXXXXXXXXXXXXXX
> Idempotency-Key: 12345
...
< HTTP/1.1 400 Bad Request
...
< Idempotency-Key: 12345
...
{"message":["name should not be null or undefined","name must be a string"],"error":"Bad Request","statusCode":400}% Replayed >
curl -v -X POST http://localhost:3000/v1/events/trigger \
-H "Authorization: ApiKey XXXXXXXXXXXXXXXXXX" \
-H "Idempotency-Key: 12345" \
-H "Content-Type: application/json" \
-d '{
"to": {
"subscriberId": "XXXXXXXXXXXXXXXXXX",
"email": "john@doesmail.com",
"firstName": "John",
"lastName": "Doe"
},
"payload": {
"name": "Hello World",
"organization": {
"logo": "https://happycorp.com/logo.png"
}
}
}'
...
> Authorization: ApiKey XXXXXXXXXXXXXXXXXX
> Idempotency-Key: 12345
.
< HTTP/1.1 400 Bad Request
...
< Idempotency-Key: 12345
< Idempotency-Replay: true
...
{"message":["name should not be null or undefined","name must be a string"],"error":"Bad Request","statusCode":400}% Superb work on this feature @mahendraHegde ! Thank you for this important contribution. @LetItRock could you please take a look at the requested changes? |
@mahendraHegde Looks good to me. Excellent job! Thank you! 🙌 |
What change does this PR introduce?
Reopens #4472
Why was this change needed?
closes #4469
Other information (Screenshots)
New request

Replayed request
