Derrick Martin Challenges Database ID Paradigm for Decoupled Systems
Derrick Martin of CodeOpinion.com recently presented a compelling argument challenging the prevailing practice of relying on databases for generating entity IDs. While conventional in CRUD-heavy applications, this approach, Martin contends, introduces significant architectural constraints, particularly in modern distributed systems employing asynchronous processing and messaging. Using a logistics shipment application as an example, he illustrates how waiting for a database-generated ID complicates immediate client feedback for long-running operations. If a complex workflow like creating a shipment involves extensive validation and calculations before persistence, the client is left without a definitive identifier for status tracking. Martin advocates for client-generated IDs, such as UUIDs, issued at the initiation of the request. This fundamental shift ensures the entity possesses a stable identity from its inception, enabling seamless asynchronous message processing and real-time status updates for the client.
The implications of early ID generation extend far beyond asynchronous processing, profoundly influencing system decoupling and data correlation across disparate services. In complex workflows where an entity like a shipment traverses multiple stages (e.g., order dispatch, carrier assignment, tracking, billing), various services might process events related to the same shipment. Client-generated IDs provide a consistent correlation key from the outset, obviating the need for a monolithic “shipment service” that owns all data. Instead, different bounded contexts can maintain their specific views of the shipment. This approach allows for composing comprehensive user interfaces by aggregating data from these diverse services, each already possessing relevant information correlated by the shared shipment ID. Martin highlights that this strategy avoids the pitfalls of “fat events” or Change Data Capture (CDC) to distribute entire entity schemas, as services can subscribe to minimal events (just the ID) and enrich their data independently. This design philosophy, echoing principles from Udi Dahan’s work on decoupled services, ultimately leads to a more flexible, maintainable, and genuinely decoupled architecture.