We're now going to take a look at a second option for adding in this moderation service and adding in
some events to support it.
So Here's option number two option number two is can you very select two option number one with very
one very small difference as a matter of fact option number two is probably what you thought.
Option number one was going to be OK.
So let's walk through it.
We're still going to have a user submitted come into the come and service.
We are still going to have to common service emit an event of something like comment created the event
bus is still going to send that event off to the moderation service.
But now we're going to also have it go off to the query service and actually be processed by the query
service.
So this is similar to what is going on inside our application right now without adding in this moderation
feature as soon as the query service sees come and created.
We're going to have the query service persist some information about that comment and critically it's
also going to have a default status of something like pending the query service is going to instantly
know about this comment even if it takes some amount of time for the moderation Service to process and
actually moderate the given comment.
So now we can imagine that if a user goes over to application and they enter and a common right here
and hit submit we're going to be in instantly emit comment created and that event will instantly go
over to the query service in the query service will have this record of the comments.
So as soon as the user refreshes the page in theory they will see that coming up here right away.
And because we know its status is pending we can show a nice little and a picture of that thing.
Something like this right here or a nice little something note that says this comment is awaiting moderation.
Now of course we still want to go ahead and moderate this comment so the comment created is still going
to go to moderation service and at some point in time in the future maybe seconds months who knows what
it will still continue to leave it.
You met an event of something like comment moderated this will go over to the query service query service
will see it and update the status of that given comment to approved or rejected or whatever it needs
to be that's option number two.
This definitely solves the issue of a user submitting a comment and not immediately seeing it appear
on the screen but it does also in a persistent issue that we did not discuss about option number one.
It's an issue that's present in option number 1 And option number two as well.
So let me tell you about what the issue is that is common with one and two I want you to really think
about the query service right now and once job is that query service is all about presentation.
Logic is a matter fact its name is query service.
It's about making a query or storing some data and serving that data up very quickly to users.
So right now it's really joining just two resources just the posted comments.
But at some point time in the future we could totally imagine that there might be other resources that
it joins together as well such as maybe upvotes downvotes images.
Who knows what else this query service might take many different resources and jammed them altogether
and that's what this query service is really all about.
So quick question for you.
Does it make sense for this presentation service to understand how to process this very precise update
to a comment like a comment moderated event.
Does it make sense for the query service to understand how to process event like this.
Well right now it's kind of easy to say yes because the common moderated event really just means go
and find this comment and update updated status to approved or rejected or whatever else.
So processing this event very simple and straightforward in nature it's one line of code more or less
what I want you to think about a real world commenting system.
Think about all the different ways in which a real world commenting system or a real world comment might
be able to be updated a real world comment you might be able to moderate it.
You might be able to upload it to downvoting you might be able to promote it.
So maybe a moderator or someone in charge of a Web site can say this is a really high quality comment.
I want to boost it up towards the top of all the comments.
You might be able to make a comment.
Anonymous you might be able to flag it as searchable.
You might be able to market as an advertised comments like a comment that someone paid money to promote
in some way.
Each of these different precise updates to a comment has some very precise business logic associated
with it to update the definition of that comment.
So if we continue down this line of saying that our where a service is going to be able to process this
comment my moderated event we're essentially saying that somewhere down the line we might end up in
a scenario like this one right here where the query service needs to understand how to handle this multitude
of different possible updates that can be made to a comment.
And you can easily imagine that if there were other services like our query service maybe something
to process weekly updates for popular blog posts or maybe something that functions as a recommendation
service.
And if those had to store the idea of what a comment is as well.
In theory they might also have to handle these events.
And so we start to get into this scenario where every possible way of changing a comment has to be handled
by a ton of different services.
And as you can imagine.
Yeah.
This is not even remotely what we want.
So even though this all works and this is a more or less viable approach for our current application
as it stands right now I'm going to suggest that maybe it's not the best solution.
So we're going take one more pause.
Come back the next video and discuss option number three.