.NET Developer Interview Question

Two users edit the same order at once and one change is silently lost. How do you prevent that?

What the interviewer is probing, how to structure your answer, and a spoken example you can adapt.

Quick answer

That is a lost update, and the usual fix in EF Core is optimistic concurrency. Add a concurrency token, such as a rowversion column in SQL Server, so updates include the original version in the WHERE clause. If someone else changed the row first, no rows match, EF Core throws a DbUpdateConcurrencyException, and you resolve it: reject and reload, merge, or let the user choose. Keep pessimistic locks for short, high contention operations.

Why interviewers ask this

Concurrency bugs in business applications are common and expensive, and they rarely show up in testing. The interviewer wants the problem named correctly, optimistic concurrency explained mechanically, and a sensible resolution strategy that involves the user where it matters. Knowing when pessimistic locking is appropriate, and how an API should report a conflict, for example with a precondition check, shows complete thinking.

How to structure your answer

  • Name the problem and explain how it happens.
  • Explain optimistic concurrency with a concurrency token.
  • Describe how you handle the conflict exception.
  • Say when pessimistic locking fits, and how the API reports conflicts.

Example answer

Spoken example, first person

This is the lost update problem. Both users load version one of the order, both edit, and whoever saves second overwrites the first person's change without anyone knowing. My default fix is optimistic concurrency. I add a concurrency token to the entity, a rowversion column in SQL Server. EF Core then includes the original value in the WHERE clause of the update, so if someone else saved in between, zero rows match and SaveChanges throws a DbUpdateConcurrencyException instead of quietly overwriting. The important decision is what to do with that exception. For most screens I return a conflict, the client reloads the latest version, and the user reapplies their change with a message saying someone else edited it. For an API, the client sends the version it read in an ETag with an If-Match header, so the server can reject stale updates with a 412. I only use pessimistic locks for short, high contention operations like allocating stock, because holding locks while a user thinks is asking for trouble.

Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.

See how it works

Follow-up questions to expect

  • How would you handle concurrency in a database without a rowversion type?
  • When would last write wins be acceptable?
  • How would you present a conflict to the user sensibly?

Related .net developer questions

Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.

Predict my questions

Rehearse the hard questions before they are asked

Practise with a live copilot, then walk in ready. A $29 Session Pass gets you through the interview with no subscription and no lock-in.

Get GhostPilot