u/Giovanni_Cb

▲ 5 r/dotnet

Optimistic concurrency with rowversion — how to handle multiple API calls before Save?

I have a form that loads multiple records and reads the table rowversion. While the user is still on the form, they can call other APIs (add attachment, add certificate, etc.) that internally update the same record and therefore change its rowversion.

When the user finally hits Save and sends the original rowversion, the server rejects it with a concurrency conflict even though no other user touched the record.

What is the correct pattern to handle this? Is it normal to return the updated rowversion after every intermediate API call and have the client track it, or is there a better approach?

Thanks

reddit.com
u/Giovanni_Cb — 8 days ago
▲ 24 r/dotnet

Hey, I'm building a Flutter app that works offline and syncs to an ASP.NET Core Web API when connectivity is restored. The app is for a pretty critical use case so I want to get the sync architecture right.

Here's what I'm thinking:

- On the device, pending operations are stored in a local SQLite DB with the intent type, payload, rowVersion, and timestamp

- When the device comes back online, it POSTs all pending ops to a dedicated `/sync` endpoint

- Each operation is dispatched in chronological order — if one conflicts (rowVersion mismatch), the queue stops there and the client gets back a conflict code + the current server rowVersion

A few things I'm not 100% sure about:

  1. Is a dedicated sync endpoint the right call, or is it cleaner to just replay individual requests against existing endpoints?

  2. Is `sp_getapplock` a reasonable mutex here or is there a better pattern for SQL Server?

  3. How are you handling partial queue failures — do you let the user resolve conflicts manually or do you try to auto-merge?

  4. Any experience with this in high-latency / unreliable network environments ?

Would love to hear how others have tackled this, especially if you've dealt with multi-device concurrency on the same record. Thanks

u/Giovanni_Cb — 17 days ago