Real quick note if you skipped over the entire react application chances are you downloaded the completed
code from the last lecture.
If you did so make sure you read the text note inside that lecture but you need to make sure that you
overwrite your entire current project with all the code from that zip file.
We made two small changes are really one small change in two locations to the post service.
Andy comment service you need to make sure that you get those updates after you update those files.
Make sure you rerun npm install in the post and Commons directories.
OK so let's get back to it.
The last video we finished up with the react application and we saw that while we were able to see all
of our different posts and comments associate with them there was a downside here and the downside is
that for every single post we load up we are making one request to our common service to get all the
comments associated with that post.
In my case I've got three posts right here and I ended up having to make three separate requests to
our common service to get the comments for each one so in other words we're in this kind of scenario
right now.
We are making a GET request to some post end point that's giving us back an array or less of posts and
then for every one of those we have to make a follow up request.
This is incredibly incredibly inefficient.
So I think that would really be worth our time to figure out how to maybe condense all this stuff down
to just one request.
I want to yield to make one request one single request and get all of IRC posts and all the associated
comments for those posts as well.
That's what I want to try to do now.
If you're trying to do this in a sort of monolith architecture this would be really easy and straightforward
to do so if we were building a monolith right now we could maybe say that if we ever make a get request
to slash posts and add on a query string that says something like comments equals true maybe that would
be some sign to our model a server that we want to get a list of our posts with all of the relevant
comments embedded in those posts as well let's be super straightforward super easy with a moderate approach.
But of course we're not using a monolith.
How are we going to solve this with what we have available.
How we can solve this with micro services.
Right now we only have the ability to make a request to either the Postal Service or the common service.
So we need to figure out some way of solving this problem well to solve this.
This really goes back to something we discussed a little bit ago the different styles of communication
between services are going to take a look at two possible solutions here and the pros and cons about
these solutions are going to be very similar to those methods of async and sync communication and we
discussed a little bit ago.
So a first began with a solution based on synchronous communication with this tile solution.
We might say that we are going to continue to make a get request to our post service and then maybe
to make sure that we get all the relevant comments embedded.
We could add some code to our post service to reach out automatically to our comment service and say
hey give me all the comments you have associated with these post ideas the common service would then
reply with all the relevant comments.
Then the post service would take those comments assemble them all together with the relevant posts and
then send the entire bundle back over to the browser.
So again this is one possible solution that relies upon synchronous communication.
The downsides to this approach are identical to the downsides we discussed earlier when we are first
talking about synchronous communication.
So while this approach is conceptually pretty darn easy to understand well there's a lot of downsides
to this approach as well.
First off it introduces a dependency between these services.
This is another thing we have to track and understand inside of our application if we ever have the
comment service go down for any reason.
So if this thing just mysteriously disappears all of a sudden our post service is probably not going
to work correctly either if that request from the Postal Service over to the common service fails then
the overall request is going to fail as well.
So we will show neither posts nor comments.
We also are introducing another kind of round trip request here between one service and another.
So if for any reason that request is slower than the overall request coming from the browser is going
to be delayed or the response is going to be delayed as well.
Once again we discussed this back on the synchronous communication stuff.
Right now our application just consists of two separate services but if we started to add in a bunch
more services and for some reason fetching comments from the common service required some calls to other
services we're gonna start to build up this tree or really a web of different requests which really
exaggerates all these earlier problems as well so even though this is conceptually easy for you and
I.
It is perhaps not the best solution from an engineering standpoint now that we have taken a look at
the synchronous communication approach.
Let's pause right here and then take a look at a second possible solution that we could use.