UUIDv7 doesn't have the properties you think it does

(alexsci.com)

39 points | by ibobev 1 hour ago

12 comments

  • hackingonempty 26 minutes ago
    > If you need to list things ordered by creation time very often, it’s useful if the primary index gives that behavior, removing the need for another index.

    I thought the main reason UUIDv7 was created with a time component is to keep temporally related rows together in the index pages. Randomly distributed row ids seem OK until the entire index no longer fits in RAM.

  • nitwit005 4 minutes ago
    The Python version simply forces the timestamp forward if needed to preserve ordering:

      if timestamp_ms < _last_timestamp_v7:
        timestamp_ms = _last_timestamp_v7 + 1
    
    https://github.com/python/cpython/blob/8d119208074fef0f652f1...

    But if you did want "monotonically increasing IDs", as the article suggests, that is what you want.

  • skrebbel 22 minutes ago
    I feel like this article way downplays the entire point of UUIDv7s, which is that it lets you sort (and store!) your data kinda sorta by creation time, no overlap ever. That's great for cursors, for streaming data, for twitter clones, for chat messages, for player moves, and so on and so forth. Nearly everything that's vaguely realtimey that you might like to both persist and broadcast live to other clients, and displayed in a stable & reasonable order, benefits from a property like this.

    In fairness, he does mention this, but squeezes it into a single sentence near the end. But eg the fact that you can't reliably extract the precise timestamp from the UUIDv7 is a feature, not a bug. It's either that or collisions and you don't want the collisions.

    • roughly 5 minutes ago
      Yeah, I think the key here is that you have to know what the limitations are. UUIDv7 does _not_ provide you with sorted and ordered IDs by creation time, it provides you with _kinda sorta_ sorted and ordered IDs by creation time. That's probably fine for a lot of use cases, but if it's not OK for yours (forensic accounting, risk mitigation for banks, whatever), you can't use it for that. You're right it's not a technical problem necessarily, but when the marketing material describes something without an asterisk, people who are unaware that what's being described is impossible at the limits can make bad system design decisions based on that promise.
  • sedatk 40 minutes ago
    You probably don't need a UUID: https://ssg.dev/you-probably-dont-need-a-uuid/
    • kune 14 minutes ago
      I support this. I wrote a Sqlite plugin for KSUIDs, but at the end I never used them, since all I do can be handled by integer primary keys, which sqlite maps to the rowid automatically. Autoincrement is only required, if you want to prevent the reuse of ids in deleted rows.
  • 0x20cowboy 19 minutes ago
    As others have said, I don’t think the time was meant to be something you relied on for the object time, but more the help with indexing and sharding.
  • jefecoon 38 minutes ago
    Great article.

    I assume I'm oblivious and naive, but it seems theoretically possible these issues could -- theoretically -- result in TOCTOU or similar issues.

    Any thoughts about relying on:

    - central time service, with message-queue of inbound requests, resulting in correctly timed + sequenced events [ albeit with hopefully small lag tradeoffs ]?

    - know of any databases that implement this type of logic around their own minting of time-stamped UUIDs?

    Prior efforts implementing event-driven backend service with UUID7s minted in client-code seemed perfectly fine at low usage/scale. However, as clients + usage + event-volume scaled, team became more curious about time/timestamp/related issues, and any minting client-side quickly fell out of favor.

    Any insights greatly appreciated -- thanks

    [ edited b/c i don't know how to format... ]

  • phoronixrly 30 minutes ago
    Wow... That is some nitpicking... The major issue these UUIDs solve for me is the fact that using a random UUID as a primary key of a relational database leads to horrible performance...

    It has never crossed my mind to decode the timestamp from them so I save myself a 12-byte column, neither has it crossed my mind to have them monotonic in a distributed system...

  • ForHackernews 21 minutes ago
    Most (all?) of these are also true of UUIDv1. Devs in 2026 should be well versed in using UUIDv4 if they really truly can never leak anything.
  • pphysch 47 minutes ago
    > My mental model for UUIDv7 is that it’s a mash-up of a bunch of different ideas which implementations are free to choose as they see fit. There’s a wide variance of properties that UUIDv7 implementations can provide, with varying degrees of certainty they can successfully provide those properties.

    I think this is good. A proper UUID that has specific significant bits dedicated to (approximately) monotonic values is useful. I don't want it over-specified beyond that, and I don't want to just use UUIDv8.

  • doormatt 44 minutes ago
    [dead]
  • Vaushite 51 minutes ago
    [dead]
  • saagarjha 34 minutes ago
    Just use UUIDs as they were meant to be used, as a random identifier. Don't shove random other junk into it!