Scrivio Interview library
LeadershipPrincipal6 min read · updated 12 November 2026

Concurrency bugs (lost updates, double bookings) are found years after systems go live and are expensive to fix. What organisational practices reduce this risk over the long term?

Concurrency bugs are cheap to prevent at design time and expensive to find later, so I would make concurrency control a required part of design reviews for every write path, and use database constraints as the last line of defence for invariants. I would add concurrency and contention tests to the pipelines, train engineers on isolation anomalies with real examples from our own systems, and track and publish concurrency incidents so every team learns from them.

Background to this question

Lost updates and double bookings rarely show up in testing, because tests run one request at a time. They appear in production, under load, sometimes years later, and by then the data is already wrong and must be repaired. A senior leader's job is to change how the organisation builds systems so these bugs are caught early. In this answer, we will see why they escape normal practice, then go through the practices that catch them, with the reasoning and an example for each.

1Why Concurrency Bugs Escape

A lost update needs two requests to touch the same data within milliseconds. In development and in most automated tests, requests come one at a time, so the bug cannot appear. In production at low traffic it appears rarely, perhaps once a month, and looks like a data glitch. As traffic grows, it becomes frequent, and by then hundreds of records may be wrong and the code has been copied into other services.

The other reason is knowledge. Many engineers believe that a transaction protects them, without knowing that the default isolation level, READ COMMITTED in PostgreSQL, allows lost updates in a read-modify-write sequence. So the organisational response must address both: create conditions in which the bug appears early, and make sure people know what to look for.

2Practice 1: Concurrency in Every Design Review

The cheapest place to fix a concurrency bug is on the whiteboard. I would add one required question to the design review template for any change that writes data: what happens if two requests do this at the same time for the same record, and which mechanism prevents the wrong outcome? The answer must name a mechanism, such as an atomic update, @Version, a row lock or a unique constraint. If nobody can answer, the design is not ready.

Take a seat booking feature as an example. The review asks what happens when two users book seat 12A at once. Without the question, the design checks if the seat is free and then inserts a booking, which can double-book. With it, the team adds a unique constraint on show and seat, and the problem disappears before any code is written.

Step throughReview question for every write path
  1. Can two requests change this data at once?
    YesName the conflictNoDocument why not
  2. Which mechanism prevents the wrong outcome?Atomic update, version, lock or constraint
  3. Is there a database constraint as backstop?
    YesRecord itNoAdd one or explain why none fits
  4. Is there a concurrent test for it?
    YesApprove the designNoAdd the test to the plan

4 steps in order. Play them, or step through them one at a time.

Four questions in a template catch most concurrency bugs before code exists.

3Practice 2: Constraints as the Last Line of Defence

Application checks can be bypassed by a race, a second service, a batch job or a manual script. Database constraints cannot. A unique constraint prevents double bookings, a check constraint such as balance >= 0 prevents negative balances, and a foreign key prevents orphan records. When the application logic fails under concurrency, the constraint turns silent data corruption into a visible error that can be retried or reported.

So I would set a standard: every business invariant that can be expressed as a constraint must have one, even when the application also checks it. The cost is a few lines in a migration; the benefit is that the worst case changes from wrong data discovered in an audit to an exception in a log.

4Practice 3: Concurrency Tests in the Pipeline

Bugs that only appear under concurrency need tests that create concurrency. A simple pattern is to start many threads that perform the same operation on the same record at the same moment, then assert the invariant. With Testcontainers the test runs against a real PostgreSQL, because an in-memory database may lock differently.

Java
@Test
void concurrentDepositsAreNotLost() throws Exception {
long id = accounts.create(BigDecimal.ZERO);
int threads = 20;
var start = new CountDownLatch(1);
try (var pool = Executors.newFixedThreadPool(threads)) {
for (int i = 0; i < threads; i++) {
pool.submit(() -> { start.await(); service.deposit(id, BigDecimal.TEN); return null; });
}
start.countDown(); // release all threads at once
} // close() waits for all tasks
assertThat(accounts.balance(id)).isEqualByComparingTo("200");
}
// with a read-modify-write bug: balance is 40 or 90 or 130 ... -> test fails

Beyond unit-level tests, load tests should include contention: many users acting on the same few records, such as one popular product, rather than spreading requests evenly across millions of records, which hides the problem.

5Practice 4: Training With Real Examples

Abstract definitions of isolation levels do not stick. What works is a short internal course built on our own code: a lost update in a balance, a write skew in on-call scheduling where two doctors both go off duty, a double booking. Engineers reproduce each one with two database sessions side by side, then fix it. A one-hour lab like this, part of onboarding, gives people the instinct to ask the design review question themselves.

6Practice 5: Track and Publish Incidents

Finally, we make the problem visible. Every incident caused by a concurrency bug gets a tag and a short, blameless write-up: what happened, which mechanism was missing, and how it was found. A quarterly summary shared across teams shows patterns, such as three teams hitting the same lost update in counters, and drives fixes like a shared helper or a new constraint standard. Over time the count of such incidents, and how long they stayed hidden, shows whether the practices work.

7Follow-up questions

How do you prioritise fixing systems that are already live?

Start with the write paths that handle money, inventory and bookings, and look for read-modify-write code without a version, lock or atomic update. Adding database constraints first gives fast protection, and the code fixes follow in order of business risk.

Is SERIALIZABLE isolation everywhere a simpler answer?

It prevents all these anomalies, but every transaction must then handle serialization failures with retries, and throughput under contention drops. It is a good tool for specific multi-row invariants, not a blanket replacement for design thinking.

How do you keep design reviews from becoming box-ticking?

Keep the question short and ask for a named mechanism, not a yes. Reviewers should occasionally ask the author to walk through the two-request timeline aloud; that quickly shows whether the answer is real.

8Conclusion

In this answer, we saw that concurrency bugs escape because ordinary tests and low traffic never create the timing that triggers them, and because many engineers overestimate what transactions guarantee. The practices that reduce the risk are a required concurrency question in design reviews, database constraints for every invariant, concurrency and contention tests in pipelines, hands-on training with real anomalies, and tracked, published incidents that drive shared fixes.

What to say in the interviewAbout 80 seconds aloud

Open with

These bugs escape because tests and early traffic never put two requests on the same record at the same moment, and because many engineers assume a transaction protects them when READ COMMITTED does not prevent a lost update.

Then, if they want more

So I would act at several points. First, design reviews: every design that writes data must answer what happens if two requests do this at once for the same record, and name the mechanism, an atomic update, a version, a lock or a constraint.

Second, database constraints as the last line of defence: unique keys against double bookings, check constraints against negative balances, so a race becomes an error instead of bad data.

Third, tests: concurrency tests that release twenty threads at once against a real database in Testcontainers and assert the invariant, and load tests with contention on hot records rather than evenly spread traffic. Fourth, training with our own examples, a lost update, a double booking, a write skew, reproduced in two sessions side by side.

Fifth, tag concurrency incidents, write them up without blame and publish a quarterly summary, so patterns lead to shared helpers and standards, and the incident count tells us whether this is working.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Concurrency bugs (lost updates, double bookings) are found years after systems go live...": https://scrivio-interview-library.netlify.app/databases/locking-and-concurrency-control/6677bb1e47/