We're not going to go back over to our common module and inside of all the different events we have
great inside of here.
We're going to make sure that we communicate the version number inside of these things.
So for example in the case of ticket updated along with some information about the ticket that was just
updated we're also going to include this ticket's version number and that is was going to eventually
help us make sure that we process these events in the correct order before we add in this version number.
However I want to try to answer a question that you might be asking yourself right now that question
might be something like this when should we increment or include the version number of a record with
any event should it be all the time.
Should every single event that ever talks about some record always increment version number or always
included.
Well the answer is No.
We're only going to worry about incrementing or including the version number of a record whenever it
is the primary service responsible for a record that is emitting an event to describe that record either
being created updated or destroyed.
Now this rule alone by itself doesn't really make a lot of sense and I don't think really answers this
question.
So let me just show you a hypothetical scenario back inside of that blog post application that we worked
on much earlier inside this course.
And when we walk through this hypothetical scenario I think you're going to understand this answer a
little bit better OK.
So here's the blog post application we're looking just at the comment service moderation inquiry to
remember how this thing works.
Whenever a user came to the comments service to create a comment we would emit an event of comment created
and that would go over to the moderation service and the query service the moderation service would
then moderate the comment in some way and it would emit an event of comments moderated.
That was only received by the comment service the comment service then process that update events and
they said OK I need to somehow moderate this comment or handle the moderation event and it may have
made a change to the content of the comment the comment service would then emit a follow up event of
comment.
Updated and that would go on down to the query service and the query service then knew.
OK.
This thing has been moderated.
We are all good to go.
That was the flow of events back inside of that blog post application.
Now I want to imagine what would happen if we did not follow this rule right here if we said that any
old service can increment the version number of a record whenever it felt like it.
So here's what would happen.
We can have our comment service and we're going to imagine that this thing is going to publish this
comment created event and it's going to include a version number by default version zero.
That's going to go back to the moderation service and query service now the moderation service will
once again do the moderation and then it's going to MIT comment moderated and we're going to say for
just a moment that we are not going to follow this rule.
It's going to show you what we should not do.
This is not what we want to do at all.
They're going to say that when the moderation service kind of processes this comment the moderation
service might think oh well I've kind of done some processing on this comment.
I've kind of update it in some way.
So you know what I'm going to update the version number and again that's not what we want but let's
just imagine it happens for a second.
So I'd put on a version number of one.
So now this event was processed only by the common service.
Remember that was not processed by the query service at all.
Now the comment service takes a look at that thing.
It says OK the comment was moderated.
I'm going to process this and I say this comment has been moderated and then eventually emit the comment.
Updated events presumably as a part of the comment service processing comment moderated.
It will presumably also see that has a version number of one.
And so when common service emits common updated we're going to assume that in turn it decides to take
that version number add one to it and then emit that as the final update.
So inside Come in updated we would imagine that this thing would have a version of two now think about
this solely from the query service perspective.
We can forget everything else that's going on here and just think about it from the query service perspective
the service has now seen a events of common created and had a version of zero.
So record being created fantastic let's save that record internally inside of query service.
And now the next event that the query service would expect to see should have a version of one but that
never comes because the record that tried to say hey here's version 1 never got received or processed
by the query service.
And so the next event that this thing was received would have a version of to the query service would
say oh obviously on a version one.
So I'm going to reject version two and not process it until I eventually receive an event a version
one.
Well naturally it's never going to receive version 1.
So the query service is now going to be stuck and never be able to process this event right here so
all this could have been prevented if we followed this rule right here and we said that only the primary
service responsible for record is going to be in charge of incrementing a version number.
So if we apply that rule we would have said that the current created event right here at the version
0 moderation service would have sent back comment moderated and it would have not included some incremented
version number it can include the version number.
No problem there.
It can include the version number but we would definitely not have this other service or the service
that is not truly in charge of comments increment the number.
Now the com service would receive comment moderated it would do some processing it would update comment
internally and now the new version number of one common service would emit come an updated would have
a version of one and now query service and see version zero version one no problem let's process this
right here version 1.
So long story short we're gonna make sure that only the service that is responsible for a record like
the actual definition the true canonical definition of ordered a record is is going to be responsible
for incrementing and including that incremented version number.
Now again this diagram here might be just a little bit misleading because I put the word include it
is OK if other services include the version number and as a matter of fact we might want to have them
include that version number as we just saw here at the moderation service told you okay to include the
version number.
What we're really talking about right now is whether or not this other surface increments that version
number and the answer is no not at all okay.
I apologize for the long aside.
But as I mentioned I thought this might be a question you had especially as we go into our common module
and start to include the version number on all these different events.
Let's take a pause right here and actually update this thing in just a moment.