primary key - Why can't I trust a client-generated GUID? Does treating the PK as a composite of client-GUID and a server-GUID solve anything? -


i'm building off of a previous discussion had jon skeet.

the gist of scenario follows:

  • client application has ability create new 'playlistitem' objects need persisted in database.
  • use case requires playlistitem created in such way client not have wait on response server before displaying playlistitem.
  • client generates uuid playlistitem, shows playlistitem in client , issue save command server.

at point, understand bad practice use uuid generated client object's pk in database. reason malicious user modify generated uuid , force pk collisions on db.

to mitigate damages incurred forcing pk collision on playlistitem, chose define pk composite of 2 ids - client-generated uuid , server-generated guid. server-generated guid playlistitem's playlist's id.

now, have been using solution while, don't understand why/believe solution better trusting client id. if user able force pk collison user's playlistitem objects think should assume provide user's playlistid. still force collisons.

so... yeah. what's proper way of doing this? allow client create uuid, server gives thumbs up/down when saved. if collision found, revert client changes , notify of collison detected?

a nice solution following: quote sam newman's "building microservices":

the calling system post batchrequest, perhaps passing in location file can placed data. customer service return http 202 response code, indicating request accepted, has not yet been processed. calling system poll resource waiting until retrieves 201 created indicating request has been fulfilled

so in case, post server response "i save playlistitem , promise id one". client (and user) can continue while server (maybe not api, background processor got message api) takes time process, validate , other, possibly heavy logic until saves entity. stated, api can provide endpoint status of request, , client can poll , act accordingly in case of error.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -