Ctrl K
Python · Senior · Theory

In a Django service, two concurrent requests are charging money from the same balance, and sometimes the balance goes negative or one of the charges gets lost. Why does this happen, and how would you fix it?

~4 min by voice

How to approach it

This checks whether the candidate understands the nature of the read-modify-write race (lost update) and why transaction.atomic doesn't cure it, and whether they can choose a suitable protection mechanism (pessimistic or optimistic locking, an atomic update, database constraints) while accounting for the related risks: deadlocks, retries and idempotency.

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsВозьмём перевод между двумя счетами, которые лежат в одной базе: списать с одного, зачислить на другой. Как вы это реализуете, чтобы при параллельных операциях деньги не потерялись и баланс не ушёл в минус? SeniorA Django monolith can no longer keep up with growing traffic. How would you design how it runs in production: the application server, the worker model, the number of workers, and working with the database? Mid-levelWhat is a database transaction, and what does the acronym ACID stand for? JuniorA method is annotated with @Transactional, but when an error occurs the data in the database isn't rolled back. What causes would you check? Mid-levelDuring a sale, an online store sold more units of a product than it had in stock. The code first checks the stock level and then decrements it. Why did this happen, and how would you fix it? 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