Before understanding the Microservices architecture, we need to understand what is the traditional approach and what are its problems.
In a client-server model, the server-side application follows monolithic architecture i.e. it is a single large unit that performs everything. It acts as a single unit that handles the HTTP requests, executes business logic, performs database operations, reads files etc.
Drawbacks of Monolithic Architecture
- A small change to a particular component of application may require building and deploying the whole application again.
- If a particular component fails, the whole application may go down.
- If we wish to scale some components, we may need to scale the whole application instead of just the components.
- Not easy to use multiple technologies and multiple programming languages for a single large project.
What is Microservices Architecture?
Microservices architecture breaks large software projects into loosely coupled components, which communicate with each other through simple APIs. Each component is responsible for handling its own defined tasks and to communicate with other components through simple and universally accessible APIs.
The most important thing to consider now days is SCALABILITY and one of the most frequent asked question is: Is your application scalable?
Advantages of Microservices Architecture
- We can choose any technology or programming language to build a particular component.
- Each service can be build and deployed independently.
- If we need to re-build a particular component, we don’t have to stop or deploy whole application, only that particular component needs to be fixed.
- Failure of single component will not crash the whole application.
- Scaling components will not disturb other components and application as a whole.
- It is easy to add more components and maintain them.
- We don’t have to depend on a particular technology stack.
Disadvantages of Microservices Architecture
It is not necessary that everything new is always good. We have to carefully decide before choosing a particular architecture. Here are some problems we can face with Microservices architecture:
- Managing a distributed system is always a bit complex. We have to take care of every request between modules and may need to write additional code to handle failure of components.
- The request between multiple independent components adds delay to final response.
- Testing a microservices based application may be difficult because of involvement of multiple technologies and programming languages.
- Deploying microservices may be complex and is not as straight forward as uploading your files to FTP server.
With the right kind of automation tools, above discussed disadvantages can be handled.
How does clients of microservices find the location of service instances?
Service Registry comes into the picture. It is a database of all microservices, their instances and locations. Service instances are registered when the Service Registry is started and de-registered when Service Registry shuts down.