This story was originally published on HackerNoon at:
https://hackernoon.com/implementing-transactional-api-idempotency-with-nodejs-and-postgresql.
With idempotency keys in Redis, a crash can still charge twice. Keep the key in the same Postgres transaction as the write (Node.js) so a crash rolls back both.
Check more stories related to programming at:
https://hackernoon.com/c/programming.
You can also check exclusive content about
#api-development,
#transactional-idempotency,
#postgresql,
#nodejs,
#idempotency-keys,
#redis-distributed-locks,
#api-retry-mechanisms,
#hackernoon-top-story, and more.
This story was written by:
@dmatoso. Learn more about this writer by checking
@dmatoso's about page,
and for more stories, please visit
hackernoon.com.
A Redis idempotency store can still charge a customer twice if the server dies between the write and saving the response. I reproduce the double charge, then move the key into the same Postgres transaction as the payment, so a crash rolls back both.