Imagine I have 2 services (or contexts) - (i) Warehousing + Catalog and (ii) Order
If we want to Create a new Order, we call an endpoint, CreateOrderCommand, passing a body like
{
[{
productId: 12123, <—— this could be invalid
qty: 500
}]
}
The Order service assumes there is enough stock and creates a OrderCreated domain event:
{
orderId,
products: [{
productId: 12123,
qty: 500
}]
}
The Product Service will respond to this event and either deduct the quantity on hand (success OrderKitted) or fail and product a OrderFailedEvent (with orderId) (i.e. we have a choreography saga). That’s all great, but what trips me up is how do we validate that productId 12123 is valid? Perhaps in my situation I can assume it’s valid until the Product service gets the message and it fails, but that only works in this scenario due to the process flow that assumes the order has enough stock.
The other options are
- Orders keeps a list of all productIds (every time a catalog adds an item we have a ProductAddedToCatalog domain event which the Orders service can listen to)
- Orders service calls out to Products service to validate the productId (not sure I like this coupling and dependency).
What are the typical approaches to validating ids (stable identifiers like productId) which are shared across contexts?
Thank you