So, given that entities need to have a stable identity over time, they require a unique identifier or key. Who is responsible for creating these identifiers? Where do these identifiers come from?
The responsibility for creating unique identifiers (keys) for entities in a domain-driven design (DDD) system depends on the context and requirements of the application. There are several common approaches to generating these identifiers, each suited to specific use cases. Let’s explore these approaches and who is responsible for generating the identifiers in each case.
In some domains, the identifier is inherent to the entity itself and comes from the real-world domain.
Examples:
- Serial numbers for banknotes: In the state mint context, the identifier (serial number) is usually assigned during the manufacturing process. The mint’s production system generates the serial number and ensures uniqueness.