• (nodebb)

    Awkwardly and inefficiently and with a high probability of collisions due to bad randomness

    I would argue that this is a good example of "doesn't work" (especially the "high probability of collisions" part), and yet the article says that it does work...

    But then again:

    1. Why did it take until 2021 for JS to sprout a random-UUID function?

    2. Why would we want to generate UUIDs in the browser rather than in the server code? (The WTF-ness of this question may explain why it took so long...)

  • Hanzito (unregistered)
    1. The probability of collisions is very low. The built-in random functions are really good enough.

    2. It's just a random id, nothing else. You can't send a 128 bit number in a url or json, so formatting it as a uuid is probably fine.

    3. Nobody cares about the meta data in uuid, unless you mix different types (and I can't think of a reason why you ever would, although there's probably someone here who knows an obscure use case), but this code even takes that into account.

  • (nodebb) in reply to Steve_The_Cynic

    "Why would we want to generate UUIDs in the browser rather than in the server code?"

    Some APIs require that the client generates the id of a newly created resource. It's bad, but at least someone else is to blame for it.

  • (nodebb) in reply to Steve_The_Cynic

    Why would we want to generate UUIDs in the browser rather than in the server code? (The WTF-ness of this question may explain why it took so long...)

    CQRS

    When you have strict query/command separation, you don't really have return value(s) with your write operations. So if you want to create a new resource, you have to provide a unique identifier to find you resource again.

  • Jim Jam (unregistered) in reply to Melissa U

    It is not bad at all when a UUID is used as an idempotency key, as to prevent creating duplicates on network hiccup.

  • Industrial Automation Engineer (unregistered)

    the "4" in the string is the type of the identifier.

  • (nodebb)

    The proper thing to do is check whether crypto.randomUUID exists and use this only as a fallback.

Leave a comment on “Uniquely Expressed”

Log In or post as a guest

Replying to comment #:

« Return to Article