It starts with a key
Your app sends POST /payments with an Idempotency-Key generated on the device. If the network hiccups and the app retries, the key stays the same.
That one header is what makes “charged twice” impossible later on.
Follow a single payment through a backend built so it is never lost, never charged twice, never silently stuck. Scroll to move it along. Tap any block to jump there.
a walkthrough by Eduard Iadigarov · backend engineer, Java & Spring
Your app sends POST /payments with an Idempotency-Key generated on the device. If the network hiccups and the app retries, the key stays the same.
That one header is what makes “charged twice” impossible later on.
The gateway terminates TLS, checks the OAuth2 token, applies rate limits per user and stamps a trace ID that will follow this payment through every system it touches.
The payment service runs SET key NX in Redis. The first request wins the key. Any duplicate gets the stored answer of the first one instead of a second charge.
Daily limits, velocity checks, a risk score. It has to answer within a few milliseconds, so counters live in memory and the decision stays cheap: allow, challenge or decline.
The payment row and an outbox event are written in one PostgreSQL transaction. Either both exist or neither does. Money is double-entry: every debit has a matching credit.
A relay reads the outbox and publishes to Kafka. Notifications, analytics and the bank connector each consume at their own pace. If one of them is down, events wait, nothing is lost.
Timeouts, retries with exponential backoff, a circuit breaker. The connector sends the same idempotency key to the bank, so a retry can never turn into a second transfer.
What still fails after all retries is parked in a dead-letter queue, not dropped.
The instant-payment rail moves the funds between banks and confirms. The confirmation flows back through Kafka and the ledger flips PENDING → SETTLED.
Every night a job compares the bank statement with the ledger, line by line. Anything that doesn't match (a lost callback, a double, a missing cent) gets fixed or flagged before a customer notices.
Every hop emits traces, metrics and logs. Alerts fire on symptoms: rising latency, a growing dead-letter queue, a dip in settlement rate. The on-call engineer hears first, not support.
Backend engineer, Java & Spring. I work on payment integrations and the unglamorous, reliable plumbing around them, the kind of system you just scrolled through.
A teaching model: real systems differ in the details, not in the spirit. Built with Three.js.