# UID Comparison ## UUID v4 The UUID that everyone knows and loves. ### Technical notes Length: 36 characters Encoding: Base16 Special characters: dashes `-` Sortable: No Collission chance: Low Availability: All languages Performance: Considered the benchmark. Not great for 1000s per second. ### Examples Generator: https://www.uuidgenerator.net/ Raw: `8a95ef8c-9ee2-4362-87ca-0c936da12e82` #### API `/v3/invoices?uid=8a95ef8c-9ee2-4362-87ca-0c936da12e82` ``` { "id": 7, "uid": "8a95ef8c-9ee2-4362-87ca-0c936da12e82", "created_at": "2011-06-08T02:29:03.000000Z", "created_by_id": 1, "modified_at": "2011-06-08T02:34:45.000000Z", "modified_by_id": 1, "number": "400007", "animal_id": 9, "animal_uid": "24c30792-233f-47fb-bc80-61dfcbe2933c" "consult_id": 5, "consult_uid": "addd6830-c51a-4bde-9681-d87ac92d39f7" "date": "2011-06-08T11:00:00.000000Z", "payment_term_id": 1, "due_date": "2011-06-08T11:00:00.000000Z", "order_number": "", "comments": "", "inc_tax": true, "sub_total_exc_tax": 1.74, "freight_method_id": null, "freight_account_id": null, "freight_exc_tax": 0, "freight_tax": 0, "freight_tax_rate_percentage": 12.5, "tax_account_id": null, "total_tax": 0.26, "total_inc_tax": 2, "paid": 2, "due": 0, "tax_rounding": 0, "tax_rounding_account_id": 9, "customer_reference": "", "ownership_id": 2, "client_contact_id": 14, "contact_uid": "ba6142fa-4349-480b-8e6c-40589201e35d" "status": "approved" } ``` #### Logs ``` [2021-12-13 15:16:37] application.INFO: [site:vsc][CRON][rVetLink] { "starttime": 1639433796, "forclass": "RVetLink", "endtime": 1639433797, "data": "entires-2", "animalsSentThrough": [ "24c30792-233f-47fb-bc80-61dfcbe2933c", "394b26a0-14d5-4a29-b5e8-4f897433d810" ] } ``` ### Type reference As this already makes use of dashes we can prepend the object reference and a dash. Animal: `animal-24c30792-233f-47fb-bc80-61dfcbe2933c` Contact: `contact-ba6142fa-4349-480b-8e6c-40589201e35d` Consult: `consult-addd6830-c51a-4bde-9681-d87ac92d39f7` Invoice: `invoice-8a95ef8c-9ee2-4362-87ca-0c936da12e82` ## Nano ID The most popular UID generator after UUID v4. Smaller than UUID in length and supposedly less chances of collission. The power of Nano is related to the flexibility. You can use it out of the box or set it up how you want. Custom character set and length is highly supported on all platforms. ### Technical notes Length: 21 characters Encoding: Base64 Special characters: dashes `-` and underscores `_` Sortable: No Collission chance: Very low Availability: Most languages Performance: At least two times faster than UUID v4 ### Examples Generator: https://nanoid.dev/ Raw: `V1StGXR8_Z5jdHi6B-myT` #### API `/v3/invoices?uid=V1StGXR8_Z5jdHi6B-myT` ``` { "id": 7, "uid": "V1StGXR8_Z5jdHi6B-myT", "created_at": "2011-06-08T02:29:03.000000Z", "created_by_id": 1, "modified_at": "2011-06-08T02:34:45.000000Z", "modified_by_id": 1, "number": "400007", "animal_id": 9, "animal_uid": "uye4dVdaER3Rivt5HDZS8" "consult_id": 5, "consult_uid": "69-rtm3ugcyGwapDo_THf" "date": "2011-06-08T11:00:00.000000Z", "payment_term_id": 1, "due_date": "2011-06-08T11:00:00.000000Z", "order_number": "", "comments": "", "inc_tax": true, "sub_total_exc_tax": 1.74, "freight_method_id": null, "freight_account_id": null, "freight_exc_tax": 0, "freight_tax": 0, "freight_tax_rate_percentage": 12.5, "tax_account_id": null, "total_tax": 0.26, "total_inc_tax": 2, "paid": 2, "due": 0, "tax_rounding": 0, "tax_rounding_account_id": 9, "customer_reference": "", "ownership_id": 2, "client_contact_id": 14, "contact_uid": "ezSaEEjLxd57pKCmMs0U7" "status": "approved" } ``` #### Logs ``` [2021-12-13 15:16:37] application.INFO: [site:vsc][CRON][rVetLink] { "starttime": 1639433796, "forclass": "RVetLink", "endtime": 1639433797, "data": "entires-2", "animalsSentThrough": [ "uye4dVdaER3Rivt5HDZS8", "zANZ8WSsuocCweYhc42On" ] } ``` ### Type reference As this already makes use of underscores we can prepend the object reference and an underscore. This will make it easier to spot and read compare to dashes. Animal: `animal_uye4dVdaER3Rivt5HDZS8` Contact: `contact_ezSaEEjLxd57pKCmMs0U7` Consult: `consult_69-rtm3ugcyGwapDo_THf` Invoice: `invoice_V1StGXR8_Z5jdHi6B-myT` ## KSUID A very mature sortable UID generator. Smaller than UUID in length and less chances of collission. The main focus for KSUID is related to the timestamp aspect built into the ID. This will allow us to see roughly when IDs were generated and may assist us in debugging. The other pull for KSUID is related to the simpler encoding character set. No special characters means it can be used anywhere that alphanumeric is supported. ### Technical notes Length: 27 characters Encoding: Base62 (numbers and letters only) Special characters: No Sortable: Yes Collission chance: Very low Availability: Most languages Performance: Built for performance ### Examples Generator: https://golang.cafe/ksuid Raw: `23cEymhbGTgWKFSW3nESOnRONSn` #### API `/v3/invoices?uid=23cEymhbGTgWKFSW3nESOnRONSn` ``` { "id": 7, "uid": "23cEymhbGTgWKFSW3nESOnRONSn", "created_at": "2011-06-08T02:29:03.000000Z", "created_by_id": 1, "modified_at": "2011-06-08T02:34:45.000000Z", "modified_by_id": 1, "number": "400007", "animal_id": 9, "animal_uid": "23cF6uTbQltw6KHJ5EtzZ6FDMN1" "consult_id": 5, "consult_uid": "23cFIiBZaQbmsO0txDLpuKky0WQ" "date": "2011-06-08T11:00:00.000000Z", "payment_term_id": 1, "due_date": "2011-06-08T11:00:00.000000Z", "order_number": "", "comments": "", "inc_tax": true, "sub_total_exc_tax": 1.74, "freight_method_id": null, "freight_account_id": null, "freight_exc_tax": 0, "freight_tax": 0, "freight_tax_rate_percentage": 12.5, "tax_account_id": null, "total_tax": 0.26, "total_inc_tax": 2, "paid": 2, "due": 0, "tax_rounding": 0, "tax_rounding_account_id": 9, "customer_reference": "", "ownership_id": 2, "client_contact_id": 14, "contact_uid": "23cFUKpmPUeJzMkhWgFrNihKmug" "status": "approved" } ``` #### Logs ``` [2021-12-13 15:16:37] application.INFO: [site:vsc][CRON][rVetLink] { "starttime": 1639433796, "forclass": "RVetLink", "endtime": 1639433797, "data": "entires-2", "animalsSentThrough": [ "23cF6uTbQltw6KHJ5EtzZ6FDMN1", "23cGIxLNeKC2oBUdV0DHuMgppm5" ] } ``` ### Type reference As this focuses on the ability to move between systems without encoding we will need to change tact. My suggestion is to use the number zero `0` as a delimiter between the alphabetic only reference name and the rest of the UID. Animal: `animal023cF6uTbQltw6KHJ5EtzZ6FDMN1` Contact: `contact023cFUKpmPUeJzMkhWgFrNihKmug` Consult: `consult023cFIiBZaQbmsO0txDLpuKky0WQ` Invoice: `invoice023cEymhbGTgWKFSW3nESOnRONSn` ## ULID Another sortable UID generator. The main draw here is the simple character encoding set and case insensitivity. It also handles generating IDs at the same milisecond. ### Technical notes Length: 26 characters Encoding: Base32 (numbers and letters only) Special characters: No Sortable: Yes Collission chance: Very low Availability: Most languages Performance: Faster than UUID ### Example Generator: https://ulidgenerator.com/ Raw: `01FSAHYA40B7D2G660T2E3HGWK` #### API `/v3/invoices?uid=01FSAHYA40B7D2G660T2E3HGWK` ``` { "id": 7, "uid": "01FSAHYA40B7D2G660T2E3HGWK", "created_at": "2011-06-08T02:29:03.000000Z", "created_by_id": 1, "modified_at": "2011-06-08T02:34:45.000000Z", "modified_by_id": 1, "number": "400007", "animal_id": 9, "animal_uid": "01FSAJMT588D5ZTS861MH6DDY7" "consult_id": 5, "consult_uid": "01FSAJNHT6B426NBQP0Z6J5THF" "date": "2011-06-08T11:00:00.000000Z", "payment_term_id": 1, "due_date": "2011-06-08T11:00:00.000000Z", "order_number": "", "comments": "", "inc_tax": true, "sub_total_exc_tax": 1.74, "freight_method_id": null, "freight_account_id": null, "freight_exc_tax": 0, "freight_tax": 0, "freight_tax_rate_percentage": 12.5, "tax_account_id": null, "total_tax": 0.26, "total_inc_tax": 2, "paid": 2, "due": 0, "tax_rounding": 0, "tax_rounding_account_id": 9, "customer_reference": "", "ownership_id": 2, "client_contact_id": 14, "contact_uid": "01FSAJNSZQSNXMHM1AHGHYB8XJ" "status": "approved" } ``` #### Logs ``` [2021-12-13 15:16:37] application.INFO: [site:vsc][CRON][rVetLink] { "starttime": 1639433796, "forclass": "RVetLink", "endtime": 1639433797, "data": "entires-2", "animalsSentThrough": [ "01FSAJMT588D5ZTS861MH6DDY7", "01FSAJS6V4KV6BR353TZZ3YMNR" ] } ``` ### Type reference As with the other low character count variants we will use a zero `0` as the type delimiter. Animal: `animal001FSAJMT588D5ZTS861MH6DDY7` Contact: `contact001FSAJNSZQSNXMHM1AHGHYB8XJ` Consult: `consult001FSAJNHT6B426NBQP0Z6J5THF` Invoice: `invoice001FSAHYA40B7D2G660T2E3HGWK` ## CUID The collission resistant ID meant to be used by a horizontally scaling system. Really designed for use from a mass of different devices. Like ULID and KSUID it has a reduced character set to be used across multiple devices without the need for further encoding. These IDS are easily identifiable as they all start with a lower case `c`. ### Technical notes Length: 25 characters Encoding: Base36 (numbers and letters only) Special characters: No Sortable: Yes Collission chance: Very low especially among vast different devices Availability: Most languages Performance: Designed for performance ### Example Generator: https://codesandbox.io/s/llm8q74pl7 Raw: `ckydcm91i0001266jzu7qx6ld` #### API `/v3/invoices?uid=ckydcm91i0001266jzu7qx6ld` ``` { "id": 7, "uid": "ckydcm91i0001266jzu7qx6ld", "created_at": "2011-06-08T02:29:03.000000Z", "created_by_id": 1, "modified_at": "2011-06-08T02:34:45.000000Z", "modified_by_id": 1, "number": "400007", "animal_id": 9, "animal_uid": "ckydcm91i0002266jgy3ir1cg" "consult_id": 5, "consult_uid": "ckydcm91i0003266j93jjdma7" "date": "2011-06-08T11:00:00.000000Z", "payment_term_id": 1, "due_date": "2011-06-08T11:00:00.000000Z", "order_number": "", "comments": "", "inc_tax": true, "sub_total_exc_tax": 1.74, "freight_method_id": null, "freight_account_id": null, "freight_exc_tax": 0, "freight_tax": 0, "freight_tax_rate_percentage": 12.5, "tax_account_id": null, "total_tax": 0.26, "total_inc_tax": 2, "paid": 2, "due": 0, "tax_rounding": 0, "tax_rounding_account_id": 9, "customer_reference": "", "ownership_id": 2, "client_contact_id": 14, "contact_uid": "ckydcm91i0004266jwfglwdhd" "status": "approved" } ``` #### Logs ``` [2021-12-13 15:16:37] application.INFO: [site:vsc][CRON][rVetLink] { "starttime": 1639433796, "forclass": "RVetLink", "endtime": 1639433797, "data": "entires-2", "animalsSentThrough": [ "ckydcm91i0002266jgy3ir1cg", "ckydcm91j000l266js0h4g9p0" ] } ``` ### Type reference As with the other low character count variants we will use a zero `0` as the type delimiter. Animal: `animal0ckydcm91i0002266jgy3ir1cg` Contact: `contact0ckydcm91i0004266jwfglwdhd` Consult: `consult0ckydcm91i0003266j93jjdma7` Invoice: `invoice0ckydcm91i0001266jzu7qx6ld`