mardi 17 décembre 2019

What is the best way to design microservice with multiple interdependent external calls?

I have a microservice with following functions:

• To prepare a list of response of various categories.

• Each category of response, contain list of items.

• To construct these items, data need to fetched from various external services.

Lets take an example to understand better:

Flow

So, to prepare response

• Category 1 needs data from Service 1.

• Category 2 needs data from Service 2.

• Category 3 needs data from Service 3, but service 3 to run itself needs some data from service 2.

So, one of the easy way I can think is to just get all the data first, service 1 and 2 in parallel, and then service 3. Then pass all this data to all categories, and categories will prepare responses on basis of data they need. This will ensure no multiple hits are made to external service for same data. But, is this correct from design point of view?

From what I can think, it should be responsibility of Category classes, to tell what data they need for their purpose. As in future, further categories can come, and this would be easier to just specify what data they need and use it accordingly (IMO)

What is a good design for such service?

Aucun commentaire:

Enregistrer un commentaire