Evolution of Microservices

Chandima Jayamina
6 min readMay 27, 2021

Before microservices we had monolithic application which we build on top of an operating system. Normal banking systems, Collage student enroll systems etc. But with the improvement of technology businesses grows worldwide. For example online shopping carts, Online forums there were some requirements that can not satisfied by monolithic applications. Thats where microservices came to stage.

Monolithic Applications Cons And Pros

In monolithic application we have a single executable file for entire application.

Cons

  1. If we have to do a change then we have to unzip the entire application and go through the code base for do the changes. When we do the testing we had to test entire application.
  2. We have to maintain huge code base some times 100 engineers may be in one project.
  3. When we have to transfer into new version, in that case entire team has to work on for this to ensure application smoothly running down.

Pros

  1. Single test for entire application.
  2. Easy to monitor the entire application.

Micro services (soa2.0- service oriented architecture)

Microservices are domain driven development, These services has exact define scope. These services has its own processes, These processes should not depend on other processes. If the processes depend on other processes then the actual value of microservice is not achieved. Services can communicate with other services by using light weight way mainly use HTTP. Services can deploy and scalable as individual services. In microservices we should maintain decentralized control as much as possible.

So according to these factors before going to microservices we have to look what we have to use for the implementation. So according to software requirement we have to choose what we have to use monolithic design, microservice design or hybrid solution.

Evolution of Microservice Architecture

Stage 1

In the first stage we had independent machines which run a service on each machine.

maintanace, power , memory allocations unused spaces eg database.
3 different servers 3 different physical hardware boxes
space, network, maintanace, waste

Cons:

  1. Hardware maintenance costs, power, unused memory spaces.
  2. OS License, maintenance costs for each machines
  3. Physical space.
  4. Network maintenance costs.

Stage 2 — hypervisor

In here we have single high processing hardware box. On top of that we have a hypervisor. On top of hypervisor we create multiple virtual machines. Each virtual machine has OS and we install the services on top of that. In this design we are able to use one hardware component.

Pros:

  1. Waste of hw is less we can allocate them according to services.

Cons:

  1. OS License, patches, maintenance update costs.
  2. Bootup time for each services.

Stage 3 containerized application

In here we have Single high processing hardware box. On top of that we have one operating system. On top of that we have docker engine. On top of docker engine we have multiple docker container which contains the services. In her docker containers able to docker containers share all the storage, cpu cores and other hardware components.

Pros:

  1. From this design we can mitigate patching updating license and maintenance costs.

Why Docker

Docker is open sourced project which is implemented with go language. Docker no need separate OS, separate VM, no multiple license, patching which others required.

One of the main advantages is there is no bootup time because OS is already started. : ) Docker gives orchestration, security, all the services which needs for microservices. Lets talk more about docker with another blog. Which is not our main topic.

Best Practices and Design Patterns

Discovery Tool

Microservices communicate with each other services. For communicate one service should have the URL of other services. We can hardcode the URL but if URL changes then we have to change the hardcoded URL each times. Thats why we can use discovery tool for our microservices. Discovery tools keeps the addresses of each services and when services want to communicate it gets the address from discovery service.

Aggregator pattern

Service chain pattern

In microservice for one task it has to go through multiple services as a service chain. For example In attendance marks we send a call to employee service and get the employee details and send a call to leave service and the get the available leaves marks the attendance.

Parallel aggregation pattern

In here when we take the above scenario attendence service send parallel calls to employee detail service and leave service and take the details and do the calculation.

Branch

In here according to the parameters it decide which service to communicate.

Circuit breaker pattern

In here if Service D is not responding(Cascading failures) so all the threads came to access D is waiting, So huge thread base is creating at service D and these threads wait until Service D response it is cascade failure.
What we can do is if service D is not respond within 200 milliseconds we fail service D. In here we use fail fast mechanism so other threads not wait.
If this service is critical service then it create huge thread stack below. What happens here is after service comes alive it tries to process all the stack at once and as a result of huge load this service will die.
In these scenarios we can give if more than three threads waiting to access service we fail the service so other threads will not create a stack below.
What circuit breaker do is in back end is it sends a ping message time to time and check service is back alive. If it is alive it give access to next thread trying to access service.

Proxy pattern

In here for one service we have two versions. Service 1.0 is the old one which works with the Emp ID. But the new service require the Emp code. So what we do in here is by using a proxy we send the service call to the correct service. In production we use this and give notification that we are going to remove service 1.0 near future. So from that consumers able to change their behaviors to new service. That's how we do the migration from version to versions.

Conclusion

In here we talked about what is the difference between the monolithic applications and microservices and we discuss the evolution of microservice architecture by resolving cons. And we discussed the industry best practises and design patterns in microservice based applications. There are more to discuss lets meet with new blog hope this gives some knowledge for you. Thanks for the time. :)

--

--