when working dynamodb , have need generate unique ids customers, products or other things users come in contact correct way of doing it?
sure uuids great not can expect customer use , if want make own on server have make pretty awkward database calls make sure either use next 1 in sequence, save weird field or make random stabs in dark.
so how can go solving issue?
i argue uuids still way go. if looking architect scalable solution, can't rely on single "point of failure" generate sort of sequential unique identifiers - require synchronization , availability enemy of performance in distributed system.
however, if you'd generate more human friendly identifiers, have couple of options:
you start uuids , fold in half (take first 8 bytes , xor last 8 bytes), take resulting 64-bit number , encode using base 62 encoding (numbers 0-9 plus upper , lower -case letters) generate 11 character string more human-friendly typical uuid; if you're ok less entropy fold uuid twice, obtaining 32-bit number encode 6 character base 62 representation, or 7 character base 32 encoding uses numbers , upper case letters
the second approach take use combination of mac address, time stamp , pseudo random number generator generate own ids, following rule, similar how uuids generated less entropy, again, may encode ids such user friendly
you can prevent issues arise in case same id accidentally generated in 2 different places, can take advantage of conditional writes dynamodb.
Comments
Post a Comment