Meaningful Identifiers

2021 01 02 head

Identifiers are a key concept to successfully model complex business domains. They permeate how our modern civilization functions.

Could you imagine a country without a car registration number of vehicles, internet addresses, postal addresses or social security numbers?

Identifiers are identifiers.

Identifiers cannot be changed at any time.

Updating identifiers means introducing mapping relations between the old and the new values.

In computer science, identifiers IDs are lexical tokens that name entities.

Identifiers are used extensively in virtually all information processing systems.

Identifying entities makes it possible to refer to them, which is essential for any kind of symbolic processing.

External Well-Defined Identifiers

The best identifiers are externally well-defined identifiers.

A unique and well-defined authority is responsible for defining and publishing them. Ideally, the authorities should only create new identifiers and never delete existing ones. The published information is available to all interested parties.

Examples are

  • Currency names as defined in ISO standard 4217.

  • Country abbreviations as defined in ISO standard 3166.

  • Social security numbers are well documented in the country they are used.

  • Car numbers are well-known and documented.

Try to use global externally defined identifiers as much as possible. Always document the authority in charge to create these identifiers.

Examples you are using are

  • IBAN account numbers are defined worldwide through ISO 13616.

  • Bank connections are defined as Business Identifier Codes through BIC ISO 9362. The registration authority is SWIFT.

  • Car numbers and country acronyms are defined worldwide.

  • Passport numbers are defined worldwide. Each country has its own structure and conventions.

  • Social security numbers are a counter-example. There are currently only defined locally.

External Managed Identifiers

You shall document the source of truth for all externally defined and managed identifiers.

The source of truth shall work as a benevolent responsible. It should support all interested parties and guaranty their identifiers can be trusted.

Internal-Managed Identifiers

One possible approach is to define a naming convention such as

Year - Acronym - Counter

An example of such an identifier would be

2021-CNT-0001 (Contract number 1 in year 2021)
2020-EVT-0101 (Event number 101 in year 2020)

Variations are

  • A full date as prefix, our system uses this convention to name invoices.

  • A more readable acronym, our ERP system uses the word invoice to name invoices.

Beware if you export internal managed identifiers, you become a source of truth. You are responsible for documenting these identifiers and the process to create new ones. You shall also guaranty that existing identifiers are never recycled. If your identifiers are strings, you shall clearly define the supported languages and character sets.

Domain-Driven Design

Domain Driven Design DDD is a powerful and modern approach to define agile software architecture [1, 2]. Some key rules are related to identity.

Entity has a well-defined identity

An entity is an object not defined by its attributes, but rather by a thread of continuity and its identity. Any instance of an entity abstraction must have a unique identifier.

Identify aggregate through identity

An aggregate is a group of objects that are bound together by a root entity, called the aggregate root. Objects outside the aggregate are allowed to hold references to the root but not to any other object of the aggregate. The aggregate root is responsible for checking the consistency of changes in the aggregate.
An aggregate is found and referenced through the identifier of the aggregate root entity.

Reference over aggregate through identity

An aggregate shall reference another aggregate through the identity of their root entity instance.

The concept of identity is therefore central to the domain-driven design approach.

Lessons Learnt

Always try to find an external, well-defined identifier for your entities. Beware of legal aspects when you are using government defined identifiers such as social security numbers, passport numbers or car numbers.

Avoid by all means to using an internal privately defined identifier as a public one. You will bear the burden of documenting, manage and evolve the scheme as soon as you do this.

Related concepts are discussed in our blog series