Implementing Transactional API Idempotency With Node.js and PostgreSQL
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.
You May Also Like

This Week in Startups
Jason Calacanis

De Grote Tech Show | BNR
BNR Nieuwsradio

Packet Protector
Packet Pushers
Accidental Tech Podcast
Marco Arment, Casey Liss, John Siracusa

Tech Brew Ride Home
Morning Brew

Mark Tilbury
Mark Tilbury Fan

The New Stack Podcast
The New Stack

Artificial Intelligence Masterclass
AI Masterclass

The Paul Barron Crypto Show
paulbarronnetwork.com

First Ring Daily
Paul Thurrott and Brad Sams
Community discussion