0

I am looking at designing an application that has a Microservices back end and a SPA front end. I have some concern about performance, a single CRUD page to populate may require calls to 6 or 7 service endpoints which I can't imagine will be fast.

Is is good practice to implement an additional service layer that essentially creates view models with all the information required rather than requiring the client make so many calls? What is this pattern called?

  • 1
    Take a look to Backends for Frontends. Sam Newman introduce a mix of dedicated API gateways and service's agreggators. – Laiv Aug 1 '17 at 15:59
2

You have two basic options.

  1. Create a 'wrapper' service for the UI that makes aggregated calls to each service it needs from and puts the data in the form the UI needs it.
  2. Create a service that always has the most up-to date information already stored in its own datastore for each resource you are interested in.

I have done #1 and it does not scale very well. Especially if you have to paginate data and have complicated search queries that needs to filter data that are stored in different micro services. If you strongly anticipate you may need such capabilities, I would not go down this rabbit hole.

We are starting to work more and more with #2 now. Based on my research there are lots of shops that follow this 'pattern'. It is called even driven data management. What this means is that each micro service may broadcast asynchronous events when their data changes and anyone can subscribe to these events and react by updating their datastore appropriately. In your case you may have a simple data store to house all the information necessary to serve the UI and ensure that you catch these events correctly and update the data.

This is one of the very serious drawbacks of using a micro service architecture. Data management is a lot harder due to bounded context. You go down the path of aggregating calls until you realize it won't suffice then you may have to start doing event driven data management that is just a lot of extra work to 'denormalize' your data into a single datastore for quick querying.

  • This is very interesting, good answer. – Craig Jul 31 '17 at 23:52
2

I usually implement a service layer that is dedicated to the needs of each specific client. I assume you're talking about a webapp that needs to make 6-7 requests to render a page. As you've noticed this isn't scalable or performant for a web client to make so many requests.

Is is good practice to implement an additional service layer that essentially creates view models with all the information required rather than requiring the client make so many calls?

Yes that's what I would do. I would create a new microservice for serving the needs of this webapp. Create an API in this microservice that maps pages/requests of your webapp to one or more requests to other services. The webapp should only make a single request to your backend for each action/page.

What is this pattern called?

I don't know if it's a specific pattern, but it's essentially the microservice equivalent to the adapter pattern.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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