Torid
DESCRIPTION
Temporally Ordered IDs. Generate universally unique identifiers (UUID)
that sort lexically in time order.
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:
- Fast ID generation
- No central coordinating server/system
- No local storage
- Library code, that is multiple apps on the same machine can use the same code
and they will not generate duplicate ids
- 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
require 'torid'
uuid = Torid.uuid
uuid.to_s
uuid.bytes
Using your own instance of a Generator
require 'torid'
generator = Torid::Generator.new
uuid = generator.next
uuid.to_s
uuid.bytes
CREDITS / RESOURCES
The vast majority of the credit and research stems from:
You could consider Torid to be a reimplementation of lexical_uuid. It definately steals some code from it and simple_uuid
Blog posts around ID generation:
Libraries implementing similar approaches:
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.