Our application is now in a pretty complete state.
So now we're gonna start to think about how we could take this app and deploy it online.
Let's first begin with a quick discussion about how our application is being executed right now on our
local machine.
So of course this is what is going on on your computer right now.
We've got post comments query moderation and event plus they're all running on some very specific ports
and each of them can reach directly out to the other services and send messages make requests whatever
is required.
It's very direct and simple communication between each of our different services.
So how do we somehow take this same kind of structure make as few changes as possible and deploy it
online.
Well a very easy way to do this would be to go out to digital ocean or NWS Microsoft asa or whoever
else and rent a virtual machine.
Once we get that virtual machine we can transfer all of our services over to it.
Like when I when I say transfer I really just mean copy our source code and then run each these services
in the exact same way that we are doing right now.
So we can have all the services communicating with each other by reaching out directly over local host
and trying to access port four thousand four thousand one and so on.
So this is definitely work.
Without a doubt but as we start to really think through this scenario and think about how we would grow
our application the future well life starts to get a little bit more challenging.
Let me show you what I mean.
Let's imagine for a second that our comment service right here is starting to become really overburdened.
Maybe we have a tremendous number of users coming into our application and trying to create comments.
And so at some point in time we might decide that we need to create a second or third instance of this
comment server just to handle this additional demand.
A very easy way to do that would be to say on the same virtual machine let's create two new copies of
that common service.
So we've got the original copy right here and two more over here whenever someone tries to create a
comment.
We can then load balance between these three different services.
When I say load balance I essentially mean just randomize which server their incoming request goes to
now there's a couple of challenges with this approach.
First off these additional copies of the comment service would have to be allocated some Newport on
this machine.
So maybe we would have worked four thousand six and four thousand seven right there.
That's relevant because remember art event bus needs to know the exact IP address and port of all the
different services that it's going to send events to.
So in other words as soon as we create these additional copies of the comment service over here we would
have to open up our event bus code and as a matter of fact I can do that right now.
Here's my event bus index dot J.S. file.
We would have to find where we tried to take an event and send it off to all these other running services
and we would have to add in two additional lines right here.
Something like maybe four thousand and six and seven.
Like so so if we follow this approach that we're going to start to couple or very directly tie the number
of services that we are running with the actual implementation of our code if we ever decide to increase
or decrease the number of comments service servers running at any given time we are going to have to
make a change to our event bus code and deploy that change as well.
And I bet as you can imagine that would probably not be too great.
This whole scenario gets even more complicated if we see that the comments services right here that
we added on are overburdening the one virtual machine we have.
So let's imagine for a second that we decide to get a second virtual machine and run those two additional
com and services on the second machine maybe they are still listed at North out port four thousand six
and seven.
But now the event bus not only needs to know or keep track of ports four thousand six and seven but
it also is going to have to have some code to figure out how to reach out to this other virtual machine
and eventually get access or send some events to the comment service right there and the CoM service
right there.
So once again we would have to open up our event plus file and rather than make your request to local
host we'd have to put in the IP address of that other virtual machine like so and once again I bet as
you can imagine that would be a really tedious finally.
Let's imagine a scenario.
One word just one more scenario here.
Very quickly let's imagine for a second that our Web site is very popular at just certain times of the
day.
So maybe at 10:00 a.m. in the morning a lot of people come to our Web site and they start to create
comments.
And so at 10:00 a.m. in the morning we would want to have these additional copies of the comment service
running but then maybe at 1:00 a.m. in the morning like at the dead of night maybe nobody is coming
to our application.
And so in order to save money on our hosting fees we might decide at 1 a.m. to temporarily shut down
the second virtual machine and just say hey no one's coming to our website.
We don't need those additional copies of the common service.
So let's just temporarily temporarily turn all that stuff off now in this scenario.
Once again the event boss needs to know that that second virtual machine is now dead and it should not
attempt to send any events over there.
Well to handle that we would have to come back over to our event bus and maybe add in some code and
say something like if it is 1:00 a.m. or I should say if it is not 1:00 a.m. then go ahead and attempt
to send the incoming events off to those other two services and once again has I'm sure you can imagine
this is definitely not something we would ever want to write out right here.
We would never want to say oh well if it's a certain time of the day let's try making requests over
to these additional copies.
So everything we're discussing now is really going down towards a very bad path.
We are trying to put together this event bus and have it communicate between all these different services
in a very direct and imperative fashion.
We're trying to say he event bus you need to keep track of all the different services and you need to
make sure that you always send every incoming event to every service that is running and you need to
keep track of whether or not they are running.
This is all just over the top.
Complex way too confusing and there's probably no way we would be able to pull this off very easily.
So I think it's pretty clear at this point that although what we have right now is working on our local
machine it would probably not work in the long term.
We need a better solution.
We need something that's going to keep track of all the different services that are running inside of
application has the ability to maybe create new copies of a service on the fly and make sure that we
have something as well that can automatically figure out whether or not a service is running and whether
or not we should maybe tried to make contact between two given services.
So this is all going to lead us into a really big discussion in this section in all the next coming
videos around two big open source technologies called Docker and Cuban eddies.
They're going to take a pause right here.
We're going to come back next video and have a quick discussion on Docker.
We're going to get a little bit more familiar with it and then do the same thing with Cuban cities as
well.