Container Image Reference
A library for using and handling Typed Object IDs.
About
An Object ID (OID) is a base32hex (which is base32 with the extended hex
alphabet; see RFC4648 for details) encoded UUID. The UUID is either v4
(random) or v7 (based on UNIX Epoch; see [draft RFC4122v17] for details) - this
library further qualifies the OID with a "type" which is a short alphanumeric
prefix separated from the OID by a -
. This library refers to Typed OIDs as
TOIDs which are distinct from the OID counterparts which lack the "type"
prefix.
For example EXA-4GKFGPRVND4QT3PDR90PDKF66O
, by convention the prefix is three
ASCII characters, however that is not a hard constraint of TOIDs in general.
The Pitch
TOIDs allow a "human readable subject line" in the form of the prefix, where actual data is a UUIDv7. This means while debugging or reviewing a system it's trivial to determine if an incorrect TOID was passed in a particular location by looking at the prefix. This isn't achievable with bare UUIDs or GUIDs due to their lacking of any typed identifiers.
In other words, without using TOIDs it's far too easy to incorrectly swap say a
UserID
with an OrderID
if they are both just simple GUIDs. Where as a TOID
would make the mistake more easily identifiable or even programmatically
impossible.
Base32hex encoding the UUID also allows compressing the data into a smaller and more familiar format for humans, akin to a commit hash. Using the "extended hex encoding" adds the additional property that the encodings do not lose their sort order when compared bitwise.
Finally, using a UUIDv7 enables index locality when used as database entries.
The Anti-Pitch
The downside to TOIDs is a layer of indirection when handling IDs and values, it's not immediately obvious that the TOIDs are a prefixed UUIDv7. Additionally, the prefixes themselves must be controlled in some manner including migrated on changes which adds a layer of complexity at the application layer.
There is also additional processing overhead compared to a bare UUID in order to encode/decode as well as handling the appending and removing the prefixes.
However, we believe the drawbacks pale in comparison to the benefits derived from the format.
Example
use ;
use Uuid;
use Result;
Minimum Supported Rust Version (MSRV)
The MSRV depends on which crate features are enabled:
Feature | MSRV |
---|---|
uuid_4 |
1.60.0 |
uuid_7 |
1.60.0 |
serde |
1.60.0 |
surrealdb |
1.75.0 |
License
This project is dual licensed under the terms of either the Apache License, Version 2.0, LICENSE-APACHE or MIT LICENSE-MIT at your option.
typed-oid
was originally forked from seaplane-oid
v0.4.0
which was licensed under the Apache License, Version 2.0.