In recent years, micro-service is getting popularity and is a buzz word in IT/Software industry.
Micro-services are an architectural style or an approach to build IT systems as a set of business capabilities that are autonomous, self-contained, and loosely coupled. Its used to achieve agility, the speed of delivery and scaling.
Many organizations such as Netflix and Amazon used this technique to functionally partition their applications into smaller atomic units.
Micro-services originated from the idea of hexagonal architecture. Hexagonal architecture is also known as the Ports and Adapters Pattern.
Hexagonal Architecture >>
Let’s take an example of an E-commerce application. In a typical monolithic architecture, all modules are part of the same project/package and are connected with single database technology as shown in the architecture above. Here are some of the problem, which developer and business were facing with Monolithic architecture over the period of time:
- In older and large applications, codebase increased over the period of time and it takes ages to build and deploy.
- There is a technology constraint with the application, new features have to be developed with old technology stack, or it requires a huge amount of effort to upgrade the version or using latest tools and technologies available.
- Each module is tightly coupled with other modules, so if you change one module it will impact the other module also, so maintaining the monolithic applications are more error-prone.
- When you make a change in any module, whole application has to be built and deployed again.
- You can’t scale only one section of the application. For example, in an E-commerce application, search and browse catalog usually have the highest load, in the monolithic approach we can’t only scale these two services only, we have to scale the whole application on separate server instances behind a load balancer.
In traditional monolithic application, we build a .war or .ear and deploy it on an application server like Tomcat, JBoss, WebLogic, WebSphere etc. In micro-service architecture, each micro-service will be built as a jar, embedded with all the dependencies and run as a standalone Java process.
Micro-services may also have their own containers for execution. Container technology like Docker is an ideal choice for micro-services deployment.
Benefits of using micro-services:
- Can use different architecture, technology and version of the technology for each micro-service.
- Enabling experimentation and innovation. for example, recommendation engine, where we keep changing the recommendation algorithm.
- Elastically and selectively scalable, we can select only the selected service where application receives the highest load. For example: Search and Catalog section of the e-commerce application.
- This enables building up an organic system, where we keep adding the feature in an agile way over the period of time without impacting the existing system.
- This helps in reduction of technology debt, we can change/upgrade technologies with much lesser effort/impact as compare to monolithic.
- It supporting event-driven architecture, for example: In e-commerce when an order is received various service has to be invoked like: save order, update inventory, send email/SMS/push notification, data analysis, delivery etc.
- Micro-service are the key enabler for DevOps. It advocates automating as much as possible, for example, continuous integration – testing, automatic infrastructure provisioning, automatic build, automatic deployment etc.