Search code examples
serverclientguid

Who must generate identifiers for new entities?


I've been working as iOS developer for more than 4 years and I've done some other platforms and practised .net. A few days ago I had an argument about who must generate identifier for a newly created entity - client or server?

There is a client-server app, and client sends create request with 'name', 'description' and other stuff. But server-side guy says that I also have to generate GUID and send it over in this entity.

I don't see a big problem in generating GUID but I am just not sure it's right to put that responsibility on a client side.

Any thoughts? Maybe pros and cons?


Solution

  • UUIDs being universally unique means that it doesn't matter who generates them, even if there are multiple parties not talking to each other in real time—or at all.

    This enables scenarios such as clients creating and using UUIDs offline (perhaps even multiple objects referring to each other) and then uploading them later without any concern about collisions. Whether this is "right" is a matter of opinion and may depend on the specifics of your application, but it is certainly a valid pattern.