WEB APPLICATIONS TO MICROSERVICES

Hansini Rupasinghe
Nerd For Tech
Published in
6 min readJun 7, 2021

In 2013, along with Martin Fowler’s book and several discussions on Microservices, people started thinking about new architectural views for web applications. Let us focus on how we can migrate from web applications to microservices.

We use Monolithic applications. Monolithic architecture consists of a single executable file for the entire application. This can also be a WAR, EAR or some other archive. The ground rule of monolithic applications is that the entire application is packed into one file.

Disadvantages of Monolithic Applications

📍 If you want to make a single change (such as UI/UI color/ simple business logic), you may need to zip entire file. Why this matters because you will have to;

📎 Test entire application (Regression Testing)

📎 Perform and execute the entire app

📎 May put down the entire app, send it to offline and then to a new version

📎 Cumbersome

📍 Have to maintain a huge codebase.

When an issue, diagnostic thing or anything comes up with the production, you may have to go through separate support processes as no one knows each and every part of the code. Even if you want to debug, you have no idea from where it comes and where it goes. Therefore, Debugging process becomes very hard.

📍 Deployment process is hard.

This happens because you need to make sure if;

📎 other side is taking a traffic?

📎 all the modules, applications and dependencies are sent offline or rerouted traffic?

📎 a deployment or an installation takes place?

Therefore, the entire team must work overnight to make sure that everything is smoothly transferred into a new version / new build.

Advantages of Monolithic Applications

💠 Easy to test.

Integration testing becomes easy because we can write one test case since there are no dependencies. Can access everything from mock objects.

💠 Easy to monitor.

Because it is one application and you know the exact paths, it becomes easy to monitor the application.

Ref: https://images.app.goo.gl/3kFSYpg33CyC2nJg9

Microservices Architecture

Microservices is basically a practice or an architectural view that carries out some useful features that Service Oriented Architecture consisted of.

The definition of Microservices Architecture according to Martin Fowler’s Book:

“ The microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API.”

Ref: https://images.app.goo.gl/UnHxGjreATdCGFUJ8

Features of Microservices

Ref: https://images.app.goo.gl/8QbntmHZZJgtYVuM6

● Microservices have a dedicated purpose of living.( domain-driven development)

● Needs to have an exact well defined scope for microservices.

● Should run its own process; i.e: own web container

● Microservices do not depend on others.

● They can communicate with other services via light weighted mechanisms.

Ex: Mainly HTTP (But not limited to HTTP)

● Should be able to scale and deploy as individual services while maintaining a decentralized control as much as possible.

● Should be able to implement using different languages.

● Should be able to develop using a small team. (Usually the head count should be in between 8–12)

Let us consider the scalability of Microservices.

➞ X Axis : Cloning of data

Application should be able to scale out through x-axis. In case if one instance is not enough, you should be able to spawn another instance and keep going.

Clustering

Adding more data centers

⬆︎ Y Axis : Split by function, service or resource

Should be able to functionally decompose. Microservices come and fit there.

Individually Scalable.

⬈ Z Axis : Splits with lookup

Should be able to shard (Database Sharding)

Should be able to split out traffic geographically.

Ex: European customers are directed to European servers, Asian customers are directed to Asian servers etc.

How to develop Microservice Applications

● Each service should be able to use different languages.

Ex: If you use Java, you can use frameworks such as Spring Boot, Drop Wizard etc.

● Domain-driven design

You need to ensure that your service does not depend on other factors.

● Your service should be capable of removing from the system and plug at anytime.

● When deploying your service, you should not have a hard dependency to other services.

● Service resilience and fault tolerance must be implemented.

Ex: Assume you are going to invoke another service B from your service A. If service B is timed out/failed/not working, you should be able to maintain the situation. This is what you call as “Fault Tolerance.” We can achieve this through;

▸ Fail over mechanism

▸ Proxy

▸ Circuit breaker pattern

Requirements when you implement Microservices

● Should have a visibility from consumer to backend.

● You need to restructure your team and it should consist of people from;

▸ UI — User Interface

▸ DB — Database

▸ Java / Service Development

▸ QA — Quality Assurance

▸ BA — Business Analytics

You need to have a full stack team.

Aspect of implementing microservices and restructuring is to distribute responsibilities throughout the team.

Advantages of implementing Microservices

💠 If any production issue happens, the team knows what happened. Therefore, it is easy to understand and diagnose issues since a team consists of 10–12 members and these members are aware of entire service.

💠 Even though it is complex, the service is isolated. So, it is just your service. Therefore, downtime is reduced through fault isolation.

💠 Services are independently scalable.

💠If the development team feels like the implemented language is not doing as expected and the framework is outdates, it is easy to migrate into another language or framework as the service does not have any dependency to other services.

💠 Saves cost as it is on demand and elastic spawning can be applied.

💠 Maintaining communication among team members becomes easy as each team can have either face-to-face communication or across different global area.

💠Restructuring team is easy and a team must include all the expertise in different area of development.

Disadvantages of implementing Microservices

♨️ As we distribute complexity, it is hard to monitor the application. (Because this is not a single application, but multiple services)

♨️ Microservices take some latency to talk to other services.

♨️ It is not easy to test since your service is isolated. It would be really hard to execute integration testing.

♨️ Should pay attention to versioning and deployment because the dependent services may affect if you change your version.

Differences between Monolithic and Microservices Applications

Ref: https://images.app.goo.gl/dQtMM7wwKJKWkUwQ7

Microservices Applications

💡 Concept : You build it, You own it!

✹ Services should have a dedicated goal.

✹ Services should be able to scale independently.

✹ Services should be able to maintain by a separate team. And the team has the responsibility to your application.

✹ Services should be able to implemented in any desired language.

Ref: https://images.app.goo.gl/1iHMR8nstvFRMNwA9

References

--

--