seniorClean Architecture
Managing Identity (IDs) in Clean Architecture.
Updated Apr 28, 2026
Short answer
IDs should be generated in the Domain or via an Interface, not purely relying on Database Auto-increment.
Deep explanation
In CA, an Entity should ideally be complete before it's saved. If you rely on SQL AUTO_INCREMENT, the Entity doesn't have an ID until after it touches the database. Using UUIDs generated in the Use Case or Domain ensures the Entity is 'valid' throughout its entire lifecycle.
Unlock with a Pro subscription to view this section.
View pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro