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?
- A. Change POST to GET, which is safe
- B. Accept an idempotency key with each request and return the stored result when the same key is seen again
- C. Ask users never to retry
- 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.
Practise more Software Engineering, Git and Cloud Basics questionsSoftware Engineering, Git and Cloud Basics: notes and key points
More Software Engineering, Git and Cloud Basics questions
- A feed API uses ?offset=20&limit=20 pagination. While a user reads page 1, 5 new items are inserted at the top. What goes wrong on page 2…
- During a network partition between two data centres, a replicated database must either reject some writes or accept writes on both sides…
- An order service and a payment service each own their database. Placing an order must reserve stock, charge the card and create the order…
- A circuit breaker protecting calls to a slow service has three states. Which sequence is correct?
- A Kubernetes pod takes 60 seconds to warm its cache after start-up. During that time it should get no traffic but must not be restarted…
- A CI workflow uses a build matrix of 3 operating systems x 4 language versions, with 2 specific combinations excluded. How many jobs run…