I saw a tweet about an interview question that sounded simple. How would you handle two people writing to the same data in a database?
People were debating whether to add a version column or use an updated_at timestamp. My first thought was to use PATCH. If each person sends only the field they changed, why would one save erase the other?
I still think PATCH is a good answer for one version of the question. The example that changed my mind was two people editing the same field.
Where my PATCH idea works
Imagine two dispatchers open the same trip in their browsers. One changes the pickup note. The other changes the driver. If both browsers submit the entire trip from their original copies, the second save could restore the old pickup note while changing the driver. Both requests succeed, and the first dispatcher’s edit disappears. That’s a lost update.
With a partial update, the first browser sends only the new pickup note and the second sends only the new driver. If the server writes only the supplied columns and those changes can safely coexist, both edits survive. That last part matters. A PATCH endpoint that reconstructs the whole row from an earlier read can still overwrite a concurrent change. RFC 5789 on HTTP PATCH
What if both people edit the pickup note?
Now imagine both dispatchers start with the note “Meet at the main gate.” One changes it to “Meet at the east gate.” The other, working from the same original note, changes it to “Meet at reception.”
Each request updates exactly one field. Both edits still collide. If the server accepts both unconditionally, the last write wins, and the first dispatcher gets no indication that their instruction was replaced.
That was the gap in my interview answer. I’d decided how much data each request should write. I still needed to decide what should happen when the data had changed since the user opened the form.
What a version or timestamp actually does
Suppose both dispatchers read version 7 of the trip. I’d have each save include the version it started from. The database can check that version and apply the edit in a single statement:
sqlUPDATE tripsSET pickup_note = $1,version = version + 1WHERE id = $2AND version = $3RETURNING version;
The first save changes version 7 to 8. The second still expects 7, so the statement updates zero rows. For an existing trip, the API can surface the conflict and let the dispatcher review the current note before deciding what to save. A separate read followed by an unconditional write would leave a window for another edit between those two steps. At the HTTP layer, I can send a strong ETag when the client reads the trip and require If-Match on the PATCH. If that precondition fails, the server can return 412 Precondition Failed. PostgreSQL transaction isolation · RFC 9110 on If-Match
An updated_at value can serve the same role if the write compares it atomically and every relevant edit produces a distinct value. If two edits can receive the same timestamp at the stored precision, the check can miss a change. I’d reach for an integer version when I just need a reliable revision token, and keep updated_at for showing when the trip was last edited.
How I’d answer the interview question now
I’d ask what happens if both edits are allowed to land. For independent fields, targeted writes can preserve both changes. For edits that depend on the version the user saw, I’d use a conditional write. A row-level version can also reject two edits to different fields, so I’d decide whether the entire trip should be treated as one unit before choosing that policy.
There’s another case I’d call out. If both people are incrementing a counter, I’d send the operation and let the database run SET count = count + 1. If the counter starts at 10, two increments should make it 12. Two clients reading 10 and each PATCHing it to 11 lose one of those increments. PostgreSQL transaction isolation
I went into the thread thinking about the shape of the request. I came away thinking about the intent behind the write. Change this one field, save this edit if the data still matches what I saw, and add one to the current value are three different instructions. I’d make the API and the database preserve whichever one the user actually meant.

