Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Architecture of a microservice based web app

I am confused about the point at which a web application diverges into microservices - is it at url level or models level? As an example, Suppose I have a monolithic app that serves 3 pages. Say each page serves a separate usecase and I want to back each of them with their own microservices. Now, which of these is the correct way of implementing a microservice based architecture:

  • I create three different apps(microservices), each containing the (route, controller, models, templates) for one of the pages. And then based on which ever page is requested, I route the request to that particular app. This means that the whole page from database to HTML is served by a separate app. Basically, different pages in the same website are being completely served by different apps on the backend.
  • The 3 microservices do not handle the UI stuff but only the data for their usecases(models, controller, no templates) and expose it over a REST api. I have one public facing app. This app queries the three different apps(microservices) only for the data and then builds the html pages to be returned to browser. All the pages in a web app in this case are being served by a single app which internally makes use of three different microservices.

enter image description here

like image 408
shreyj Avatar asked Nov 11 '14 13:11

shreyj


People also ask

What is a microservice application architecture?

A microservices architecture is a type of application architecture where the application is developed as a collection of services. It provides the framework to develop, deploy, and maintain microservices architecture diagrams and services independently.

What is microservices in web applications?

With a microservices architecture, an application is built as independent components that run each application process as a service. These services communicate via a well-defined interface using lightweight APIs. Services are built for business capabilities and each service performs a single function.

What are the different architecture of microservices?

While there are literally dozens of ways to implement a microservices architecture pattern, three main topologies stand out as the most common and popular: the API REST-based topology, application REST-based topology, and the centralized messaging topology.


2 Answers

You trouble is how model your microservices.

In term of microservices the second approach is most appropriate, which expose its logic through API.

Always when you model your microservices keep in mind the follow facts.

  • Loose Coupling: When services are loosely coupled, a change to one service should not require a change to another. The whole point of this Microservice thing is being able to make a change to one service, and deploy it, independent of a need to change any other part of the system. This is really quite important.

  • Strong Cohesion: We want related behaviour to sit together, and unrelated behaviour to sit elsewhere. Why? Well, if we want to change behaviour, we want to be able to change it in one place, and release that change as soon as possible.

like image 110
DeivinsonTejeda Avatar answered Oct 13 '22 22:10

DeivinsonTejeda


As usual in Software Engineering, the answer is it depends. I can't imagine a reason right now but the option 1 could be useful in some particular scenarios.

However, considering the formal definition of microservices, the option 2 illustrates it better. One of the main advantages of having microservices is being able to reuse it. Different applications have different requirements and needs on presenting the information. Making your microservices return a JSON representation of your data will give you more flexibility on how to format this information.

like image 33
Trein Avatar answered Oct 13 '22 23:10

Trein