FlakeIds are problematic with clients that are powered by v8. This includes NodeJS in backend services, and most (if not all) JavaScript clients and browsers. These runtimes support 56 bit floating point numbers as opposed to the 64 bit integers FlakeId is based on.
To alleviate this, serving applications can call ToString() on a FlakeId, and serve the ID as a string to their clients. This is inherently dangerous, as the client will observe this ID to be a number, and may therefore parse it as such. This parse operation will be successful and the client will be in the possession of a number ID.
However, because this number is lacking (very important) 8 bits, it is no longer guaranteed to be unique and will sooner or later collide. This is an extremely pernicious bug that could have disastrous consequences, such as retrieving the wrong customer information from an external service, or worse.
Therefore, this PR introduces an alternate ToString() method in the form of a ToStringIdentifier() extension method, which takes the textual bytes of the FlakeId, and returns them in base64 format. This base64 identifier can then freely be passed around, similar to YouTube video IDs. They're a lot longer, though.
FlakeIds are problematic with clients that are powered by v8. This includes NodeJS in backend services, and most (if not all) JavaScript clients and browsers. These runtimes support 56 bit floating point numbers as opposed to the 64 bit integers FlakeId is based on.
To alleviate this, serving applications can call
ToString()
on a FlakeId, and serve the ID as a string to their clients. This is inherently dangerous, as the client will observe this ID to be a number, and may therefore parse it as such. This parse operation will be successful and the client will be in the possession of anumber
ID.However, because this number is lacking (very important) 8 bits, it is no longer guaranteed to be unique and will sooner or later collide. This is an extremely pernicious bug that could have disastrous consequences, such as retrieving the wrong customer information from an external service, or worse.
Therefore, this PR introduces an alternate
ToString()
method in the form of aToStringIdentifier()
extension method, which takes the textual bytes of the FlakeId, and returns them in base64 format. This base64 identifier can then freely be passed around, similar to YouTube video IDs. They're a lot longer, though.