Ali Saad
Database Engineering

Preventing Lost Updates in Multi-User .NET Applications

Ali Saad · November 9, 2026 · 4 min read

EF CoreSQL ServerConcurrencyData Integrity

Two people open the same employee record. One changes the department, while the other updates contact details using an older copy of the form. Both see a successful save, but the second submission restores the old department. No exception occurred and no service went offline. The application simply lost a valid update. This is the kind of correctness problem that ordinary single-user testing can miss.

Recognize stale data as an expected condition

A screen is a snapshot of data at the time it was loaded. By the time someone submits it, another user or background job may have changed the record. Faster queries reduce waiting, but they do not remove that gap. The application needs a policy for detecting and resolving stale writes.

Start by identifying operations where overwriting matters. Editing a draft description, approving a request, and changing a financial state do not necessarily need the same conflict behavior. Describe the consequences of a stale update before selecting a technical mechanism or applying one rule to every table.

Check the version when saving

Optimistic concurrency compares the version read by the caller with the version currently stored. The update succeeds only if the expected version still matches. In EF Core, a configured concurrency token participates in that check; an update or delete affecting no matching row can produce a concurrency exception that the application must handle.

SQL Server's rowversion can support this pattern. Despite its name, it is a generated version value, not a date or time. For a disconnected web form or API, carry the original version through the request and configure persistence to compare against it. Merely reading the latest version immediately before saving defeats stale-edit detection.

Choose a resolution that fits the workflow

A conflict should become an understandable outcome. For a form, show that the record changed and offer a reload or a review of competing values. Preserve the user's proposed edits where practical so resolving a conflict does not require retyping everything. Avoid replacing a clear business message with a raw database exception.

Automatic merging can work for independent fields, but it requires rules. Two changes to different columns may still conflict semantically: altering a department and its approval route is not always safe to combine. Approval and finance transitions often need revalidation against current state rather than a blind retry of the original write.

Protect invariants beyond one row

A concurrency token on one entity does not automatically enforce every rule involving several records. Preventing duplicate assignments, maintaining a balance, or enforcing a capacity limit may require database constraints, an appropriately scoped transaction, or another coordination mechanism. Identify the invariant and ensure the database operation actually protects it.

Keep database transactions short. Holding a lock while a person reviews a browser form is generally impractical and can block unrelated work. Prefer gathering user input first, then checking the current state and performing the protected transition within a bounded operation.

Test competing actors deliberately

Use two independent reads of the same starting record, then save them in sequence. Assert that the second stale write receives the intended conflict outcome and does not erase the first change. Repeat with a background update, a deleted record, and a state transition that becomes invalid between reading and saving.

Also verify the user-facing recovery path. A detected conflict is only half a solution if the screen loses the proposed values or offers an action that will fail again. Concurrency tests should establish both data protection and a practical way for the user to finish their work.

Key takeaways

  • ✓Treat stale edits as a normal multi-user scenario.
  • ✓Compare the original record version during persistence.
  • ✓Resolve conflicts according to business meaning.
  • ✓Protect cross-record invariants with appropriate database guarantees.

Conclusion

Concurrency handling makes successful saves trustworthy. The goal is not to prevent every simultaneous edit, but to stop one valid action from silently erasing another. Clear version checks, business-aware resolution, and deliberate competing-user tests provide a strong foundation for dependable enterprise applications.

Related articles

All articles