-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.html
449 lines (387 loc) · 10.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
<html>
<head>
<title>🔑 Awesome Identifiers</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="p-4">
<div class="p-4 flex justify-between bg-green-100 rounded items-center">
<div>
<h1 class="text-xl font-bold">🔑 Awesome Identifiers</h1>
<p>Pick the best database primary key</p>
</div>
<div class="text-right">
<div class="pb-2"><a class="text-blue-600 dark:text-blue-500 hover:underline" href="https://github.com/adileo/awesome-identifiers"><svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="inline-block w-4 h-4">
<path stroke-linecap="round" stroke-linejoin="round" d="M13.19 8.688a4.5 4.5 0 011.242 7.244l-4.5 4.5a4.5 4.5 0 01-6.364-6.364l1.757-1.757m13.35-.622l1.757-1.757a4.5 4.5 0 00-6.364-6.364l-4.5 4.5a4.5 4.5 0 001.242 7.244" />
</svg>@adileo/awesome-identifiers</a></div>
<a class="github-button" href="https://github.com/adileo/awesome-identifiers" data-size="large" data-show-count="true" aria-label="Star adileo/awesome-identifiers on GitHub">Star</a>
</div>
</div>
<style>
td{
padding: 0.6em;
text-align: center;
}
tr>td:nth-child(1){
text-align: left;
}
</style>
<table class="mt-8 text-xs">
<thead>
<tr class="bg-green-400 sticky top-0">
<th></th>
<th>SERIES (aka INT)</th>
<th>BIGSERIES (aka BIGINT)</th>
<th>Snowflake ID</th>
<th>Sonyflake</th>
<th>CUID</th>
<th>nanoId</th>
<th>xid</th>
<th>ULID</th>
<th>UUIDv4</th>
<th>UUIDv1</th>
</tr>
</thead>
<tbody>
<tr class="bg-green-100">
<td>Best for</td>
<td>Lightweight and fast PK, easy to read, ideal when you don't have a distributed system.</td>
<td>Like SERIES but allow up to 2^64 (Quadrillion) records, still not ideal for a distributed system.</td>
<td>Same performance of BIGSERIES with the plus of supporting a distributed system by dedicating some bits to sharding and sequencing.</td>
<td>Inspired by Snowflake ID, longer timestamp lifetime despite the resolution of 10ms, works on more distributed machines 2^16 than snowflake 2^10.</td>
<td>Similiar to xid but larger in terms of bits footprint in favor of a better timestamp resolution of 1ms.</td>
<td>Completly random string, works well in a distributed system, useful for public facing identifiers since it's a completly opaque token. Not useful for sorting or pagination, not K-ordered. Thereafter not ideal as a database PK.</td>
<td>Inspired by the Mongo Object ID, but shorter in terms of chars, 20 vs 24. XID is Sortable and works well in a distributed system. Smaller binary size than UUID or ULID could improve performance on huge databases. Timestamp resolution of 1 second.</td>
<td>Like UUIDv4 but lexicographically sortable and without the ugly dashes. It supports generating up to 1.21e+24 unique ULIDs per millisecond. Thanks to the large number of bits of randomness it works also well in a distributed system.</td>
<td>The most famous identifier, not sortable, completly random generated so it works well with distributed system. It's a completly opque identifier like nanoid, less compact than ULID due to the hexadecimal representation separated by the dashes. </td>
<td>Even if encoding the timestamp within it, UUIDv1 is not lexicographically sortable. Since it uses the MAC address it allows to quickly discern which IDs are generated by a single machine.</td>
</tr>
<tr class="bg-green-300">
<td>General Specification</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Example</td>
<td>13</td>
<td>120310392</td>
<td>1584093427933380608</td>
<td></td>
<td>cjld2cjxh0000qzrmn831i7rn</td>
<td>V1StGXR8_Z5jdHi6B-myT</td>
<td>9m4e2mr0ui3e8a215n4g</td>
<td>01arz3ndektsv4rrffq69g5fav</td>
<td>fa23bd22-a5ac-46c2-8a67-bda88ca3e6e4</td>
<td>e6a21b7c-5c2f-11ed-9b6a-0242ac120002</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Number Range</td>
<td>0 - 4,294,967,295</td>
<td>0 - 18,446,744,073,709,551,615</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Numbers of bit</td>
<td>32</td>
<td>64</td>
<td>64</td>
<td>64</td>
<td>200</td>
<td>variable</td>
<td>96</td>
<td>128</td>
<td>128</td>
<td>128</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>GB needed to store 1 Billion Keys</td>
<td>4GB</td>
<td>8GB</td>
<td>8GB</td>
<td>8GB</td>
<td>25GB</td>
<td>variable</td>
<td>12GB</td>
<td>16GB</td>
<td>16GB</td>
<td>16GB</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Numbers of characters</td>
<td>0 - 10</td>
<td>0 - 20</td>
<td>19</td>
<td></td>
<td>25</td>
<td>variable</td>
<td>20</td>
<td>32</td>
<td>36</td>
<td>36</td>
</tr>
<tr class="bg-green-300">
<td>DB Specification</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<trc class="even:bg-green-50 odd:bg-green-100">
<td>Suggested DB Type</td>
<td>INT</td>
<td>BIGINT</td>
<td>BIGINT</td>
<td>BIGINT</td>
<td>VARCHAR(25)</td>
<td>VARCHAR(X)</td>
<td>VARCHAR(20)</td>
<td>VARCHAR(32)/UUID</td>
<td>UUID</td>
<td>UUID</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Performance impact on Database (eg. Storage, JOIN operations, etc...)</td>
<td>very low</td>
<td>low</td>
<td>low</td>
<td>low</td>
<td>high</td>
<td>variable</td>
<td>medium</td>
<td>high</td>
<td>high</td>
<td>high</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Is timestamp based</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td></td>
<td></td>
<td></td>
<td>Yes</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Sortable by creation date</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Can be easly used in a distributed system</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Support cursor-based pagination without adding a dedicated createdAt field</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Needs to be configured (eg. machine ID, shard id)</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>Yes (machine ID)</td>
<td>No</td>
<td>No</td>
</tr>
<tr class="bg-green-300">
<td>BIT Distribution</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Time</td>
<td>0</td>
<td>0</td>
<td>41 bit (msec res.)</td>
<td>39 bit (10msec res)</td>
<td>8 chars <br>(64 bit UTF8 ecoded, 41 bit real entropy, 1msec resolution) </td>
<td>0</td>
<td>32 bit <br>(1sec resolution)</td>
<td>48 bit</td>
<td>0</td>
<td>60 bit</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Sequence/Counter</td>
<td>32 bit</td>
<td>64 bit</td>
<td>12 bit</td>
<td>8 bit</td>
<td>4 digits <br>(32 bit UTF8 encoded, 10-11bit of entropy)</td>
<td>0</td>
<td>24 bit <br>(starting random)</td>
<td>0</td>
<td>0</td>
<td>16 bit<br>(clok seq.)</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Machine Id + Process Id</td>
<td>0</td>
<td>0</td>
<td>10 bit</td>
<td>16 bit</td>
<td>4 chars <br>(32 bit UTF8 encoded, </td>
<td>0</td>
<td>40 bit <br>(24 machine + 16 process)</td>
<td>0</td>
<td>0</td>
<td>48 bit <br>(MAC Address)</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Randomnes</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>8 chars<br>(64 bit UTF8 encoded)</td>
<td>variable</td>
<td>0</td>
<td>80 bit</td>
<td>122 bit</td>
<td>0</td>
</tr>
<tr class="bg-green-300">
<td>Security</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Is completly Random?</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
<td>No</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Predictability of the ID</td>
<td>High</td>
<td>High</td>
<td>Medium</td>
<td>Medium</td>
<td>Medium</td>
<td>Low</td>
<td>Medium-High</td>
<td>Low</td>
<td>Low</td>
<td>Medium-High</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Leaks the count of items</td>
<td>Yes</td>
<td>Yes</td>
<td>Partially</td>
<td>Partially</td>
<td>Partially</td>
<td>No</td>
<td>Yes?</td>
<td>No</td>
<td>No</td>
<td>No</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Leaks information about the machine/process</td>
<td>No</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
<td>No</td>
<td>No</td>
<td>Yes, MAC Address</td>
</tr>
<tr class="even:bg-green-50 odd:bg-green-100">
<td>Leaks the date of creation</td>
<td>Partially<br>(thorugh interpolation of <br>known dates it could be guessed)</td>
<td>Partially<br>(thorugh interpolation of <br>known dates it could be guessed)</td>
<td>Yes</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
</tr>
</tbody>
</table>
<script async defer src="https://buttons.github.io/buttons.js"></script>
</body>
</html>