Microservice at a frontend level

front-endmicroservices

I'm a software developer, and the kind of developer we call "front end developer". I'm working on stuff like Angular, React, Vuejs and many others.

I wanted to know how we can organize our front end code so that we can fit a microservice architecture.

Actually, we scale services across units, each service is "independent" or at least, is decoupled from the others. This makes perfect sense. My question is:

How can we organize code, so that our front end code can matches these services?

I don't want to build monolithic applications in a microservice and big scale context. I was thinking of a way to split my front end components. But the problems come when we try to expose those components in a webpage that would aggregate them to build a real application…

I'm a bit lost in this situation and I need some help understanding the flow on a front end side.

If you can, please link any articles, or practices that could help me.

Best Answer

The last week or so I've been exhaustively researching the idea of microservice organization on the FrontEnd.

I think the easiest approach would be to leverage your library/framework of choice to separate different pieces of the Front End in verticals that correspond to the respective backend micro services. In Angular that would be something like Modules that are lazy loaded where each module corresponds to a microservice. You could go so far as to use your build tooling (ie. Webpack) to limit the output to just the components for the micro service(s) being deployed.

If you already have discrete front end repositories then it's more challenging because you have to decide how to stitch together the components. Some options for page composition include:

  • HTML iframes which have been around for a long time, but have trade-offs such as performance, communication between components, nesting of components, etc. However iframes offer the most freedom when it comes to allowing two (micro service) components to run side-by-side in the same DOM.
  • Polymer, Vue and React offer a lot when it comes to composition of custom elements but without a different root document you'll have to carefully manage component dependencies so libraries aren't fighting/breaking each other.
  • native web components are eventually coming to modern browsers but you'd be better off using Polymer, Vue or React as I believe they offer polyfills and other advantages.

Since I can only post 2 links, here are perhaps the most relevant.

Related Topic