The last couple of videos we've had have been just a bunch of lecturing for me.
I know that's super boring.
Just one more lecture and we're gonna start writing some code again in this video we're going to go
over the design of the event bus.
We're going to talk about how we can use the event bus to communicate events for one service over to
another as a reminder.
We're going to try to build as much of as this stuff as possible from scratch rather than using some
off the shelf solution.
And that includes the event bus.
So we're going to build this event bus on our own.
We're going to build it using JavaScript and express.
I want to give you a couple notes on how this thing needs to work.
OK so event buses the first thing to understand about them is that there are many different implementations
available.
You might have heard of terms like rabbit and Q Kafka or nets.
These are all different types of event buses.
They're open source projects.
You can download them and run them yourself or you can get some kind of pre hosted provided solution.
The one common thing between these different event buses is that they're going to receive events and
then publish them out to listeners when we use the term events here.
We're really talking about some piece of information.
There's no set structure of what a event has to look like.
It can be Jason.
It can be Rob bytes of data.
It can be a string.
It can be whatever you want to share between your different services.
When we use the term listeners we're talking about other services that want to listen to events that
are being emitted now between these different implementations of say rabbit and Q Kafka Nats and many
others that exist out there.
Turns out that there are many very small features available in these different event buses that make
some things a lot easier or a lot harder.
So in this larger application that we're gonna work on in the second half of this course I picked a
event bus that is really easy to get started with extremely fast.
But there are some downsides to it as well somethings that are going to make our lives a little bit
more complicated.
So you just need to be aware that you cannot just pick one these implementations off the shelf you kind
of have to evaluate them and understand what they can really do for you.
Now once again we are going to build our own event buses Inn Express.
It is not going to implement the vast vast majority of features that a normal event bus has to.
Ours is going to be incredibly simplistic incredibly simple not very useful outside this one single
implementation.
But again we're going to build this from scratch just you have a really good idea of what is going on
behind the scenes.
And yes again for our next application we're going to work on the much larger one.
We are going to use a production grade even bus.
This is an event bus that is used in many many very large deployments and projects.
So you're going to get some very practical experience with some real technology as well.
All right.
Let's talk about the Express based event bus that you and I are going to put together.
Now this really is a very simplistic implementation for event bus.
The reason we are doing such a simple implementation is just you can see how this stuff kind of works
behind the scenes.
And so you can very easily see the flow of data throughout our application.
Let me tell you about how this thing is going to work we are going to add in a new route to our postal
service intercom in service.
We're also gonna make sure that our query service has a very similar route as well.
Each of these routes are going to watch for a post request to a path of slash events.
We'll talk about the purpose of that in just a moment.
At some point time inside our application we're going to have our postal service or common service decide
that it needs to emit an event whenever a service needs to emit any event it's going to make a post
request off to this new event bus that you and I are going to put together again this event bus right
here is going to be a plane express application.
Essentially we're really just doing a post request from one service to another in that post request.
We're going to attach along some event data so it's going to be some object that represents this event
right here this event bus is going to receive this event that's going to take that event and make a
series of post request with it.
So it's going to take all that event data and it's going to take that exact information and just send
it off to a post request to local host 4000 slash events.
That would be our postal service.
That's going to make an identical request off to a local Post four thousand one slash events.
And same thing or local localized 4000 to social events.
So in all three of these post requests it's going to send along this event data so in short any time
one of our services makes a post request over to event bus event bus is just going to take that exact
information and throw it out to everything else that we have running inside our application even the
same service that emitted the event originally so that's it.
That's how simple our event bus is going to be.
Now again as we start to use some more production ready application or solutions here for the event
bus you can see that there's a lot more to this implementation.
But at the end of the day this is pretty much what is going on more or less we're throwing an event
over to the event bus even bus is just going to echo that event back over to all of our different services
now that we've got an idea of what's going on here.
Quick pause.
We're going to start building this event bus which is a very simple very straightforward in the next
video.