Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Question regarding 'Chapter 4. Integration' in the book 'Building Microservices'.

Question regarding 'Chapter 4. Integration' in the book 'Building Microservices'.

Under the section entitled 'Defer It For As Long As Possible', the author states:
"Let’s consider our Email Service, whose job it is to send out emails to our customers from time to time. It gets asked to send an order shipped email to customer with the ID 1234. It goes off and retrieves the customer with that ID, and gets back something like the following:"...

My question is, should the Email service retrieve the customer from the Customer Service via a direct REST GET request to that service, introducing coupling, or should it be done via an event?

Thank-you!
1 person has
this question
+1
Reply
  • Hello Dean,

    Thanks for your interest in Building Microservices. I'll contact an editor and forward them your question. Once I have more information on this I will contact you.

    Best regards,
    Paul Fichera
    O'Reilly Media
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • Hi Dean,

    The answer is it depends! A simple option would be for the email service to directly call the Customer service to get the detail it wants. If using REST, original request to the email service could include the URI for the customer, making this fairly straightforward.

    We could of course include all the details of the customer in the original request to the email service itself, just passing it the email address & any other required details for the customer. This would make the email service unaware of (and therefore not coupled to) the customer service at all. In general this 'feels' more right for something like an email service. One thing to consider though. If the requests to the email service are queued up, we do have to accept that we increase the chance that in the time between the request to the email service is made and the email being sent that the customer could have changed their email address. This is also possible when requesting it directly from the customer service, but the window is much larger.

    Another option is that the Email service could subscribe to events coming out of the customer service, and could record locally what it thinks the email address is for every customer. So when it gets a request it knows where to send it. This feels wrong to me. We introduce the need to store a local email address for every customer, and keep them up to date, even if we don't need to email them. There may be some extreme cases where this makes sense, but this duplication of data worries me somewhat.

    I hope that helps!
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated