Varied approaches have appeared recently in computing like big data, serverless, microservice architecture, event-driven architecture, etc. Companies like Netflix and its contemporaries are using these approaches.
For their application development, Microservice architecture plays a major role. But how do they benefit from microservice architecture if the services are not wired? How a single microservice can work on its own?
One of the ways to do this is Event-driven architecture. This software architecture paradigm promotes the production, detection, consumption of, and reaction to events.
The event-driven architecture is a design pattern in which application data is defined as a stream of events. This streaming of data uses various mechanisms like message queues, enterprise service bus (ESB), most recent being Apache Kafka.
This diagram explains the event-driven architecture in detail:
What is an event?
Simply put, the event is a significant change in state, which is triggered when a user takes an action. For example:
- When a customer buys a car and its state changes from For Sale to Sold is an event.
- After a successful transaction, when an amount gets deducted from your account is an event.
- Once clicking on the book cab button, when a cab is booked from your account is an event.
Every event may trigger one or more than one options in response.
How is event-driven architecture different from the request-response model?
Event-driven architecture components
An event-driven architecture typically consists of four components:
The significant change in the state of an object that occurs when users take action.
2. Event Handler
A software routine, which handles the occurrence of an event.
3. Event Loop
Event loop handles the flow of interaction between an event and the event handler.
4. Event Flow Layers
The event flow layer is built on three logical layers: Event Producer, Event Consumer, and Event Channel (also called Event Bus).
Producer which is responsible for detecting and generating events.
Consumer which consumes the events produced by the event producer.
Event Channel which transfers events from the event generator to the event consumer.