3 ms·
What database support is needed? Assuming Postgres already has the uuid type and that you can (and often should) do the actual generation of them in application
by klabb3 2y ago
What database support is needed? Assuming Postgres already has the uuid type and that you can (and often should) do the actual generation of them in application code?
- tyre 2y agoWhy should they be done in application code?
- eproxus 2y agoThere’s no need since they are random, so you might as well generate them on your application servers which are easier to scale, to offload the write database.
- bozey07 2y agoIMO marking the row as generated makes its intent clearer. It also means less code - no generating UUIDs, shorter queries = more robust. For my workloads at least, I think it's worth the tradeoff of forcing Postgres to muster 15 random bytes.
- deleted 2y ago[deleted]
- sbuttgereit 2y ago> you can (and often should) do the actual generation of them in application code I can absolutely see scenarios where it would be desirable or convenient to create the these IDs in the application code. However, I can equally assert that you can, and often should, let the database be the source of truth for record identity when using database surrogate keys for that purpose... but I won't. The truth is there are many kinds of architectures and many kinds of applications the details of which have a direct bearing on where or where not certain operations should be conducted. In many environments in which I work, the idea of "the application" can be murky. In many enterprise environments databases can be driven by and integrated into many applications, possibly from different software developers and vendors with varying degrees of influence in how they internally operate. In such environments the database can be the great unifier and placing substantial control of data in the database itself can make sense in these heterogenous application environments: but it's very much a circumstantial call. I would expect if there really were one true way to develop application or how to use databases to achieve goals, we could well be asking why they built these functions in the first place... I suspect it's because there are a reasonable number of valid use cases to justify the lift. I'd like to think my use cases fit the envisioned valid use cases thus my interest and question.
- klabb3 2y ago> I can absolutely see scenarios where it would be desirable or convenient to create the these IDs in the application code. I feel like I’m taking crazy pills. Isn’t the whole (or 99% of the) point of uuids that you can generate them client/application side for idempotency, because entity creation starts there and you want an id earlier than the first round trip completion? If they’re generated by the db (with world-knowledge) then you can auto increment a 64 bit is significantly more performant.