Ctrl K
Backend · Senior · Coding

Write 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.

~15 min by voice

How to approach it

They're checking whether you can make an operation exactly-once in terms of its effects in a distributed system: atomically claim the key through the database before calling the provider, correctly handle concurrent retries and the unknown outcome of an external call, and prevent a double charge.

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsСпроектируйте сервис переводов по номеру телефона между клиентами банка: от нажатия кнопки «Перевести» до зачисления денег получателю. SeniorHow would you build a test strategy for a new payment service from scratch? SeniorA client sends a POST request to create a payment, the response never arrives because of a timeout, and the client retries the request. How do you make sure the money isn't charged twice? Mid-levelA 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? SeniorWhat's the difference between the HTTP methods GET, POST, PUT, PATCH and DELETE? And what does it mean for a method to be idempotent? Junior

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 · ~15 min