2

I have 2 Micro Services one for Orders and one for Customers
Exactly like below example
http://microservices.io/patterns/data/database-per-service.html
enter image description here

Which works without any problem.
I can list Customers data and Orders data based on input CustomerId

But now there is new requirement to develop a new screen
Which shows Orders of input Date and show CustomerName beside each Order information

When going to implementation
I can fetch the list of Ordersof input Date
But to show the corresponding CustomerNames based on a list of CustomerIds
I make a multiple API calls to Customer microservice , each call send CustomerId to get CustomerName
Which lead us to more latency

I know above solution is a bad one
So any ideas please?

Yogendra Mishra
  • 2,399
  • 2
  • 13
  • 20
Ahmed Nabil
  • 17,392
  • 11
  • 61
  • 88

2 Answers2

1

The point of a microservices architecture is to split your problem domain into (technically, organizationally and semantically) independent parts. Making the "microservices" glorified (apified) tables actually creates more problems than it solves, if it solves any problem at all.

Here are a few things to do first:

  • List architectural constraints (i.e. the reason for doing microservices). Is it separate scaling ability, organizational problems, making team independent, etc.
  • List business-relevant boundaries in the problem domain (i.e. parts that theoretically don't need each other to work, or don't require synchronous communication).

With that information, here are a few ways to fix the problem:

  1. Restructure the services based on business boundaries instead of technical ones. This means not using tables or layers or other technical stuff to split functions. Services should be a complete vertical slice of the problem domain.
  2. Or as a work-around create a third system which aggregates data and can create reports.
  3. Or if you find there is actually no reason to keep the microservices approach, just do it in a way you are used to.
Robert Bräutigam
  • 7,514
  • 1
  • 20
  • 38
1

New requirement needs data from cross Domain

Below are the ways

  1. Update the customer Id and Name in every call . Issue is latency as there would be multiple round trips

  2. Have a cache of all CustomerName with ID in Order Service ( I am assuming there a finite customers ).Issue would be , when to refresh cache or invalidate cache , For that you may need to expose some rest call to invalidate fields. For new customers which are not there in cache go and fetch from DB and update cache for future . )

  3. Use CQRS way in which all the needed data( Orders customers etc ..) goes to a separate table . Now in this schema you can create a composite SQL query . This will remove the round trips etc ...

Prag
  • 54
  • 3