https://github.com/copiousfreetime/torid
Temporally Ordered IDs. Generate universally unique identifiers (UUID) that sort lexically in time order.
https://github.com/copiousfreetime/torid
ruby temporal-data uuid
Last synced: 6 months ago
JSON representation
Temporally Ordered IDs. Generate universally unique identifiers (UUID) that sort lexically in time order.
- Host: GitHub
- URL: https://github.com/copiousfreetime/torid
- Owner: copiousfreetime
- License: isc
- Created: 2014-07-06T04:20:16.000Z (almost 11 years ago)
- Default Branch: main
- Last Pushed: 2024-03-07T06:13:40.000Z (about 1 year ago)
- Last Synced: 2024-11-16T23:33:49.241Z (6 months ago)
- Topics: ruby, temporal-data, uuid
- Language: Ruby
- Homepage:
- Size: 82 KB
- Stars: 27
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
## Torid
[](https://copiousfreetime.semaphoreci.com/projects/torid)
* [Homepage](https://github.com/copiousfreetime/torid/)
* [Github Project](https://github.com/copiousfreetime/torid)## DESCRIPTION
Temporally Ordered IDs. Generate universally unique identifiers (UUID)
that sort lexically in time order.## DETAILS
Torid exists to solve the problem of generating UUIDs that when ordered
lexically, they are also ordered temporally. I needed a way to generate ids for
events that are entering a system with the following criteria:1. Fast ID generation
2. No central coordinating server/system
3. No local storage
4. Library code, that is multiple apps on the same machine can use the same code
and they will not generate duplicate ids
5. Eventually stored in a UUID field in a database. So 128bit ids are totally
fine.The IDs that Torid generates are 128bit IDs made up of 2, 64bit parts.
* 64bit microsecond level UNIX timestamp
* 64bit hash of the system hostname, process id and a random value.## EXAMPLES
#### Using the defaults
```ruby
require 'torid'uuid = Torid.uuid
uuid.to_s # => "0004fda4-318e-f380-5a45-5321cd065b02"
uuid.bytes # => "\x00\x04\xFD\xA41\x8E\xF3\x80ZES!\xCD\x06[\x02"
```#### Using your own instance of a Generator
```ruby
require 'torid'generator = Torid::Generator.new
uuid = generator.nextuuid.to_s # => "0004fda4-3f42-3d01-4731-5a4aa8ddd6c3"
uuid.bytes # => "\x00\x04\xFD\xA4?B=\x01G1ZJ\xA8\xDD\xD6\xC3"
```## CREDITS / RESOURCES
The vast majority of the credit and research stems from:
* [jondot's](https://github.com/jondot) blog post on [Fast ID Generation](http://blog.paracode.com/2012/04/16/fast-id-generation-part-1/) served to solidify my thoughts on the criteria I needed in an ID generation system.
* This let me to [Boundary's Flake](http://boundary.com/blog/2012/01/12/flake-a-decentralized-k-ordered-unique-id-generator-in-erlang/)
* [James Golick's](https://github.com/jamesgolick) [lexical_uuid](https://github.com/jamesgolick/lexical_uuid), which if I had found a day earlier, I might be using instead of creating this.You could consider Torid to be a reimplementation of [lexical_uuid](https://github.com/jamesgolick/lexical_uuid). It definately steals some code from it and [simple_uuid](https://github.com/cassandra-rb/simple_uuid)
Blog posts around ID generation:
* [Wikipedia UUID](http://en.wikipedia.org/wiki/Universally_unique_identifier)
* [RFC 4122](http://tools.ietf.org/html/rfc4122)
* [Fast ID Generation Part I](http://blog.paracode.com/2012/04/16/fast-id-generation-part-1/)
* [Boundary's Flake Project](http://boundary.com/blog/2012/01/12/flake-a-decentralized-k-ordered-unique-id-generator-in-erlang/)
* [Flickr's Ticket Server](http://code.flickr.net/2010/02/08/ticket-servers-distributed-unique-primary-keys-on-the-cheap/)
* [Twitter Snowflake](https://blog.twitter.com/2010/announcing-snowflake)
* [Sharding & ID's at Instagram](http://instagram-engineering.tumblr.com/post/10853187575/sharding-ids-at-instagram)Libraries implementing similar approaches:
* [simple_uuid](https://github.com/cassandra-rb/simple_uuid)
* [uuid](https://github.com/assaf/uuid)
* [flake](http://github.com/boundary/flake)
* [BSON Object ID](https://github.com/mongodb/bson-ruby/blob/master/lib/bson/object_id.rb) and in [C](https://github.com/mongodb/bson-ruby/blob/master/ext/bson/native.c)
* [ffi-uuid](https://github.com/mmullis/ffi-uuid)
* [lexical_uuid](https://github.com/jamesgolick/lexical_uuid)## ISC LICENSE
http://opensource.org/licenses/isc-license.txt
Copyright (c) 2014 Jeremy Hinegardner
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice
and this permission notice appear in all copies.THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.