<h1><aid="user-content-uuid-or-else"class="anchor"aria-hidden="true"href="#uuid-or-else"><spanaria-hidden="true"class="octicon octicon-link"></span></a>UUID or else</h1>
<p>There are many use cases where we need to use a unique ID.
In my experience, I only encouter 2 cases:</p>
<ul>
<li>ID to trace request from client to server, from service to service (microservice architecture or nanoservice I don't know).</li>
<li>Primary key for database.</li>
</ul>
<p>In my Go universe, there are some libs to help us with this:</p>
<h2><aid="user-content-first-use-case-is-trace-id-or-context-aware-id"class="anchor"aria-hidden="true"href="#first-use-case-is-trace-id-or-context-aware-id"><spanaria-hidden="true"class="octicon octicon-link"></span></a>First use case is trace ID, or context aware ID</h2>
When I use that ID to search log , if it pops more than things I care for, it is still no harm to me.</p>
<p>My choice for this use case is <strong>rs/xid</strong>.
Because it is small (not span too much on log line) and copy friendly.</p>
<h2><aid="user-content-second-use-case-is-primary-key-also-hard-choice"class="anchor"aria-hidden="true"href="#second-use-case-is-primary-key-also-hard-choice"><spanaria-hidden="true"class="octicon octicon-link"></span></a>Second use case is primary key, also hard choice</h2>
<p>Why I don't use auto increment key for primary key?
<li><ahref="https://www.cybertec-postgresql.com/en/uuid-serial-or-identity-columns-for-postgresql-auto-generated-primary-keys/"rel="nofollow">UUID, SERIAL OR IDENTITY COLUMNS FOR POSTGRESQL AUTO-GENERATED PRIMARY KEYS?</a></li>
<li><ahref="https://brandur.org/nanoglyphs/026-ids"rel="nofollow">Identity Crisis: Sequence v. UUID as Primary Key</a></li>
<li><ahref="https://blog.kowalczyk.info/article/JyRZ/generating-good-unique-ids-in-go.html"rel="nofollow">Generating good unique ids in Go</a></li>
<li><ahref="https://encore.dev/blog/go-1.18-generic-identifiers"rel="nofollow">How we used Go 1.18 when designing our Identifiers</a></li>
<li><ahref="https://blog.daveallie.com/ulid-primary-keys"rel="nofollow">ULIDs and Primary Keys</a></li>