Randy is a microservice to generate truly random ID across multiple hosts, or clusters. It does not use any database to store generated numbers, instead it generates IDs algorithmically.
-
High-Performance - ables to generate thousands of random IDs per second.
-
High-Scalability - allows to run multiple Randy instances on single host (using different ports), multiple hosts and multiple clusters.
-
No centralized database - common solutions are based on having some kind of centralized database (e.g. Redis). As database could be an another SPOF or point that is not so easy to scale or maintain, the goal was to avoid it. Randy stores it's state in process memory and files (used only in process initialization).
-
Uniqueness of generated IDs - Randy ensures that every generated ID is unique due to the algorithm and pattern of the generated IDs.
Running Randy is as easy as:
$ git clone [email protected]:scalebeat/randy.git
$ cd randy
$ go build
$ ./randy -port 8080 -hash raw
2016/12/11 13:38:08 Randy initialized, running on port 8080
Note: You can choose hash algo of: raw, md5, sha256 or sha512 - it will be used to hash the final id.
Keep in mind that you should never use "raw" in production as it will expose your hostname and port on which Randy is running.
Now you can try it by running:
$ curl -i http://localhost:8080/
HTTP/1.1 200 OK
Date: Sun, 11 Dec 2016 12:37:15 GMT
Content-Length: 48
Content-Type: text/plain; charset=utf-8
1481535453344192624:16:17:localhost:8080
You can easily run performance test by using Apache Benchmark. Sample test result from a very low-end setup (VPS with 1 vCore 2,4 GHz 2 GB RAM):
$ ab -n 5000 -c 800 http://localhost:8080/
...
Requests per second: 5422.84 [#/sec] (mean)
Time per request: 147.524 [ms] (mean)
Time per request: 0.184 [ms] (mean, across all concurrent requests)
Copyright (c) 2016, Antoni Orfin - Scalebeat. Licensed under the BSD 3-Clause