Glossary / Guid

Guid

Guid is a 128-bit identifier type used for values that need a very low collision probability across independently generated systems. It is commonly used for entity IDs, correlation IDs, and distributed references, but it does not inherently provide secrecy, authorization, ordering, or strict uniqueness guarantees.

Generation and representation

Guid.NewGuid() creates a GUID using runtime/platform facilities. A GUID can be parsed and formatted in standard textual forms; string formatting and byte ordering conventions matter when interoperating with other languages or database binary columns. GUIDs can be random-based or other versions such as time-ordered forms depending on APIs and standards adopted; do not infer properties from the type alone.

Random GUIDs have poor locality in some clustered indexes because inserts are distributed, while sequential or time-ordered identifiers can improve locality but expose ordering/timing and require a trusted generator. A GUID is not a cryptographic secret or bearer token by default; use cryptographic random tokens with sufficient entropy and lifecycle controls for security tokens.

Engineering guidance

Choose identifier strategy based on collision tolerance, database indexing, privacy, sortability, and cross-system generation. Validate format at boundaries. Store as native GUID type where supported and standardize text casing/format. Avoid assuming lexicographic string order matches creation order.

Interview questions

  1. Does GUID guarantee uniqueness? It makes collision extremely unlikely under proper generation, but mathematically collisions are possible.
  2. Is a GUID secret? No; it should not be treated as authorization or cryptographic material by default.
  3. Why can random GUID hurt clustered indexes? Insert order is scattered, causing page splits/locality costs.
  4. What is a time-ordered ID tradeoff? Better locality/order but may reveal time or require coordination.
  5. What should interop define? Byte order, textual format, casing, and parsing contract.

References