Getting started with event-driven architectures

Fran Méndez

Fran Méndez

·4 min read

All developers, architects, and product managers are used to REST APIs and the synchronous paradigm of communication. You make a request and wait for the response. This is exactly how the web works. You enter a URL (e.g., google.com) in the address bar of your favorite browser and it sends a request to the server. Following, the server sends the response with the content of the website. The web is the greatest implementation of a REST API.

However, there are certain situations when you don't really need a response from the server. At least no other than the confirmation the request has been received. This is also called "fire and forget", and it's really useful when you just want to communicate or inform that "something happened." It is, you're not requesting or asking for anything, thus you don't need a response. Examples of this are:

  • A user just signed up.
  • You have a new follower.
  • Your fridge is getting empty.

Along with the event, you may also want to send extra information. For instance:

  • A user just signed up: here's the user information (e.g., name, email, age, etc.)
  • You have a new follower: here are the details of the follower (e.g., username, name, picture, etc.)
  • Your fridge is getting empty: here's the percentage of "emptiness" (e.g., 23%)

This extra information is often referred to as event payload or message payload.

Core concepts

In most cases, Event-Driven Architectures (EDAs) are broker-centric, like in the diagram above. In it you can find some new concepts, so let's go through them now.

Message broker

A message broker (or "broker") is a piece of infrastructure in charge of receiving messages and delivering them to those who have shown interest. They often store messages until they are delivered, what makes EDAs very resilient to failures. Examples of brokers are RabbitMQ, Apache Kafka, Solace, etc.

Publisher/Subscriber

A publisher (a.k.a. producer) is an application that sends messages to the broker.

A subscriber (a.k.a. consumer) is an application that connects to the broker, manifests interest in certain type of messages, and leaves the connection open so the broker can push messages to them.

Message

A message is a piece of information that's sent by the publishers to the broker, and received by all the interested subscribers. The content of the message can be anything but they are frequently catalogued as events and commands. As we saw above, events communicate a fact that occurred. Instead, commands are very much like requests in REST APIs: they tell the subscribers "do this".

Technically speaking, events and commands are the same. The only difference is in their semantics.

Channels

One detail that might pass unnoticed from the diagram above is the existence of channels. All the brokers support communication through multiple channels. The industry doesn't have a common term though so you may find them as topics, routing keys, event types, and probably other ones I'm missing.

They're usually assigned a name or identifier (e.g., user_signed_up) and it's often a good practice to send a single type of message through them. Think about TV or radio channels: the BBC only broadcasts its information through an assigned channel. If the broadcasters (publishers) didn't respect that rule you (the subscriber) would only see and hear interferences.

Why "event-driven" and not "message-driven"?

You will find both used interchangeably, although they are not exactly the same. You will even find "message-based" and "event-based". In practice, chances are they all refer to the same thing.

Theoretically, "message-driven" is the most generic term, meaning you may use events and commands, while event-driven means that it's purely about events. However, that's not always the case, as Martin Fowler explains in his talk "the many meanings of event-driven architecture":

Conclusion

We've seen what an event-driven architecture is, how it works, and what are their components. AsyncAPI is all about defining and documenting each of these components.

Check out our getting started guide to learn more.