TID spec details #1160
Replies: 3 comments
-
https://github.com/bluesky-social/atproto/blob/main/packages/common/src/tid.ts TID
The JavaScript run time gives milliseconds not microseconds. So we pad with 0s. The time stamp part of the TID needs to be monotonicity increasing. So if we need a new TID and the clock has not ticked we add 1
For a given PDS or client we want to have a monotonicity increasing ID. However what do you do if a committer has no clock ID assigned to them. We need a way to say this is a clock that is not persistenting it's last_timestamp and risks collision or regression. The clock ID space has been partitioned as such.
TTTT-TTT-TTTT-CC The string form sorts in the same order as the int64 form The repo should contain a record mapping Clock IDs to the keys of clients that commit to the repo and thus need to be able to generate repo unique TIDs offline. |
Beta Was this translation helpful? Give feedback.
-
What about byte order, can we assume network byte order (big-endian)? I assume so based on the clock ID coming last in the TID. |
Beta Was this translation helpful? Give feedback.
-
TIDs are now documented in the Record Key specs: https://atproto.com/specs/record-key#record-key-type-tid |
Beta Was this translation helpful? Give feedback.
-
The current docs for at:// URIs indicate that record-id (aka TID, aka rkey) can be arbitrarily long or short. In the examples, they are shown and described as something similar to a twitter snowflake ID: a numerical timestamp, sub-millisecond counter, and "clock identifier".
There are some more details in the current Javascript source code, but a few things are ambiguous. My understanding of how to generate a TID is:
From a standardization standpoint, it would make more sense to me to implement this as a 64-bit unsigned integer, with specific slices having meaning. AKA, timestamp is 49 bits, counter is 10 bits, clock ID is 5 bits. mask and shift these bits in to place, resulting in a uint64, then encode that with a specified byteorder as base32sortable. Potentially even better would be just using twitter snowflakes themselves, as there are already several implementations.
A couple other detail questions:
Beta Was this translation helpful? Give feedback.
All reactions