Microservices Application
Microservices Application
=======================
Monolithic Application:
=======================
- One application that contain multiple modules but finally (build as a one
application or one .war file or one component) deploy as a one application.
(Or)
If we have multiple modules/ services and all modules/services integrate into a
single unit or single application that type of application is called monolith
Application.
Example:
Amazon application have multiple modules/services like, search, cart, order, track,
payment ….. etc.
Note:
1. When use Application => then use the word “set of services”
2. When use project => then use the word “set of modules”
Advantages:
- Development – When an application is built with one code base, it is easier to
develop.
- Easy deployment – One executable file (jar, war) makes deployment easier.
- Simplified testing – Since a monolithic application is a single, centralized unit,
end-to-end testing can be performed.
- Easy debugging – With all code located in one place, it’s easier to follow a request
and find an issue. (Checking the code for issues).
Microservices Architecture
Disadvantages:
- Slower development speed – A large, monolithic application makes development
more complex and slower. Because when we develop application must follow
some sequence of order to develop Application Modules. Because one module
can depend one another module. So, in this situation complete one module then
develop next module.
- Scalability – You can’t scale individual components/services in Monolith
application.
- Reliability – If there’s an error in any module, it could affect the entire
application’s availability. Or if single point is failure, then hole application down.
- Barrier to technology adoption – Any changes in the framework or language
affects the entire application, making changes often expensive and time-
consuming. (It is not easy to add new modules as size of application grows slowly
and time consuming for development and deployment).
- Deployment – If we make small change in a monolith application, the entire
project will compile, entire project should be package and requires the re
deployment the entire application monolith.
=================================
Microservices Architectural Application
=======================================
- Microservices is an architectural design pattern. To develop every service as
separate application or separate executable application nothing but REST
application. So that we can active or deactivate services as per our needed. And
every service connected each other using webservices.
- Since each service is develop as separate REST app. So, we can take more
instances for busy service and less instance for often used services.
Microservices Architecture
Example:
Since, in e-commerce Search service will be have more traffic and more requests from
more users, for that we need more instance. And only 60% to 50% users add product to
cart so for cart service we take less no. of instances and only 20% users generally go for
payment so, we need more less no. of instances for payment service as needed.
Advantages:
- Flexible scaling – If a microservice reaches its load capacity then we can increase
or decrease instances.
- Reliability – If one functionality is failure then will not affect other functionalities.
- Highly maintainable and testable – Easy to add new features and test them easily
- Independent and autonomous – Ability to use each service in different projects.
- Technology Independency/Technology flexibility – We can develop multiple MS
using multiple technologies like one MS develop using java and Another MS
develop using .net.
- Resiliency – if one service is down, then going to other service.
- Independently deployable – Deploy without stopping other services
Disadvantage
- Big challenge is Cost and Maintenance.
To Achieve Microservices benefits we can use the following MS design patterns
1. Database per Microservice
2. Event sourcing
3. CQRS
4. Saga
5. API gateway
6. Externalized configuration
7. Circuit Breaker
8. Consumer driver contract tracing
Microservices Architecture
=======================
Database per Microservice
=======================
Cloud:
- Without buying the hardware resources if a customer can use hardware
resources(service) of vendor, on demand of customer, access through the
internet.
- On-demand
Any time, any whare customer wants to access service of vender through
the internet.
Advantages:
- Cost benefit (we are not buying any hardware)
- No upfront cost (Before not starting our business we are not paying any cost)
- Pay for what we use
- Purchasing options
Pay after use
Prepaid option
Installment is also possible (partial payment)
- Automation options
AWS cli
AWS formation
- Global availability
Cloud Providers:
- Amazon web services
- Microsoft Azure
- Google Cloud Platform
- IBM Bluemix
Example:
Microservices Architecture
Google is vendor or service provider. They provide several services like google drive,
Email… etc. if we want to access those services first, we need to create an account. Then
we can access those services.
So, google provide 15gb storage as free if we need more then 15gb storage then pay for
extra storage. So, we need no buy any hardware of HDD drive for this extra storage.
---------
Terms
---------
Compile: Converting .java file to .class file
Build: All .class file in our project, packaging into .jar/.war
Deploy: Place WAR under server and starter server
Instance: A Running server with project (successfully)
Load: No. of Request (Incoming Request) to server
Load Factor: No. of Request / Total Capacity (0 < LF < 1)
Test: Executing JUnit test cases.
Scalability
1. Horizontal Scaling
Creating multiple server instances for same type of application (or) running
the same application instances multiple time in different servers.
Microservices Architecture
2. Vertical Scaling
Increasing the configuration of the system like network capacity, DB
capacity, storage capacity, processor capacity… etc.
Load Balancer
- In case of Multiple instances exist (i.e. Horizontal Scaling) for application then we
need one Application Load Balancer for distribute request of application into
multiple servers.
Note:
- Service – A Part/ Business Unit / Component of a Project that provides set of
operations as a one project.
- Instance of service – means a running copy of the app/service (or) a running
server with project.
-