0

Let's say an Orders service knows only about the CustomerId from Customer service.

When the user places an order, the CustomerId gets transferred from the composite UI along with the OredrDto.

The question is:

In an event-based microservice environment, how can Order service make sure that the CustomerId is valid and exists before placing the order?

1 Answer 1

1

Well, you have a couple choices.

First, you could have it proactively query the Customer Service as part of its data validation logic (you are validating all your inputs, right?).

Second, you could have it just validate that it's the appropriate data type (e.g. Guid) and then pass it along to whatever the next step is. At some point, some service you have will have the job of actually fulfilling the order and it'll fail trying to look up the customer's shipping address or similar data and raise a OrderFulfillmentError or similar, which you could publish along your error event channel (if you're doing truly event-based stuff).

The former is probably easier to debug, but might result in false negatives depending on the timing of things and how the rest of your architecture is setup. The latter probably needs to be in place regardless, in case of any other upstream errors. In practice, I'd probably do both.

1
  • Should data be validated at the web tire or application service?
    – Mohsen
    Dec 3, 2019 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.