Ctrl K
Backend · Senior · Theory

A client calls your create-payment endpoint, the response is lost to a timeout, and the client retries the request. How would you design the API so the money isn't charged twice?

~4 min by voice

How to approach it

This checks whether you can make a non-idempotent operation (a POST that creates a payment) safe to retry: an idempotency key from the client, atomic recording on the server, correct handling of races, and idempotency along the whole chain, including the external provider.

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsКак вы выстроите защиту API, через которое мобильное приложение получает данные о счетах клиента, — на всём пути от приложения до базы? SeniorWrite a handler for creating a payment that takes an idempotency key and the payment data and returns the result. A repeat request with the same key must not charge the money a second time, even if two identical requests arrive simultaneously on different instances of the service; you have a database and an external payment provider. SeniorСервис зачислений читает из Kafka события об успешных платежах и пополняет счёт клиента. Как вы гарантируете, что одно и то же событие не зачислит деньги дважды? SeniorHow would you implement pagination in a feed API with millions of records where new ones are constantly being added? What options do you know, and how do they differ? Mid-levelDesign a rate limiter for a public API: for example, no more than 100 requests per minute per API key. The service runs on several instances. Mid-level

Answer by voice

The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.

Sign in to answer

Best with headphones · ~4 min