Hello, everyone.
This is Saurabh from Edureka.
And today we are going to focus
on what are Microservices. So
without any further ado
let us move forward and have
a look at the agenda for today.
So these are the topics
that we'll be covering today.
We'll Begin by understanding
why we need Microservices
which is right everything
exists for a reason.
So we'll try to figure out
why we need microservices
right then we'll focus
on what is Microservices
architecture and what
are its various features,
then we'll understand
various advantages
of microservice architecture
and we'll look at companies
using Microservices
and finally there will be
a demo based on Microservices
in which we will
have three services
that will be communicating
with each other.
So let's move forward guys
and focus on why
we need Microservices
So before microservices,
we all know that there was
an architectural pattern
called more of the architecture
that was used.
All right, so there
are certain disadvantages
of that architecture,
but let me first explain you
that architecture what exactly
monolithic architecture means.
So basically in this
the entire software is composed.
In a single piece
that is designed
to be self-contained.
So what I mean by that
basically all the components
of a monolithic program
are interconnected
and interdependent or
in other words,
if I have to put it, I will say
that it will give you
a tightly coupled software
where each component along
with its Associated components
must be present
in order to execute
or compile the code.
So all of these components
are actually dependent
on each other.
So if you notice a definition
that is there in front
of your screen,
it says that
monolithic architecture is
like a big container right think
of it as a big container
where in all the software
components of an application
are assembled together
and tightly packaged.
Right?
So if you notice
that there is an example
in front of your screen,
so there's a
server-side application,
right which executes a domain
specific logic it will retrieve
an update data from the database
and at the same time populate.
The HTML view is
to be sent to the browser.
So it is basically
a big container or I can say
that it is not divided
into small small services
or not divided into
small small component.
So even these components
that are there are
pretty tightly coupled.
Right, so I'll give you
a better example of what exactly
monolithic architecture is.
Let me just move forward.
So let us discuss
a classic example
of an e-commerce website
like Amazon or flip card.
All right.
So everyone actually visits
these websites quite often.
So that's a perfect
example to you know,
explain you so let's understand
what monolithic architecture
exactly means with this example.
So as you see that
in basic e-commerce application,
we have common option
of customer service
right product service
and card service
which a customer can access
through their browser.
Right?
And when you
launch the application,
it is deployed as
a single monolithic application.
There's only one single instance
if you can notice
so we have customer service
product service and card service
and when you deploy
all these Services,
it will be basically
a single monolithic application.
Now, what you can do is
in order to scale it you
can run multiple instances
of this application behind
a load balancer right now.
Let me discuss few advantages
of this application.
So first of all,
it is very very simple
to develop, right?
As a goal of the development
Tools in IDs is
to support the development
of monolithic application.
It makes a development
really easy and One Direction
of all right now it is
pretty simple to deploy
because you have to deploy
the executable file
at the run time
to launch the application
that executable file can be
a word file is well nowadays
pretty simple to scale
as well because you know
in order to scale
your application.
All you have to do
is run multiple copies
of the application
behind a load balancer.
Now since everything
comes with its pros
and cons monolithic architecture
also has few major drawbacks.
Let's discuss about
them one by one.
The first disadvantage is
large and complex applications.
Now if you have
a large application
or you can see
with the increase in size
the application it becomes
really complex to understand
and modify such applications.
Right and as a result
development slows down
and modularity breaks down
over time more ever
because it can be
difficult to understand
how to correctly Implement
a change and due to that
the quality of code
declines over time.
Let's see what is
an excess Advantage.
So the next disadvantage
is slow development.
So what I mean by that
As the application
and the respective teams
grow the application
becomes difficult to understand
and modify right
because it's pretty huge in size
and there are multiple
teams working on it.
So it becomes really difficult
to understand and modify also
the larger the codebase
leads to slower ID,
which makes the
developers less productive.
So the code base is pretty large
because the entire application
is one monolithic
application, right?
There are not different
if it's overseas
present night blocks
continuous development.
So what I mean by
that a large monolithic
application is an obstacle
to frequent deployments.
Let me tell you how in order
to update one component
you have to redeploy
the entire application
which interrupts
the background task.
So if I have to take the example
of the e-commerce website
if I have to update
the card service,
I have to redeploy
the entire application
the entire application
which includes the customer's
always a product service all
the services, right?
So this is also
a chance that components
that haven't been updated
will fail to start correctly.
All right, because of many
dependency issues or anything,
right and as a result
the risk associated
with redeployment increases
which Discourages
frequent updates.
I hope you are getting my point.
Let's see what we have next.
So the next point is unscalable.
I know I've told you
that it's pretty easy to scale.
But let me tell you what are
the disadvantages when it comes
to scalability and in terms
of Monolithic architecture.
So each copy
of application instance
will get access to all the data,
right which makes
caching less effective
and increase memory consumption
along with input/output
traffic also different
application components
have different resource
requirements one might be
cpu-intensive right
while other might be
Memory intensive and with
a monastic architecture.
We cannot scale each component
Independence, right?
So if you can see the example
that is there in front
of your screen.
So here we have customer
service product service
and guard service
is one instance.
And this is how we
are scaling it.
Right if I have to increase only
the customer service after scale
of the customer service.
I have to do that for product
and cart Services.
Well right now it is
pretty unreliable as well.
Let me tell you
how so because of
the tightly coupled components
if one of them goes
down the entire.
System will fail to run
what I mean by that.
If one of my say
production over space
that will in turn
lead to the downfall
of my entire application, right?
And because all
the modules are running
within the same process a bug
in any module
can potentially bring down
the entire process more ever
since all the instance
of the application
are identical the bug
will impact the availability
of the entire application.
This makes the monolithic
architecture highly unstable
and unreliable the last and
the final point is inflexible.
So, how is it inflexible guys
with the monolithic architecture
becomes really difficult
to adopt a new Frameworks
and languages suppose
you have million lines
of codes written
with XYZ framework now,
it would be extremely
expensive in terms
of time as well
as cost to rewrite
the entire application to use
the newer ABC framework,
right even if that framework
was considerably better and as
a result there is a huge barrier
to adopting new technologies.
I hope you're getting my point.
So why is it very expensive
because you know,
you have written million lines
of code in some language now
you want to use
some other language.
So it becomes really expensive
and time-consuming task.
And even if the new language
of the framework is considerably
better but you know,
there's a huge barrier
in adopting such new technology.
So I hope you have understood
the various disadvantages
of Monolithic architecture. Now
is the time to understand what
exactly is Microservice
architecture. Microservices
also known as Microservice
architecture is
an architectural style
that structures and application
as a collection of small
autonomous Services modeled
around a business domain now
if I have to put it
in simpler terms,
basically it is
a self-contained process
which always different and
unique business capabilities.
Now, if you have
large applications built using
this architectural pattern,
it can be broken down
to small multiple Services
which together axis
one large system
but behind the scene,
it's a Microservice.
So what I am trying to say here
is we have multiple services
on all of these Services,
they don't share
the data structure,
but they will be communicating
through apis right the major
advantage of breaking down
System is now each microservice
can focus on only
one single business capability
which definitely leads
to a better quality and throw
and it's obviously becomes easy
for you to understand
when I explain you
with a example again.
I'm going to take
the e-commerce site example.
Now if you remember
in monolithic architecture
all the components were
in a single module,
but if you see here
with microservice architecture
all the components are divided
into separate modules,
which communicate
with each other using
a well-defined interface
usually rest our messaging
now the communication
between the microservices
is a stateless communication
where each pair of request
and response is
an independent transaction
and because of this
microservices can communicate
effortlessly moreover
in Microservice architecture.
The data is Federated.
All right.
So let me just break
it down for you.
Each micro service
is responsible for
its own data model
and data because of
which interaction with
each microservice is handled
by different instance unlike
in monolithic architecture
where we had only
one instance here.
We have multiple.
Standard for different
different micro services.
So we have three microservices
here, customer Microservice,
product Microservice
and card Microservice,
right each of them have
their own instances.
They have their own data model
and they have their own data.
So this is what exactly
Microservices architecture is.
Now, let's dig a bit deep
into its architecture
and understand what it is.
Now as you can see
in a Microservices architecture.
So this is a small independent
and Loosely coupled.
So let me just tell
you where it is.
So with these are multiple so
which is right.
These are pretty small in size
and they're independent
and Loosely covered now,
each of these Services
have a separate code base,
which can be managed by
small development team
and it is deployed
independently, right?
So this service will have
a code bases service
will have a code base.
The service will
have a code bit.
Similarly.
All of them will
have a code base
which will be not huge in size
and when you compare it with
the monolithic architecture,
all of these services
are running in one instance.
I hope you are getting my point
now basically a team can update
an existing service
without re building
and deploying the
entire application.
For example,
if I have to update
this particular service,
I don't have to do it
for the other services as well.
I can just redeploy
the service independently
now services are responsible
for persisting their own data
or external State
internal implementation details
of each services are hidden
from other services moreover.
They don't need to share the
same technology stack libraries
or Frameworks is well
write you getting my points.
They might not have
the same technology
or same libraries
of the same framework
and they have their own database
and things like that.
So they are pretty independent
from each other
besides for the microservices
themselves some other components
appear in typical
microservice architecture.
So let me just discuss that
so the first part is management.
So the management component
is responsible for placing
services on nodes
identifying failures rebalancing
Services across nodes
and so forth right then let's
talk about service discoveries.
Now service Discovery
the task of this component is
to basically maintain
a list of services
and which nodes are located
on it enables service look up to
find the endpoint for a service.
Let's talk about API
Gateway now, right?
So API Gateway is
basically the entry point
for So this client won't call
all the services directly
write will first go
to this API Gateway
which will forward the call
to the appropriate services
on the back end.
Right if I'm
a client I'll request
for this particular service
the nap to call the API Gateway
and which will in turn call
the service on the back end.
Now the API Gateway
might aggregate the responses
from several services and return
the aggregator response.
Now, it might be possible
to write a client request
for multiple services.
So at that time it
will aggregate the results
from various services and return
the aggregated response, right?
So, I hope I am clear
with the architecture.
Let us focus on
what are the features
of Microservices architecture.
The first feature
is small focused.
So what it means it
means that the aim
of microservice Architecture is
Simplicity, you know,
so that it can be re-written
and maintained without
any extra efforts
by the development team, right?
That's what I mean
by small focused.
The next point
is Loosely coupled.
So as I've already
mentioned multiple times
at each microservice
is independent of each other
and do not need to code.
As well this makes a development
as well as a deployment
it real quick guys, right?
So if I have to update
a particular service,
I'll only update
that so which I won't, you know,
update the other services right?
That way deployment
becomes really quick.
So that's the big Advantage now,
let's talk about
language neutral.
So to be a good microservice.
It must be language nuisance
what I mean by that for example
in an application few Services
can be written in Python
for fast deployment.
Whereas few might
be written in Java
because its speed
and extensive libraries, right?
So depends on
the Microservices
what kind of programming
language we are using
so it doesn't really
affect the other services
right now bound it context.
So it means that
each microservice doesn't need
to understand the implementation
of other Microservices
so these are few features
of Microservices architecture.
Now, let's talk
about various advantages
of microservice architecture.
Now the firstly
independent development.
So each microservices
can be developed independently
where a single development
team can build test
and deploy service.
I think I don't need
to explain this much.
Development means
if I have a product service
and I can independently focus
on product service
where a team of developers
are writing code
for that particular
service testing it
and deploying it now
independent deployment means
that you can update a service
without having to redeploy
the entire application bug fixes
and feature releases
are more manageable
and less risky as
well because you have to focus
on one particular service.
You have to deploy
update one particular service.
You don't have to care
about the other service
or the entire application
as such right?
So next says fault isolation.
So it is a very
big Advantage guys.
It's basically if
a service goes down,
it won't take the entire
application down with it.
For example,
if my card service goes down.
My entire application
is largely unaffected
unlike the monastic architecture
where if one of my component
goes down the entire application
fails to work next is
mixed technology start
because of this feature teams
can pick any technology
which fits best
for their service right
and last but not the least
granular scaling which means
that Services can
be scaled independently
unlike my monastic architecture
where you know after
deploy multiple instances,
so in order The scale are I can
only scale a particular service
if I have to you know,
increase the card service
then I can just scale
up the card services
instead of scaling up
the entire application.
Let's let's move forward.
So there's a lot of companies
which are using Microservices
which is we have Amazon Netflix.
SoundCloud Twitter Who board
PayPal lot of companies,
right and why this happens
because the applications
become easier to manage
when they're broken down
into smaller composable pieces.
So without any further delay,
let's begin with our hands
on will be using spring boot
because it provides a way
to provide Java applications
quickly and simply
through an embedded server
and by default.
It is version of Tom cap.
It will basically eliminate
the need of java ee containers
and which springboard we
can expose component
such as rest Services
independently exactly is propose
any micro service architecture
that we have just discussed
in any mundane it's
of the components.
We no longer make the redeploy
of its consumers.
I'll tell you
what exactly I mean,
what is the consumer
for this lab will be use
Eclipse oxygen and Maven
three now to illustrate
the concept of SOB's,
what we'll do we'll create
three Maven projects
in this Hands-On and each
of them will symbolize back
and functionality or you
can say reusable apis and one
of them held a composition
that to put it in simpler way.
I will say it will be
a consumer of the other two.
So one application
or one service will be
a consumer of the other
two Services, right?
So we'll be creating
three simple Maven projects
that I've already done.
I'll just open my clips
and show you
that so my first Maven project
is basically diagnosed
with Microservices
then we have dr.
Microservice and we
have patient microservice.
So this doctor microservice is
the consumer right and consumer
the other two microservices
that is patient and a diagnosis.
Alright, so that is
how it is done.
Now if I have to explain one
of these Services,
let me explain
if the patient microservice
first so over here
as you can notice that we have
a bombed or XML file.
So basically this bombed
or XML file will stablish
all the dependencies right
before we start coding
the first class that we create
that we call application
will be identical.
All three product
and it only works as
an initiator spring boot
that we call a Spring
boot application annotation.
So that's how it is.
If you notice here,
we have application or Java.
So it will be common
application or Java
and application configuration
or Java the two packages
that we have created
will be common
for all the other
Microservices as well.
So if I show you a doctor's is
well now here also,
we have application or Java
and application conflict
or Java similarly
for diagnosis as well.
If you notice we have
both application or Java
and the other things as well.
Now we have patient
or Java and we have
patient rest dot Java, right?
So the patient Java here,
we have defined all
the variables like, you know,
the email ID of the patient name
and things like that
and this patient rest dot Java
will be used to provide
the input the variables.
I hope you are getting
my point but a patient rest
or job is basically
to provide the input.
I won't explain the code here.
In the upcoming tutorials,
I'll be explaining the entire
Microservice you know
how the code works
and everything all the technical
details you can find.
The next tutorial
and this I am just giving you
an overview of how things work
in Microservices and we have
this application config glasses.
Well right the package.
So let me tell you
why we actually use
it is basically it is
a resource configuration class,
which is basically
a resource manager responsible
for exposing rest services
for application consumers,
right so basically
for messaging right so
the rest services for messaging
and it is a stateless service
for application consumer
and we can notice
a patient or Java
and patient rest or Java are
in the same package right now.
Let me tell you
how I've defined a ports here.
So all I have to do
is right click go
to properties click
on run debug settings.
I'm going to go to arguments,
right so I just have to write
minus this over dot
Port 8:08 one so you can see
that my patient
Microservice is will be running
at a port a zero eight one
and I started let me just start
all these Services one
by one so I'll start this first.
Let's click on run a spring
boot app similarly click
on right click on this
and I'll just run it as
spring boot up again,
and I'll run this also
as a springboard app.
So does that now?
Let me just open my browser.
All right.
So this is for Port
8:08 one writes my poor
a zero eight one is for patient
to let me just click over there.
Let me reload this page again.
So here I have
my patient Microservice.
Similarly my port 8:08
to is for diagnosis.
Right so are high of
the diagnosis Microservice
and finally my port
8 0 8 3 basically is a consumer.
All right.
It's a doctor microservice
and in the URL.
If you notice I have written
patient ID right diagnosis
and consultation, right?
So basically we'll get you know,
this particular patient
has been diagnosed
with this disease and this
is the consultation right?
So, let me just reload
this again for you.
So I can just go ahead and
change the diagnosis as well.
I can make this
as to write sobre child
has been diagnosed
with a different disease now
similarly if I make it as one.
She has been diagnosed
with viral fever here.
Right?
So that is what
the difference is.
Basically this
particular Microservice,
which is a consumer of
the other two Services, right?
So you can even think of it
as an e-commerce application.
I know it's not of that level
but consider it something like,
you know customers
production orders.
So this patient Microservice
which will become
the order Microservice right
and the other two will become
customer and products.
So this order Microservice will be
a consumer of the product
and customers similarly
in this example
We have patient
and doctors, We have patient
Microservice and we have
diagnosis Microservice
and we also have
a doctor microservice,
which is actually a consumer
of the other two service.
So by this we come to the end of
this video editor a cup provides
online structure training
on Microservice as well.
So if you want
the detailed course curriculum,
you can go ahead
and mention your email ID
in the comment section.
They will reply you ASAP.
Thank you and have a great day.
I hope you have enjoyed
listening to this video.
Please be kind enough to like it
and you can comment any
of your doubts and queries
and we will reply them
at the earliest do look out
for more videos in our playlist
And subscribe to Edureka 
channel to learn more.
Happy learning.
