top of page

What is event-driven architecture?


Event driven architecture (EDA) is a

software design pattern that enables

applications to communicate asynchronously through events. Events are messages that represent changes in the state of a system or a domain. For example, an event could be a user clicking a button, a sensor detecting a temperature change, or an order being placed.


In EDA, there are four main components: event producers, event consumers, event channels, and event brokers. Event producers are the sources of events, such as user interfaces, sensors, or external systems. Event consumers are the destinations of events, such as services, functions, or databases. Event channels are the pathways that connect event producers and consumers, such as message queues, topics, or streams. Event brokers are the intermediaries that manage the routing and delivery of events between event channels and event consumers, such as Apache Kafka, Azure Event Grid, or AWS EventBridge.


The benefits of EDA include:

- Decoupling: EDA reduces the dependencies and coupling between components, allowing them to evolve independently and scale horizontally.


- Responsiveness: EDA enables faster and more responsive applications by avoiding blocking calls and leveraging parallel processing.


- Resilience: EDA improves the fault tolerance and reliability of applications by enabling retries, fallbacks, and error handling mechanisms.


- Extensibility: EDA facilitates the addition of new features and capabilities by allowing new event producers and consumers to join the system without affecting existing ones.


- Traceability: EDA provides better visibility and monitoring of the system's behavior and performance by capturing and logging events.


The challenges of EDA include:

- Complexity: EDA introduces additional complexity and overhead in terms of designing, developing, testing, deploying, and maintaining event-driven applications.


- Consistency: EDA requires careful coordination and synchronization of events to ensure data consistency and integrity across distributed components.


- Security: EDA poses security risks and challenges in terms of encrypting, authenticating, authorizing, and auditing events.


- Quality: EDA demands high quality and reliability of events in terms of format, content, timeliness, and accuracy.


To implement EDA successfully, some best practices are:

- Define clear and consistent event schemas and contracts that specify the structure, semantics, and metadata of events.


- Use standard and interoperable protocols and formats for event communication, such as HTTP, AMQP, MQTT, or JSON.


- Implement event-driven workflows and patterns that suit the business logic and requirements of the application, such as publish-subscribe, request-reply, or saga.


- Apply event sourcing and CQRS principles to capture the state changes of the system as a sequence of events and separate the read and write models of data.


- Adopt microservices architecture and serverless computing to build modular, scalable, and resilient event-driven applications.


Event driven architecture is a powerful and flexible way to design modern applications that can handle complex and dynamic scenarios. By understanding its benefits, challenges, and best practices, developers can leverage EDA to create high-performance, scalable, and reliable software systems.


Let’s look at three practical use cases of event-driven architecture and how it can benefit different domains and scenarios.


1. Internet of Things (IoT)

IoT is a domain where devices and sensors are connected to the internet and generate large volumes of data. An event-driven architecture can help IoT systems to ingest, process, and analyze data in near real-time, as well as trigger actions based on events. For example, an IoT system could use an event streaming platform, such as Azure IoT Hub or Apache Kafka, to collect data from devices and feed them to stream processors that can perform tasks such as filtering, aggregation, anomaly detection, or machine learning. The stream processors can also publish events to other services or applications that can respond accordingly. For example, if a stream processor detects a high temperature in a device, it can publish an event to a service that can send an alert to the device owner or initiate a cooling mechanism.


2. Microservices

Microservices are a software architecture style where applications are composed of small, independent, and loosely coupled services that communicate through well-defined interfaces. An event-driven architecture can help microservices to achieve high scalability, availability, and resilience, as well as decouple dependencies and reduce coupling. For example, a microservice could use a publish/subscribe model to publish events to a message broker, such as Azure Service Bus or RabbitMQ, that can deliver the events to other interested microservices. This way, the microservice does not need to know who is consuming the events or how they are processed. The consumers can also scale independently and handle failures gracefully without affecting the producer.


3. Business Process Automation

Business process automation is a practice where business processes are automated using software tools and technologies. An event-driven architecture can help business process automation to orchestrate complex workflows across multiple systems and services, as well as monitor and audit the execution of the processes. For example, a business process automation system could use a complex event processing engine, such as Azure Stream Analytics or Apache Storm, to correlate events from different sources and apply rules or logic to trigger actions or decisions. The actions or decisions could be implemented by invoking other services or applications through events or messages. The system could also track the state and progress of the processes and generate events for reporting or auditing purposes.

Event-driven architectures are a popular way of designing software systems that can react to changes in state, such as user actions, sensor inputs, or messages from other systems. Let’s also describe two alternatives for event-driven architectures: pub/sub and event streaming.



Pub/sub stands for publish/subscribe, and it is a model where event producers send events to a messaging infrastructure that keeps track of subscriptions. The messaging infrastructure then delivers the events to each subscriber, who can process them accordingly. Pub/sub is useful when you want to decouple event producers from event consumers, and when you want to ensure that every event is delivered to every subscriber. However, pub/sub has some limitations, such as:

- Events cannot be replayed once they are received, which means that new subscribers do not see past events and that events may be lost if a subscriber is offline or fails.


- Events are not ordered or durable, which means that subscribers may receive events out of order or miss some events due to network failures or congestion.


- Events are not persisted, which means that subscribers cannot query or analyze historical events or perform complex event processing.


Event streaming is another alternative for event-driven architectures, and it is a model where events are written to a log that maintains a strict order and durability of events. Event consumers do not subscribe to the log, but rather read from any part of the log at their own pace. Event streaming is useful when you want to enable event replayability, ordering, durability, and persistence, and when you want to support complex event processing and analytics. However, event streaming also has some challenges, such as:


- Event consumers need to manage their own offsets in the log, which means that they need to keep track of where they are in the log and how to advance their position.


- Event consumers need to handle duplicate events, which may occur due to retries or failures in the log.


- Event consumers need to handle schema evolution, which means that they need to deal with changes in the structure or format of the events over time.


Both pub/sub and event streaming have their pros and cons, and choosing between them depends on the requirements and characteristics of your system. In general, pub/sub is simpler and faster, but less reliable and expressive. Event streaming is more reliable and expressive, but more complex and slower. You should consider factors such as latency, throughput, scalability, reliability, consistency, and complexity when deciding which alternative suits your needs better.

Comments


bottom of page