-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
## Event-driven architecture | ||
|
||
An event is a change in the system's state that triggers an action to communicate between different services. Event driven Architecture(EDA) helps break an app into multiple loosely coupled components that communicate through events. EDA is made up of event producers and consumers: | ||
|
||
- An event producer detects an event and transmits the event's information to the event consumers through the event channel. | ||
- An event consumer subscribed to an event channel to receive information and process events. | ||
|
||
Each component can act as an event producer, consumer, or both, depending on the use case. Let us consider a coffee shop as an example: a customer(consumer) requests an espresso(event), communicating order details to the barista(producer) as a message. The following process happens, | ||
|
||
1. The customer orders an espresso(an event), and the order details are told to the barista(a message). | ||
1. The barista then processes the order and starts making an espresso(a response to an event). | ||
|
||
So, event-driven architecture in a coffee shop is like the seamless flow of orders and drinks without everything stopping for one specific thing. It keeps things moving smoothly ☕👩💻 | ||
|
||
## Event-driven architecture with AsyncAPI | ||
|
||
AsyncAPI simplifies defining how to communicate and send messages between different components in an EDA. It offers a way to describe the events, channels, and message formats, making it easier to understand. | ||
|
||
AsyncAPI helps you define asynchronous APIs. But what is an asynchronous API? | ||
|
||
They are like digital mailboxes where you can send messages without waiting for an instant reply. Rather, when the other person reads your letter and has something to say, they will reply back. | ||
|
||
To build an EDA where certain actions(events) trigger other actions, Async API helps map out events and their response. For example, imagine a birthday party with events like cake cutting and gift opening. These events trigger responses, such as singing when the cake is cut or clapping while opening the gifts. | ||
|
||
AsyncAPI helps you organize events that will happen, when they will happen, and how everyone should react to them. For example, when the cake is cut, AsyncAPI guides you to sing the birthday song. It also enables creating a party schedule, like cutting the cake at 6 pm and opening gifts at 7 pm. | ||
|
||
Here are reasons why using AsyncAPI enhances EDA design: | ||
|
||
- AsyncAPI plans and describes each event and its corresponding reactions across different components. | ||
- AsyncAPI facilitates communication between different components for seamless information exchange. | ||
- AsyncAPI allows components to complete tasks independently without waiting. | ||
|
||
## Microservices with AsyncAPI | ||
|
||
Each microservice represents a specific function in a microservices architecture, and different microservices communicate using events. For example, one team is responsible for baking the birthday cake, and the other is responsible for decorating the room. These teams need to talk to each other to share their progress. | ||
|
||
AsyncAPI helps different microservices communicate with each other. For microservices to talk to each other, they would have to: | ||
|
||
- Define how to send and receive messages | ||
- Schedule when to send these messages | ||
- Ensure consistent language in messages | ||
|
||
AsyncAPI ensures that each microservice knows what information it will receive, how it will receive it, and what it should do with it. It also helps document interactions between microservices to help developers understand and integrate them. |