Closed sergeyprokhorenko closed 5 months ago
- Implement a function based on a global lock (for the entire server). This is important for a microservice architecture. There is no need for either a thread-local monotonic function or a non-monotonic function without a counter.
Not sure what you mean but the way I have done it should be monotonic increasing per VM
- Add an optional formal parameter timestamp_offset (positive or negative) in milliseconds.
What would this be for?
Function generateUUIDv7 guarantees that the counter field within a timestamp increments monotonically across all function invocations in concurrently running threads and queries.
timestamp_offset
is intended to offset the generated timestamps by the appropriate value, so as not to expose the true time of UUIDv7 generation (for example, the date of the patient's visit, etc.). In many discussions on the internet, the exposure of the record creation date is discussed as a very serious disadvantage of UUIDv7 compared to bigint, along with the twice the length (128 vs. 64 bits). The timestamp offsets do not have to be the same throughout the table. The timestamp offset may change from time to time, similar to FHSS.In addition, the parameter timestamp_offset
solves the problem that it is faster to write simultaneously to several places in one table, so as not to create a write queue (it is enough to use several different timestamp offsets).
This is allowed by the RFC 9562:
Altering, Fuzzing, or Smearing: Implementations MAY alter the actual timestamp. Some examples include security considerations around providing a real-clock value within a UUID to 1) correct inaccurate clocks, 2) handle leap seconds, or 3) obtain a millisecond value by dividing by 1024 (or some other value) for performance reasons (instead of dividing a number of microseconds by 1000). This specification makes no requirement or guarantee about how close the clock value needs to be to the actual time.
Thanks. Will consider timestamp offsets.
@ryanwinchester
I would recommend:
timestamp_offset
(positive or negative) in milliseconds.