Basics about ID generation with KMP
What Id Types are there? KMP specific Id options and Ideal Auto Increment function.
Why are Ids important?
IDs are fundamental in software systems as unique identifiers that ensure entities such as records, users, or objects can be reliably distinguished. They play a critical role in data integrity, efficient data retrieval, and consistent referencing across distributed systems. Without stable and unique IDs, synchronization, data consistency, and identity verification become challenging or impossible.
1. Integer IDs
Integer IDs are numeric sequential or incremental values often used as primary keys in databases. They are simple, efficient to store, and fast to compare. However, in distributed or multi-instance systems, integer IDs must be carefully managed to avoid collisions, which often requires coordination or partitioning schemes.
2. UUID (Universially Unique Identifier)
UUIDs are 128-bit values designed to be unique across space and time, enabling distributed system components to generate IDs without coordination.
Version 1 (Method description)
UUID v1 combines the generating computer's MAC address and timestamp to ensure
uniqueness but raises potential privacy concerns due to exposing MAC addresses.
Version 2 (Method description)
UUID v2 is similar to v1 but includes POSIX UID/GID for a local domain scope, thus less commonly used.
Version 3 (Method description)
UUID v3 generates IDs from a namespace and a name using MD5 hashing, ensuring deterministic but not random IDs.
Version 4 (Method description)
UUID v4 uses random numbers to create unique IDs. It provides good randomness but does not guarantee uniqueness absolutely.
Version 5 (Method description)
UUID v5 functions like v3 but uses SHA-1 hashing for improved cryptographic strength and deterministic ID generation.
3. StringIDs
String IDs are human-readable text-based identifiers that can encode meaningful information (e.g., usernames, email addresses) but require careful design to ensure uniqueness and avoid collisions.
4. Composite IDs
Composite IDs combine multiple attributes, such as an integer and a string or multiple column values, to uniquely identify an entity, often used in relational databases to represent complex keys.
5. Hybrid IDs
Hybrid IDs blend numeric and random components to leverage the advantages of both—for example, a timestamp combined with a random number—to assure uniqueness and sortability.
6. Nano IDs
NanoID is a modern, URL-friendly unique string ID generator that is compact yet collision-resistant, making it ideal for web and mobile applications.
7. ULID (Universially Unique Lexicographically Sortable Identifier)
ULID generates 128-bit IDs that retain timestamp ordering in lexicographical form, facilitating efficient sorting and querying in distributed systems.
8. Snowflake like IDs
Snowflake IDs are 64-bit unique integers combining timestamps, machine identifiers, and sequence numbers, popularized by Twitter for generating sortable, distributed IDs without coordination.
9. Auto Increment
Auto increment IDs automatically increase with each new record. While simple and efficient for single-node databases, they pose challenges in distributed environments due to collision risk.
Special Usecase: Using IDs in human readable files.
IDs in human-readable files should balance uniqueness with readability. Techniques include using UUIDs for uniqueness or string-based codes for clarity, depending on use case requirements.
ID generation for local storage
Local storage ID generation must ensure uniqueness within the device context. Options include auto increment counters or random-based UUIDs, considering offline capabilities.
ID generation for Multiplatform application with online and offline capability
Multiplatform applications need an identification strategy that guarantees uniqueness across platforms and sessions, often combining locally generated IDs with server-side synchronization and conflict resolution.
The Ideal Auto Increment ID generation function for offline storage and database storage.
An ideal function for auto increment IDs offline should maintain the sequence locally, handle resets, and sync with server states to avoid duplicate IDs, possibly by segmenting ranges per device or user.
Sources
https://phoenixnap.de/Glossar/UUID%2C-universelle-eindeutige-Kennung
