4 ms·
> Encourages uuids generated client-side. Is there an actual problem with this? I don't mean "it feels impure" - what's the failure case here that's severe eno
by danielheath 4y ago
> Encourages uuids generated client-side.
Is there an actual problem with this? I don't mean "it feels impure" - what's the failure case here that's severe enough to discard UUIDs as PKs?
The other reasons all boil down to 'database performance tuning', which is reasonable if you have any prospect of needing it, but most datasets are _tiny_.
- srcreigh 4y agoThe other reasons are more important imo, and they aren’t really all tuning more ergonomics and simplicity. There’s a lot more edge cases when you use client-side generated IDs. You have to check if the ID is actually new to avoid security issues is the main one. Let’s just upsert into the DB and return the results and the uuid is new and randomly generated so it’s fine! So simple! Except now Alice can send someone else’s uuid and read their data. X100 endpoints all need to handle this correctly. It’s a huge risk. If you do offline first ID generation using global uuids, the possibility of conflicts (due to bugs, patched client code, etc) that’s a whole rabbit hole of edge cases and problems as well. It can be done, Bret Taylor used that architecture for quip, but it’s needlessly tricky which is the whole story for UUIDs imo - annoying and slightly worse for many normal apps. If you’re building a complex distributed system and want to deal with all the trickiness, go ahead. I’d recommend you use a B64 custom identifier instead of UUID so that it’s copy paste able :-)
- stickfigure 4y ago>> Encourages uuids generated client-side. >Is there an actual problem with this? The nature of your application and its security and idempotence needs will determine who should (ideally) generate ids for any specific context. The format is irrelevant. Generate ids on the client when it makes sense, generate them on the server when it makes sense. Server-side is more common but if you choose poorly you'll make bad software either way.