(no title)
biaachmonkie | 3 years ago
GET: {version: 1, field: [1,2,3]}
PATCH: {version: 1, field: [1,2,3,4]} # succeeds
PATCH: {version: 1, field: [1,2,3,5]} # fails with HTTP 409 response
# Client displays some sort of warning that the update failed, GETs the object again and merges the new state from the server with it's state and can retry the update
GET: {version: 2, field: [1,2,3,4]}
PATCH: {version: 2, field: [1,2,3,4,5]} # succeeds
zepolen|3 years ago
Likewise the moment you start to do this architecture is the moment you fail to scale. You're putting unnecessary load on your backend by forcing the client to refetch the resource in order to make another update, not to mention the scenario where a lot of clients are trying to add items to field
> GETs the object again and merges the new state from the server
At some critical point all those clients will start blocking each other as they constantly make PATCHes that fail and reGET only to fail again because another client managed to make their PATCH before them. The problem made worse by network latency and app code.
Patches that work with changesets will support a much higher concurrent write load as the concurrency/serialization is done server side, and the changesets will be small rather than the entire value. Under load all the individual requests may take longer to complete they will all ultimately succeed. Concurrency conflicts may still occur but they will be a couple orders of magnitude less frequent.
Depending on the type of update, eg. adding items to a list, this is what you want. Removing / updating values otoh may be classed as something you'd prefer to have constraint check via If- headers.