0

Currently, we have an API endpoint (microservice called supplier service) like this: /suppliers/{supplierNumber}, which will return a single supplier information.

In the UI, there is a screen to display a list of suppliers for different products. It looks something like this:

product1 -> supplier1
product2 -> supplier2
product3 -> supplier3

To display suppliers for a list of products, we need a for loop which calls the end point on each iteration.

My concern is that this is inefficient from a performance stand point. Why is it not possible to design an endpoint that takes in a list of supplier numbers and returns a list of supplier information?

Other people have said that it's not microservice design, and I'm not sure why it's not a proper design. Does anyone know the reasoning behind this?

J.L
  • 592
  • 5
  • 17
  • 35
  • Possible duplicate of [Posting array of objects with MVC Web API](https://stackoverflow.com/questions/16042853/posting-array-of-objects-with-mvc-web-api) – mjwills Jul 09 '18 at 03:57
  • @TheGeneral it is an endpoint, sitting in supplier service, i just pick part of the url – J.L Jul 09 '18 at 04:01
  • I see completely nothing wrong with passing a list of suppliers as a parameter. In its core, microservices architecture is separating code into distinct logical pieces, and fetching a list of suppliers is a standard example of this separation. If anything, hydrating an object in a loop is an antipattern in my eyes. – Simas Joneliunas Jul 09 '18 at 04:05
  • It's nothing to do with _microservices_. I suspect you mean REST. Also, a REST service can be microservice but not all microservices are REST –  Jul 09 '18 at 05:13

3 Answers3

1

I think it's better that you have an endpoint that returns all the suppliers information and specify some optional query attributes to restrict the results for caller situation.

in this case an attribute like supplierNames which is an array of String. /suppliers?supplierNames=s1,supplierNames=s2,... and you return all suppliers that has the supplierName in your supplierNames query attribute.

chubock
  • 834
  • 8
  • 16
0

You should have an implementation for getting the list of suppliers. Something like /suppliers/{supplierNumberList}.

Since you define the API for your service, there is nothing wrong to have a call like this.

PepitoSh
  • 1,774
  • 14
  • 13
0

From Design perspective, there is no harm having v1/suppliers/{supplierList} as an endpoint for your service (microservice called supplier service). For performance improvement you can do other optimization like cache etc. or implement CQRS.

Yogendra Mishra
  • 2,399
  • 2
  • 13
  • 20