Reputation: 3761
I'm creating a POST api in which I'm using REDIS for idempotency.
I'm taking a idempotency-key
in header which is getting saved in Redis.
When the same request comes in, I'm returning the cached message.
In redis I'm saving it as idempotency-key: message-body with Http status
During load testing I sent the same request, with same idempotency-key 30 times.
As expected, 5/30 times, the same request was stored in Redis, because new request comes in before the first finished.
In redis, how can I avoid it, without making API slow?
I did not find much material on net.
Apart for redis I only have dynamo as a centralized DB.
Upvotes: 0
Views: 914
Reputation: 2176
In redis, how can I avoid it, without making API slow?
By locking on the idempotency key when you start processing the request.
The goal of idempotency is not only always returning same response, but also ensuring that the action was executed exactly once and not multiple times.
Upvotes: 0