3 ms·
Discord uses snowflake based IDs to great success. It's actually been one of the rock solid parts of our infrastructure and the fact that time stamps are embedd
by jhgg 6y ago
Discord uses snowflake based IDs to great success. It's actually been one of the rock solid parts of our infrastructure and the fact that time stamps are embedded in the ID are great. Every channel, message, stream, attachment, user, server, etc... gets a snowflake.
We originally wrote this service in Elixir but have since rewritten it in rust. Actually very similar to this crate. Maybe I should open source ours too haha.
- Dowwie 6y agoDid you see the flake crate?
- jhgg 6y agoThe one that says "wip; use at your own risk" with no updates in the last 5 years? Or is there another? https://crates.io/crates/flake https://crates.io/crates/flake
- Dowwie 6y agosorry, missed the N at the end -- I refer to "flaken": https://crates.io/crates/flaken https://crates.io/crates/flaken snowflake libraries generally aren't updated after they're stabilized
- jhgg 6y agoNo I didn't but after looking at it it looks like its implementation falls short. - it only looks at system time at system startup, then relies on instant for monotonic clock source. unfortunately for setups that do leap-second smearing (ours does), this would deviate slightly out of sync after operating for a while. - does not handle seq overflow within a given millisecond window - this i think is very unsafe, and can cause the generation of duplicate IDs if `next_id` is called at too rapid an interval.