UUID Strategy
UUID Strategy
Section titled “UUID Strategy”This document outlines the UUID strategy for the Hatchgrid project. All contributors are expected to follow these guidelines to ensure consistency and maintainability of the codebase.
Table of Contents
Section titled “Table of Contents”Introduction
Section titled “Introduction”A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems. We use UUIDs as the primary keys for our database tables.
UUID Version
Section titled “UUID Version”We use UUID version 4 (randomly generated) for all our primary keys. UUIDv4 is a good choice for most use cases because it is easy to generate and does not require a centralized authority to ensure uniqueness.
UUID Generation
Section titled “UUID Generation”We use the java.util.UUID
class to generate UUIDs.
import java.util.UUID;
public class UuidGenerator {
public static UUID generate() { return UUID.randomUUID(); }}
UUID Storage
Section titled “UUID Storage”We store UUIDs in the database as a binary(16)
column. This is more efficient than storing them as a varchar(36)
column.
UUID Usage
Section titled “UUID Usage”We use UUIDs as the primary keys for all our database tables. We also use them as the external identifiers for our resources. This allows us to expose the UUIDs in our API without exposing the internal database IDs.