Two users edit the same record: how to test concurrent changes
Updated:
Two colleagues open the same CRM record and edit different parts. Both receive a save confirmation, but one change is missing after the page is refreshed. Testing concurrent edits needs to cover the resulting data and the application’s behaviour when a conflict occurs. This approach is useful for company portals, order administration and other systems where several people work with one record.
How a confirmed change gets lost
Consider a sample sales opportunity record numbered 37, at version 8. The next contact date is Friday and the note reads “Call the customer”. Eva and Martin load the same version. Eva moves the date to Monday and saves it. Martin then adds information about a new contact number to the note.
If Martin’s form submits the entire original record, including the Friday date, the server may overwrite Eva’s change. Martin edited the note but also sent a stale date. The result is a lost update. An ordinary test that opens and saves one form does not cover this sequence.
The problem can also occur in two tabs used by the same person or during an automatic background update. What matters to the test is the version each request is based on. The number of people signed in does not by itself determine whether a conflict occurs.
Agree on conflict rules
Before testing, decide which changes the application may merge and which it should reject. A note and a contact date might be independent, but changing the status to “Closed” could change which edits are permitted in other fields. Automatic merging must therefore respect business rules and relationships between values.
In a simpler design, the server rejects a save based on a stale version, and the user decides after loading current data. Another design merges independent fields but reports a conflict when two edits affect the same field. A record lock temporarily restricts other editors. Each approach needs its own expectations, including what happens when a window closes or a lock expires.
Specify whether the application should preserve draft text, show differences and offer another editing attempt. A message saying only “Save failed” does not tell the user what to do. A success confirmation should make clear which values the server actually saved.
Reproduce a stale form in two sessions
Use two test accounts with the required permissions and two separate browser contexts. Separate contexts have their own sign-in state and storage, so one user does not take over the other’s session. Both accounts should first load the same test record.
- Check the initial values and record version.
- Change the contact date in the first session and wait for a confirmed save.
- Keep the original form in the second session, edit the note and submit it.
- Record the server response and the message in the interface.
- Fetch the record with a new request and compare the saved values with the conflict rules.
If the second edit is rejected, the new date and original note should remain saved. The interface should preserve Martin’s draft according to the specification so that he can reuse it after comparison. If merging independent fields is allowed, expect both the new date and the new note.
Reverse the order of users and repeat the test. Then edit the same field to two different values. If the application deliberately accepts the last write, document that decision and test it. For data where silent overwriting causes a problem, the team needs a different policy.
Version checks through the API and If-Match header
The application programming interface, or API, carries requests between client and server. It lets you test a stale version directly without waiting for browser clicks. Version checking, often called optimistic locking, can use a version number or an HTTP request condition.
With HTTP, the server returns a representation identifier in the ETag header. The client sends it in If-Match when editing. RFC 9110 requires strong comparison. A weak identifier prefixed with W/ is not a matching validator for strong If-Match comparison. An unmet condition returns 412 Precondition Failed. An exception may allow a 2xx confirmation when the server can verify that the same requested operation has already occurred. An application conflict may use 409 Conflict, but its meaning differs from a failed If-Match condition.
For the sample test, Eva and Martin both load ETag: "record-37-v8". Eva saves an edit with that If-Match, after which the server assigns "record-37-v9" to the new representation. Martin sends the original value. The test expects rejection of the stale condition and no change to the state saved by Eva. It then fetches the current representation and prepares a new edit according to the application’s rules.
Add a request without a version to the suite. The API contract must define whether the server rejects it or supports another way of editing. Also verify that an unchanged version cannot bypass permission checks. A user still needs permission to edit a record even if they know its version.
Expose the gap between comparison and writing
Rejecting an old form does not yet prove safe processing of two requests received close together. The server might read the version first, compare it later and write afterwards. If both requests compare the same original version before either writes, both may pass.
Checking the current version and writing must be atomic, meaning one indivisible operation. One example is a conditional database update using both the identifier and expected version. The application then checks whether it updated the relevant row. The specific solution depends on the database and transactions in use.
Prepare two API requests with the same version and different edits. Hold them at a common point in the test tool and release them as close together as possible. Under a policy of rejecting stale versions, expect exactly one accepted write. The second attempt should receive the appropriate conflict and must not change the saved values.
Repeated runs check more timings but cannot confirm every possible request ordering. If the error is rare, a controlled pause between reading and writing in the test environment can help. A random delay makes the test slower and may still fail to create the required overlap.
Transaction isolation has its own rules too. The PostgreSQL documentation describes cases where an application must retry the entire transaction after a conflict. A database retry does not itself determine whether the application should accept an edit from a stale user form. Test that policy separately.
Check the interface after a rejected save
The page must not show an ordinary success confirmation after a conflict. Check that the user understands the reason and can continue. Loading current data should follow the agreed approach to preserving drafts. When comparing values, distinguish server data from the user’s proposed edit.
Also try a conflict after a longer idle period and repeated presses of the save button. If the application displays locally cached data, it should load the current state after a conflict. Verify a new save with a fresh server read rather than the text in the original form alone.
Include a permission change between opening and saving. A user whose access has been removed must not receive current data belonging to others just because they are handling a conflict. Both the server response and the screen should respect the new permissions.
Check side effects and confirm the result
An edit may trigger a notification, a history entry or another process. A rejected write must not create effects that belong to a successful change. For an accepted write, check the agreed number and content of events. A failed attempt may have its own technical log entry, which should not be confused with the history of saved edits.
A defect report should include the initial version, request order, responses and final values. Use synthetic data and omit authentication tokens. A developer can then assess whether version comparison, writing or result display failed. The article on what to test at the API level covers further interface checks.
Extend scenarios to status changes and deletion
Two text edits do not cover every business relationship. Have the first user close the opportunity and the second submit an edit from the originally open form. Expect rejection or a permitted change according to the rules for a closed opportunity. If it succeeds, check that the second request has not restored the original status.
Test deletion or archiving between loading and saving separately. A stale edit must not unintentionally restore the record. The API contract defines the response for an object that no longer exists or is no longer accessible. The interface should explain how to proceed without displaying data the user is not entitled to see.
For each pair of operations, record the initial state, permitted results and prohibited side effect. This matrix separates a technical version conflict from rejection of a business state transition. Tests should then avoid accepting any error response simply because the server rejected the second request.
The save succeeded, but its confirmation was lost
A version conflict is not the only reason a client fails to see success. For model record 37, have Eva save the Monday contact date, but lose the confirmation response. The server already has version 9 while the form still knows version 8. Prepare this sequence by interrupting the response in a controlled test environment. A delay alone may not establish whether the server completed the write.
| Next step | Expected check |
|---|---|
| Eva repeats the same request | Depending on the contract, she receives rejection of the old version or confirmation of the change already applied. No second business change or duplicate notification is created. |
| Martin submits the original form | Under the policy of rejecting stale versions, his edit does not overwrite the Monday date. |
| The client fetches the current record | It shows the saved Monday date and current version. The draft note is preserved according to the agreed rules. |
RFC 9110 describes the option to confirm an operation already applied. It does not mean every server can recognise every repeated attempt. If a client merely fetches a new ETag after an error and automatically resubmits the entire old form, it can defeat protection against overwriting someone else’s work. A new edit must follow the agreed comparison or merging rules.
Distinguish the number of attempts from the number of saved business changes. A technical log may contain several attempts, while history and notifications should reflect the actual change according to the contract. A database serialization failure requires retrying the entire transaction, including the logic that decides its steps. Even that retry does not guarantee success. Test exhaustion of the agreed retry limit and a clear outcome without a false save confirmation.
Start with a record edited by several people
Verified conflict handling reduces silent overwriting and helps users finish draft edits. The tests also provide concrete evidence for deciding whether independent changes should be merged or require fresh confirmation.
Choose one frequently edited record type. Agree on behaviour for stale versions, reproduce two edits in separate sessions and add concurrent API requests. Check saved data, messages and side effects before extending the suite to other record types.