Concepts of an Event-Driven Architecture Simplified

Concepts of an Event-driven architecture

The Event-Driven Architecture is an architectural pattern that helps build scalable and fault tolerant applications, learn more about the concepts of this architectural pattern in simple terms and examples.

Introduction

I came from a traditional Software Engineering background working on simple CRUD applications. Until I’ve switched to Zalando, a giant European E-commerce company where i had the pleasure to work some new architectural concepts that have just fascinated me. One of them is the Event-driven architecture and needless to say that exploring new ideas makes you a better developer and more confident with yourself as a professional software engineer. So what is an Event-Driven Architecture?

Definition

Event-driven architecture (EDA) is a software architecture paradigm promoting the production, detection, consumption of, and reaction to events.

Wikipedia

Simply put, in an Event-driven architecture there are components of the application that emits events which other parts of the application consume and respond to.

An event is something that occurred in the application that also represent a change in it’s state and other components can react then to such events.

Simple demonstration of Event-driven architecture
Figure 1: event-driven architecture

Event-driven architecture is used by a lot of big tech companies like Microsoft or Amazon. But when can this architecture pattern help us in our software development and based on what criteria should we choose to implement it?

What problem does it solve

Let’s start with a simple example, like a sign-in feature that needs to do the following steps:

  1. Receive a User sign in request with the credentials
  2. Verify the User credentials in the database
  3. Update the User Sign-in attempt in the database
  4. Increment the number of users online
  5. Notify the other devices
  6. Return back a HTTP Response

There are a lot of points of failures in this example, for example, if we successfully verify the user credentials during the sign-in process but we fail to notify other devices do we send a 200 and try the notification step later or we send 500 although the user have signed in successfully.

Using event-driven architecture we can decouple the steps of the monolithic approach to refactor it planning for better scalability and also fault-tolerance as demonstrated in Figure 2.

Figure 2: Decoupled Sign-In feature
Figure 2: Decoupling an application using Event-driven architecture

We’ve split out our application into separate components with single-responsibility principle allowing each functionality to be more independent and therefore scalable and fault tolerant.

We can now increase the resources for the components that are doing heavy processing without increasing it for all the application, also when a service like the notifier is down, it will not affect the application normal workflow.

When a user attempts to Sign-in, the Sign-in Service will emit an Event called UserSignIn and send it to the event bus then it will be consumed by the downstream components that will react accordingly to it.

When to use it

I’m a firm believer that simple always win. If you can deliver a value using a simpler method or an existing service, then by all means do it and don’t reinvent the wheel.

It’s the same thing for Event-driven architecture, if the functional and non-functional requirements for the application to build are so simple that they can be implemented using a monolithic approach then event-driven architecture would be an overkill.

Otherwise if we have to build an application that have demanding demanding requirements like 99% uptime and fault-tolerance and scalability then you got the right architecture to implement.