CS FundamentalsVery hardProduct-company system-design interview

A mobile client sends POST /payments, the server charges the card, but the response is lost on a flaky network, so the client retries. How should the API prevent a double charge?

  1. A. Change POST to GET, which is safe
  2. B. Accept an idempotency key with each request and return the stored result when the same key is seen again
  3. C. Ask users never to retry
  4. D. Return 500 for every second request

Correct answer: B. Accept an idempotency key with each request and return the stored result when the same key is seen again

POST is not idempotent by definition, so retries can duplicate effects. A client-generated idempotency key lets the server recognise the retry and replay the original response instead of charging again.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic