| You're right, not hosts or processes in that case. I forgot about random part as it's been a while since I looked at it. However, a single instance of a ULID generator must support this mode, which means that on multi-threaded architectures, it must lock the sequence as it still uses a single random value. That again, kills the purpose of a client-side, lock-free generation of universal identifiers as you said. |
| |
| ▲ | 0x457 3 days ago | parent | next [-] | | You only need to lock sequence if you care about IDs being ordered within a millisecond. That generally only matters when you create a batch of IDs at once, in that case you don't need to lock anything: generate ULID, keep incrementing sequence in that batch either by doing on the same thread, or by moving it from thread to thread. Kinda like creating an iterator and zip'ing it with iterator of thing you need IDs for. I've switched to using UUIDv7 tho. It made sense to use ULID before v7, but now ULID only has one thing going on - smaller string representation. That doesn't matter if your storage can store UUIDs natively (i.e. as 128 bit integer) If your goal is to have global order intact, then neither ULID nor UUIDv7 is going to work for you. | | |
| ▲ | sedatk 3 days ago | parent | next [-] | | > You only need to lock sequence if you care about IDs being ordered within a millisecond Yes, and that's when sequences are only used. I guess that's to avoid hogging the CPU or emptying the OS entropy pool during high loads. However, that "optimization" is a failure mode if you're not aware how ULID internals work. It's easy to shoot yourself in the foot by blindly trusting ULID will always generate a unique ID across threads without blocking your thread. That's a sneaky footgun. > That generally only matters when you create a batch of IDs at once No, any web service instance can receive requests at arbitrary times, and sometimes in the same millisecond zone. The probability is proportional to the number of concurrent users and requests. > If your goal is to have global order intact, then neither ULID nor UUIDv7 is going to work for you. Agreed. | | |
| ▲ | 0x457 13 hours ago | parent | next [-] | | > No, any web service instance can receive requests at arbitrary times, and sometimes in the same millisecond zone. The probability is proportional to the number of concurrent users and requests. Yes, but does it matter that you have out of order IDs within the same ms for concurrent requests? That's why I said batch. I only ever been an issue for me when I've chosen ULID as an ID for an event log (if the command produced more than one event, random bits will ruin the order) > However, that "optimization" is a failure mode if you're not aware how ULID internals work. That's not ULID internals, that's whatever library you're using. The rust implementation I've used, for example, will generate random bits unless you implicitly increment, and that requires `&mut` | |
| ▲ | jasonwatkinspdx 3 days ago | parent | prev [-] | | > or emptying the OS entropy pool during high loads. Just a heads up that's not really a thing. If the CSPRNG is initialized correctly you're done. There's nothing being depleted. I know for ages the linux docs said different, they were just wrong and a maintainer was keeping a weird little fiefdom over it. | | |
| ▲ | sedatk 3 days ago | parent [-] | | Thanks for the heads up, then it’s one less reason for ULID to adopt this weird behavior. |
|
| |
| ▲ | vbezhenar 3 days ago | parent | prev [-] | | I hope that's not literally incrementing a sequence. Because it would lead to trivial neighbor ID guessing attacks. I've implemented this thing, though not called it ULID. I've dedicated some bits for timestamp, some bits for counter within millisecond and rest for randomness. So they always ordered and always unpredictable. Another approach is to keep latest generated UUID and if new UUID requested within the same timestamp - generate random part until it's greater than previous one. I think that's pretty good approach as well. | | |
| ▲ | sedatk 3 days ago | parent | next [-] | | > I hope that's not literally incrementing a sequence It's literally incrementing it by one: https://github.com/ulid/javascript/blob/11c2067821ee19e4dc78... https://github.com/ulid/javascript/blob/11c2067821ee19e4dc78... | | |
| ▲ | vbezhenar 3 days ago | parent [-] | | Well, that makes little sense for me, you can just use numeric identifier instead. Bulk inserts which generate identifiers in bulk are commonly used. But that's easy to fix, so just implementation quirk for this particular library, the idea is sound. | | |
| ▲ | sedatk 3 days ago | parent [-] | | > But that's easy to fix, so just implementation quirk for this particular library, the idea is sound. It's in ULID spec. |
|
| |
| ▲ | jasonwatkinspdx 3 days ago | parent | prev [-] | | > I hope that's not literally incrementing a sequence. Because it would lead to trivial neighbor ID guessing attacks. It is and it does. Also the ULID spec suggests you use a CSPRNG, but doesn't mandate that or provide specific advice on appropriate algorithms. So in practice people may reach for whatever hash function is convenient in their project, which may just be FNV or similar with considerably weaker randomness too. |
|
| |
| ▲ | cpburns2009 3 days ago | parent | prev [-] | | If you really need lock-free generation, you can use an alternate generator that uses new random bits for every submillisecond id. That's what the `ulid-py` library for Python does by default instead of incrementing the random bits. | | |
| ▲ | sedatk 3 days ago | parent [-] | | Yes, the problem is that this mode is supported and required per the spec. So, a developer must know the pros/cons of this mode. It requires them to correctly assess the consequences. It's quite easy to shoot themsleves in the foot especially when a solid alternative like UUIDv7 exists. |
|
|