Entity ID

July 02, 2021

Entity ID

Generating ID is an interesting challenge.

How you provide an ID doesn’t make it easier. That is, it’s provided via a microservice, it still is challenging to generate meaningful ID.

Asking the following questions may help you come up with a good strategy for generating.

How many needed?

Infinity… Might end up waiting for infinity for an ID that’s endless. When you get it, where do we store? Practically, asking how many you will need is an interesting way to go about it.

This is similar to KeyGen. Character, Number, or both?

When to generate?

An instantiated object can have an ID. Often when we think of an ID, it’s generated by a database (autoincrement) which means it’s generated at the time of serialization. I guess that’s the “officially” registered as an ID.

This is strange because if an application created an object. What ID should it have? A temp ID? How do you associate an object with a temp ID?

In Client/Server scenario. What does it mean to create an ID on the client side. E.g. Should a web client (UI) generate ID offline?

How to sync an ID?

This is simply solved by having a central location that provides ID that’s served for apps. This may not be a problem if it’s the app space already expressed in an environment (with multiple servers.)

Should ID have a pattern?

This depends on use/abuse. If id is generate sequentially, then an ID can be guessed and tried on. Any ID can but randomly generated makes it harder.


This almost solves it at the expense of size. It might be an overkill to store 100 records. It can be generated by any process following the same rule and endup with a different key. Conflicts is rare.

When to build an App ID?

When the GUID is too big to handle. Its 16-byte (128-bit) might be too big to handle.

SQL server likes it 4-byte number which can generate 4.2e9 numbers (2^32). After that, you can double to 8-byte 1.8e19 numbers (2^64) numbers.

App Specific ID with UTC

Down to nano seconds might not be enough. If you stamp with App ID (another unique number) then the ID will be unique.

  • it can be generated by App.
  • it might exceed number.

ID has a meaning. It might be confusing. ID can be longer than GUID. App ID needs to be carefully managed. Multiple apps with the App ID may cause data corruption - by Human Error.

© 2023 Kee Nam