Microservices – Understanding Microservices Architecture

In this article, we’re going to discuss; the Microservices Architecture, compare Monolithic vs Microservices Architectures and learn when to opt for a Microservices Architecture.

But, before start this topic, I want to shed some light on the Layered Architecture.

What’s a Layered Architecture?

Layered Architecture is a pattern used to build web applications despite of the type of architecture (monolithic or microservice). This type of pattern contains a group of layers, each layer:

  • is a bunch of components or modules
  • is assembled on top of one of another
  • provide services to the higher layer
Layered Architecture
Layered Architecture

The most layered pattern consists of following standard layers:

  • Presentation Layer
  • Business Layer
  • Persistence Layer

Presentation Layer

Presentation Layer consists of UI, Controllers and Models.

UI – User Interface component is the web interface which users will use to send request data through.

Model – is a Java Class that describes the data structure, it will be used through object instantiation to perform CRUD operations on the database like insert, get, update or delete.

Controller – this component defines a collection of end-points or APIs to handle all types of requests coming from web browsers.

Presentation Layer
Presentation Layer

(1) – Controller component receives requests from web browser.

(2) – Controller component uses an object instantiation from the Model Class to transfer the data through.

(3) – As I mentioned earlier, each Layer call functions from the Layer below. In this case, is the Business Layer.

(4) – Get a response data from the Business Layer.

(5) – Send data to the View or User Interface component.

(6) – Send back the response to the user.

Business Layer

service – this component or module determine a group of business logic methods; each method implements a specific code to use.

Business Layer
Business Layer

(1) – Business Layer receives a call from the Presentation Layer.

(2) – Business Layer will call the Persistence Layer to save the information.

(3) – Return back a response to the Business Layer.

Persistence Layer

repository – this module predefined a bunch of methods which will then be used to perform CRUD (Create, Read, Update and Delete) operations to the database.

Persistence Layer
Persistence Layer

What’s Microservices Architecture?

Microservice is an approach that was introduced first in 2011 in order to build large web applications. This concept decomposes a large application into multiple microservices (components or services).

Each microservice,

  • has its own codebase to program with
  • implements its own business logic
  • has a private database to store data
  • runs on its own process
  • can be separately deployed
  • can communicate with other microservices through APIs

Monolithic vs Microservices Architecture

Monolithic architecture is a traditional approach used to build web applications, as shown in the graphic below.

Monolithic Architecture
Monolithic Architecture

Advantages of Monolithic architecture

debugging – a monolithic application is a one structure, which means unit testing is going to be easy.

deployment – deploying a monolithic application, means pushing a single executable jar file into a web server. It’s an easy step for developers.

Disadvantages of Monolithic architecture

development – monolithic approach builds a web application as a one single piece, which means that in development phase all team must program in parallel in order to develop the application.

reliability – in a monolithic architecture when something goes wrong, that means that the whole application needs to be fixed. Therefore, it’s going to be hard and also a waste of time.

scalability – in a monolithic architecture when something goes wrong, that means that the whole application needs to be fixed. Therefore, it’s going to be hard and also a waste of time.

Microservices architecture

Microservice Architecture
Microservices Architecture

Advantages of Microservices architecture

development – specific microservices can be assigned to specific team developers, following this approach allows them to focus on the service without worrying on the rest of the web application.

deployment – this approach makes each microservice deployable independently, thereby, it makes continuous deployment and faster app updates for large web applications.

fault isolation – If a specific microservice fails, you can isolate that failure to that single service that would cause the app to crash. This fault isolation means that your critical application can stay running even when one of its components fails.

Disadvantages of Microservices architecture

complex development – microservice application can even contain a multiple of microservices that needs to communicate with each other. Debugging can be challenging when applications consists of a collection of microservices, each microservice has it’s own set of logs, tracing the source of the issue cannot be a breeze.

Requires a cultural shift – Agile or DevOps environment in place to put microservice approach into practice because it fits into this development model perfectly, as each small team can own and focus on one service.

More expensive – each service uses its own technology stack, CPU, programming language, etc…

When to opt for a Microservice Architecture?

Microservice approach offers many benefits, as well as helping enterprises release software faster, update software more frequently and integrate new features more quickly.

The client needs change instantly, so companies needs to implement this concept in order to update quickly the web application.

Consider a scenario where you’re developing an e-commerce application that obeys to the following characteristics:

  • Support all variety of client (desktop and mobile users)
  • Expose API for third parties to consume
  • Run multiple instances for each microservice
  • Deploy each microservice on a container

From the requirements above, you can conclude that this application relies on microservices architecture.

You have to define an architecture that structures the application as a set of loosely coupled, collaborating services. Services can communicate using either synchronous or asynchronous protocols. Services can be developed and deployed independently of one another. Each service has its own database in order to be decoupled from other services.

This e-commerce application consists of the following modules or components:

user – implements services like signup and signin users
product – implements services like addProduct, editProduct and deleteProduct.
order – implements services like addOrder, deleteOrder.
shipping-card – implements services like addToShippingCard
delivery – implements services like sendDelivery
bill – implements services like sendBill

Defining this architecture for this e-commerce application, means that each team will focus on implementing the services required for that microservice (component or module). After the development cycle, each microservice will be deployed and running in it’s own process.

Microservices – Understanding Microservices Architecture

Leave a Reply

Your email address will not be published.

Scroll to top