Event-Driven Architecture

Learn how asynchronously emitting and consuming events at scale works and take a look at different messaging services and frameworks.

As applications become more and more distributed, many are looking to more event-based systems. Rather than services communicating directly with each other, polling for new work to do and generating a bunch of chatter, applications are instead publishing a change in state to a message broker which services can listen on. These changes in state are often referred to as “events”.

Consider the scenario of an online shop. When a user places an order, several internal services will probably need to know about it. The payment system will need to process the customer’s payment details, the shipping service will need to begin generating the resources to send the customer the product, the inventory service will need to be updated, and so on. Not only is this additional load on our storefront, but it also needs to know where all of these services live and what to do if they’re offline at the time of a purchase. If a new service is added to this process, it also means the storefront needs to be updated to communicate with it.

img

Now, consider if the responsibility was flipped. In an event-driven architecture, the storefront would instead put a message out (traditionally on something like a message broker or event bus) saying “Hey, there’s a new order!”. Once that message is sent, the storefront doesn’t need to communicate any further with the backend services. Instead, these services will listen to that message broker for messages about new sales and take the appropriate action.

img

Furthermore, additional metadata could be added to these messages, for example in the case a customer needs to change a shipping address on a sale that has not yet shipped. In this case, only the shipping service would receive this message so that it could sort through all pending orders for that customer.

img

If you’re looking to get started with eventing, make sure to check out the guides below such as Getting Started With RabbitMQ, Getting Started With Kafka, or if you’re a Spring developer, Getting Started With Spring Cloud Stream. These guides will walk you through the basics of interacting with some popular message brokers and show what tools are available in these ecosystems.


Code Samples

Getting Started with Kafka

An example of how to connect to, send, and receive messages from Kafka.

Getting Started with RabbitMQ

An example of how to connect to, send, and receive messages from RabbitMQ in several languages.

Spring Boot RSocket Sample

Getting Started With RSocket On Spring Boot

Spring Cloud Data Flow Sample

Building Microservice Data Streams With Spring Cloud Data Flow

Spring Cloud Stream Demo

Simple Event Driven Microservices with Spring Cloud Stream