Skip to content
Back to blog
Production note•Oct 23, 2026

Preventing lost work when two people edit the same record

Use version checks to detect stale writes, preserve the user’s draft, and make conflicts understandable.

ArchitectureReliabilityAPI DesignUX

Both saves succeeded; one person's work disappeared

Two operators open the same service request. One corrects the contact details. The other changes the priority and saves an older copy of the whole form. Both see a success message, but the second save restores the old contact details.

No request failed. The system accepted a decision based on information that was already out of date.

This is a different problem from retrying the same action. An idempotency key can identify a repeated submission. Here, two separate intentions compete over the same record.

Decide which changes may overwrite each other

Start with the consequence of a collision. A personal display preference may reasonably use the latest write. A reviewed application, published price, or customer record needs a more deliberate rule.

Sending only changed fields reduces accidental overwrites, but it does not resolve every conflict. Two people can still edit the same field. Changes to different fields can also violate a shared rule: a discount and a base price may each look valid against the old record while producing an invalid combination together.

Write down the unit of consistency. Is it one field, a whole record, or several related records? That decision determines where a conflict must be detected.

Carry the version the editor actually saw

For a record-level policy, return an integer version with the editable data. Include that version when saving, and make the database update conditional on it still matching.

UPDATE service_requests
SET priority = $1,
    version = version + 1
WHERE id = $2
  AND workspace_id = $3
  AND version = $4
RETURNING id, priority, version;

The parameters represent the proposed priority, record ID, authorized workspace, and version originally loaded. The server must validate the input and derive the workspace scope from the authenticated caller.

If one row is returned, the change was accepted. If no row is returned, the caller may have stale data, the record may have been deleted, or it may be outside their authorized scope. Resolve those cases without revealing inaccessible records. An authorized editor with a stale version can receive a conflict response, such as HTTP 409.

Every writer covered by this policy must check and increment the version, including background jobs and bulk actions. One unconditional update creates a gap in the guarantee.

Put the comparison inside the write

Reading the version in application code and then issuing an unconditional update leaves time for another save between those two steps. The condition belongs in the database statement that changes the row.

PostgreSQL documents how, at Read Committed isolation, a competing update waits and then rechecks its condition against the updated row. That behavior supports this single-row version check. Wrapping an ordinary read and unconditional write in a transaction alone does not provide the same protection.

Rules spanning multiple rows need a wider concurrency design, such as appropriate locking or serializable transactions with retry handling. A version on one row cannot protect every related invariant.

Treat a conflict as an editing state

A useful conflict message explains what happened: “This request changed while you were editing. Review the latest version before saving.” Keep the local draft available.

Show the latest saved value alongside the proposed change where practical. Let the user reload, copy their draft, or deliberately reapply it against the new version. Automatically retrying with the latest version can silently approve an overwrite the user never reviewed.

Verify with two editors

Open the same version in two sessions. Save in the first, then save in the second. The first change should remain intact, and the second editor should see a conflict with their draft preserved. Repeat with reversed timing and a background writer.

The useful outcome is that nobody loses work behind a success message. A conflict the user can resolve is easier to trust than a save that quietly erases someone else's decision.

Facing a similar problem in your product? Let’s discuss your situation and the work you need.