I've tried to generate 10k integer from Go's UnixNano, and it doesn't show any collision.
package main import ( "fmt" "sync" "time" "strconv" "github.com/OneOfOne/cmap" ) func main() { var wg sync.WaitGroup k := 1000 wg.Add(k * 1000) coll := cmap.New() for z := 0; z < k*1000; z++ { go func() { k := strconv.FormatInt(time.Now().UnixNano(),36) if coll.Has(k) { fmt.Println(`collision: `, k) } coll.Set(k,true) defer wg.Done() }() } wg.Wait() } The database only support 64-bit integer at maximum and doesn't support atomic counter/serial.
EDIT 2017-03-06 It has collision
collision: bb70elvagvqu collision: bb70elwbgk98 collision: bb70elwnxcm7 So if I create a primary key using that number, converted to base-36, appended with 3 digit server key would it be no possible collision right?
Some example:
0bb4snonc8nfc001 (current time, 1st server) 1y2p0ij32e8e7zzz (maximum value: 2262-04-11 23:47:16.854775807, 46654th/last server) Requirement 2017-03-04
- Lexicographically correct
- Unique
- As short as possible
- Ordered by creation time