Closed NotIlya4 closed 11 months ago
Hello @NotIlya4
Thank you for taking the time to report this.
By default, the IdempotentAPI
library caches only the responses with 2xx HTTP status codes. However, this is configurable in the attribute. So, if, in your business case, you would like to cache the error response, you should set the CacheOnlySuccessResponses
option to false
.
If this does not help you, could you provide more information on the issue to be investigated?
I'm referring to situations where, after successfully writing to the database, my service goes down before saving to the cache. Am I right that, in this case, if a user sends a request again, it will be processed twice, resulting in the same transaction occurring twice? It seems like the only way to prevent this is to write to a separate table with idempotency tokens and a unique constraint column within the same transaction.
The source of truth for the IdempotentAPI
library is the cache.
Yes, in such a case, in which the application is not gracefully stopped, a following request with the same idempotency key will be processed.
To deal with this, you could store the "idempotency key" in the database in the same transaction (be part of your business code). You could use the IdempotentAPI
library by implementing the IIdempotencyCache
interface, having your database as a source of truth (either primary or secondary). You can follow existing implementations as examples.
However, you could also investigate how to shut down the application gracefully.
Gracefully stopping application in prod environment is not possible. Pod/node could go down without any reason at any time))
I'm new in idempotency tokens so I'm looking for different reliable solutions, thanks for the answers)
I'm not sure, but if I successfully process the request (e.g., write the transaction to the database) and it fails before saving it in the cache, if the client makes the same request a second time, my app would execute the same transaction twice.