3 ms·
Why would you let the client generate the IDs? If you have to check them anyways, just generate them on the server and only give the ID to the client.
by echoangle 3y ago
Why would you let the client generate the IDs? If you have to check them anyways, just generate them on the server and only give the ID to the client.
- kevincox 3y agoIt can be very useful for offline work and latency hiding. For example the client can generate data structures with the final IDs then sync them to the server. This can also be useful for implementing idempotent updates. The alternative of having some sort of "placeholder ID" until the sever gets back to you (or you get back online) adds a lot of client complexity.
- echoangle 3y agoCan't you just give the client a list of generated IDs on the first request and check if the IDs are from the pregenerated IDs afterwards? That should be a lot cheaper than checking all IDs you ever generated.
- kevincox 3y agoYou can do that I suppose. But I have found that in most cases I have a unique index on the ID anyways, as they are often table primary keys. So really I just have to ensure that it is either an INSERT or an UPDATE to a record that is owned by the user.
- echoangle 3y agoThen you don't really have the problem this is about though, and which UUIDs are supposed to solve. The real pro of UUIDs is that you can issue them in distributed situations where you can't look up the already used IDs easily.