We were just taking a look at options or two and we eventually said that the issue with this approach
is that we are allowing our query service to have a very deep understanding of what this comment moderated
event is.
So to solve this we're going to have a comment moderated b instead processed by the comments service.
Let me show you how this is going to work out OK.
So in this diagram on the left hand side we've got our comment service and the query service the comment
service is the service that is ultimately in charge of exactly what a comment is and knows all the very
precise business rules all the business logic everything around what a comment is how to update it and
how to deal with it in some way.
And so it makes a lot of sense to have our comment service be the one that is responsible for some very
precise very well calibrated way of updating a comment whenever the comment service updates a comment
by handling one of these very specialized events.
We're going to have it emit one single very generic event called simply comment updated whereas all
the events on the left hand side meant that we wanted to update a common in some very specific way that
come an updated event says hey there's a new comment right here or a new version of this comment.
Don't worry about what the update was.
Don't worry about trying to interpret it.
Don't worry about trying to run some specialized business logic around it.
Just take these updated attributes and store them if you need them.
So we're gonna follow this pattern throughout all the services we've put together the service that is
in charge of a basic resource will be in charge of these various specialized updates and any time those
specialized updates occur that service will emit a very generic event update so let's take a look at
what this is going to look like for the services we are talking about right now.
So we're going to once again have a user submitted comment as soon as they do so we're going to have
our comments service versus that event and notably you'll notice that it now knows the status of that
comment as well.
The comment service will then continue to emit a comment created event that will go to the event bus
it will go off to our moderation service and to the query service as well.
So we're going to still solve that issue we ran into earlier where the query service didn't really know
that a comment was created.
And so that was where we ran into issues with the user submitted comment and then refreshing the page
were then going to make sure that the moderation service still processes that comment and moderates
it in some way.
So that's going to go off to our event bus and now it's only going to go over to the comments service
the comment service will be the only thing that knows how to process this very specialized update to
what a comment is.
So in this case we'll change the status around pending to approved then because the comment Service
just made a change to a comment a very specialized very domain specific change that will then you missed
a comment.
Updated event.
So this is a very generic event.
It just says Hey some attributes change.
Don't worry about what changed.
Don't worry about processing this in any way.
Just use these attributes if you care about it at all that will go off to the event bus the event plus
we'll send it off to the query service.
And now the query service is going to say oh a comment was updated.
I don't care how or why it was updated.
I'm just going to take all the different properties out of that event and I'm going to use those as
the basis for my new comment or for update this comment.
We're not going to necessarily just change that status flag.
We're just going to say take all those attributes and use them to update our existing comment.
That's it.
Now I know that this might seem a little bit challenging to understand this idea of having a domain
specific event in a very generic event.
Well you're going to see many examples of this on the later project.
We work on as well.
So don't worry you'll get a lot of experience with this over time.
So that's what we're gonna do inside of our application.
We are going to use option number three.
We're going to end up introducing two events.
One is going to be very specialized in nature that is going to be the comment moderated event.
It's going to be process by comment service and then as soon as comment service updates that comment
it's going to emit that generic event to say hey this comment was just updated.
If you care about it great use it in some way.
Now the upside to this approach is that the query service only needs to know about common updated even
if we start to add in a billion different ways of exactly how we can precisely update a comment query
service doesn't need to know that it just needs to know oh this comment was updated on is going to take
these attributes and use them OK.
So now we understand what we're going to do inside of our application.
We'll take a quick pause right here and start to implement option or three in just a moment.