title: Generating unique short IDs - MongoDB to manage collisions
body: <p>I am evaluating the following code to generate a short ID in my Node server (inspired by previous post: <a href="https://stackoverflow.com/questions/30354581/short-user-friendly-id-for-mongo">Short user-freiendly ID for mongo</a> ):</p>
  
  <pre><code>&gt; b = crypto.pseudoRandomBytes(6)
  &lt;SlowBuffer d3 9a 19 fe 08 e2&gt;
  &gt; rid = b.readUInt32BE(0)*65536 + b.readUInt16BE(4)
  232658814503138
  &gt; rid.toString(36).substr(0,8).toUpperCase()
  '2AGXZF2Z'
  </code></pre>
  
  <p>This may not guarantee uniqueness, but my requirements are to have a short ID of maximum length 8 characters and it must also be all upper case. The purpose of this is to make the ID user friendly.</p>
  
  <p>To ensure that there are no collisions, I am planning to create a collection in MongoDB that contains documents that map the short ID, which will be an indexed field, onto the MongoDB ObjectID of the actual document I want the short ID to refer to. </p>
  
  <p>What is the best strategy for doing this to ensure scalability and performance in a concurrent environment where multiple process on multiple physical servers will be checking for short ID uniqueness?</p>