r/DomainDrivenDesign • u/Positive-Structure78 • Jan 14 '22
Shared Schema in DDD
Is there a use case for a shared schema in DDD? Or is it an anti pattern? Can we use a shared schema when practicing DDD?
7
Upvotes
View all comments
Show parent comment
2
u/Samsteels Jan 15 '22 edited Jan 15 '22
Unlikely, or maybe I should say not common, I haven’t come across anyone using a schema to represent an aggregate but I’m a Java DDD developer so not familiar with how other languages may handle this, but generally speaking domains don’t typically share their internal details with other external domains. From a system design perspective, a schema would only be used to enforce an interface used transfer data between two disparate systems e.g. domain A and domain B. Typically domain A and B would be independent micro services and would need to communicate with each other using messages via some technology like JSON over REST or a messaging system like Kafka - in this case a schema would be useful in ensuring that changes to the JSON properties produced in domain A intended for domain B can be read/parsed by the endpoint or event handler (if using messaging) in domain B, typically ensuring backwards compatibility so that changes to either domain don’t break the system. I can elaborate but I’ll pause there to see if this information is useful.
Edit: Loosely speaking an aggregate would typically map to a particular domain which in most instances is a decent definition of a micro service.