Chapter 5, Event-Driven Architecture Patterns gpt Flashcards
What are the key characteristics and benefits of event-driven architecture?
Event-driven architecture is a software paradigm that promotes the generation, detection, consumption, and reaction based on events. It enables the building of distributed and scalable cloud-native applications. Unlike service composition patterns, which are mostly synchronous, event-driven architectures are asynchronous. This decoupled approach simplifies scaling and is fundamental for designing large-scale distributed cloud-native applications.
Page 262
Event-driven architecture is a software architecture paradigm that promotes generation, detection, consumption, and reaction based on events. An event-driven architecture allows us to build distributed and scalable cloud native applications. In contrast to the service composition patterns, which are mostly synchronous in nature, event-driven architectures are asynchronous. They provide a clean and decoupled way of designing cloud native applications, allowing simpler scaling, and are one of the fundamental architectures for building large-scale distributed cloud native applications.
How does event-driven architecture differ from traditional service composition patterns in terms of communication style?
Event-driven architecture differs from traditional service composition patterns by being asynchronous, whereas service composition patterns are mostly synchronous. This asynchrony in event-driven architecture allows for a cleaner and more decoupled design, facilitating simpler scaling and more efficient handling of distributed systems.
Page 262
Event-driven architecture is a software architecture paradigm that promotes generation, detection, consumption, and reaction based on events. An event-driven architecture allows us to build distributed and scalable cloud native applications. In contrast to the service composition patterns, which are mostly synchronous in nature, event-driven architectures are asynchronous. They provide a clean and decoupled way of designing cloud native applications, allowing simpler scaling, and are one of the fundamental architectures for building large-scale distributed cloud native applications.
What role do events play in sharing information within an event-driven architecture?
Events are used for sharing information between applications in an event-driven architecture. Typically, the application generating the event notification does not expect a direct response, allowing the consuming application to decide how to process the information. This decoupling of the sender and receiver enhances scalability and flexibility.
Page 262
Events are used for sharing information. In most cases, the application generating the event notification does not expect any response, and it lets the consuming application decide what to do with that information. Even if the applications generating the event notification expect a response, they expect it only indirectly.
How do applications generating event notifications handle the need for responses in an event-driven architecture?
Even when applications generating event notifications expect a response, they anticipate it indirectly rather than through direct synchronous communication. This allows for greater flexibility and decoupling between the producer and consumer of the event.
Page 262
Events are used for sharing information. In most cases, the application generating the event notification does not expect any response, and it lets the consuming application decide what to do with that information. Even if the applications generating the event notification expect a response, they expect it only indirectly.
How can significant occurrences or changes in a system state be categorized in an event-driven architecture?
Significant occurrences or changes in a system state can be categorized as events. For example, depositing $50 into an account is considered an event. These events can trigger notifications and actions in other systems.
Page 262
Things to note: Events can be categorized as any significant occurrence or change in a system state. Let’s take an example of depositing $50 into Bob’s account. Now, Bob’s account balance has increased by $50; this incident is considered an event.
How can the occurrence of an event be communicated to other systems in an event-driven architecture?
The occurrence of an event, such as a deposit, can be sent to other systems, like sending a notification to a user’s cell phone. This is typically done through asynchronous messages that contain the event occurrence information.
Page 262
The occurrence of this event can be sent to other systems, such as to Bob’s cell phone, as a notification. The event notification is typically an asynchronous message produced and transmitted with the event occurrence information.
What is the relationship between events and event notifications in an event-driven architecture?
In event-driven architecture, the term event is often used interchangeably to denote the message that notifies the event. This is because the architecture relies on an asynchronous messaging infrastructure to identify and communicate event occurrences.
Page 262
Though events just occur and do not travel, the term event is also used interchangeably to denote the message that notifies the event. This is mainly because event-driven architectures are built on top of an asynchronous messaging infrastructure that uses messages to identify and communicate event occurrences.
Why are intermediate systems like message brokers often needed in event-driven architectures?
Intermediate systems such as message brokers are often needed in event-driven architectures to consume, store, and deliver events to their consumers. They ensure that no events are lost across system failures and help manage the decoupled nature of event communication.
Page 265
in event-driven architecture, we cannot always directly send messages to consumers and get an acknowledgment that they have consumed them successfully. In most cases, we need intermediate systems such as message brokers to consume, store, and deliver events to their consumers while ensuring that no events are lost across system failures.
What role do defined schemas play in event-driven architectures, especially for cloud-native applications?
Defined schemas for events are crucial in event-driven architectures to ensure seamless interoperability between event producers and consumers. For cloud-native applications, using the CloudEvents specification to define the structure of the event payload is recommended.
Page 268
Like APIs and data, events should have defined schemas. This helps event producers and consumers interoperate seamlessly. When defining events for cloud native applications, we recommend using the CloudEvents specification to define the structure of the event payload.
How does the Producer-Consumer Pattern function in asynchronous event delivery?
In asynchronous event delivery, the Producer-Consumer Pattern involves passing events to another application without blocking the producer. This ensures that events are processed by one of the available consumers, allowing for efficient event handling without direct interaction between the producer and consumer.
Page 270
Provide asynchronous event delivery: In asynchronous event delivery, the most common use of the Producer-Consumer Pattern, we pass events to another application without blocking.
How does the Producer-Consumer Pattern ensure that each event is processed by only one consumer?
The Producer-Consumer Pattern uses event queues to ensure that each event is processed by only one of the available consumers. This prevents multiple consumers from processing the same event, maintaining efficient and accurate event handling.
Page 270
Process each event by a single application: We can use the Producer-Consumer pattern when we need events to be consumed and processed by only one of the available consumers. Using event queues ensures that events are not delivered to multiple consumers.
How do message brokers guarantee event delivery in the Producer-Consumer Pattern?
Message brokers guarantee event delivery by using acknowledgments. When a broker receives an event, it durably persists it and sends an acknowledgment to the producer. Similarly, it expects an acknowledgment from the consumer upon event delivery. If no acknowledgment is received, the broker attempts to redeliver the event.
Page 271
The message broker uses acknowledgments to guarantee that the events are delivered. When the broker receives an event, it persists that durably and then sends an acknowledgment to the producer, stating that it has successfully consumed the event. The producer is updated to wait for the acknowledgment from the message broker when it publishes an event. Similarly, when the message broker delivers the message to the consumer, it expects an acknowledgment, and therefore the consumer is updated to send an acknowledgment when it receives an event. If the message broker does not receive the acknowledgment, it will try to redeliver the event, and so the consumer can get duplicate events.
How can the Producer-Consumer Pattern handle sudden bursts of events?
The Producer-Consumer Pattern can handle sudden bursts of events by buffering them in a queue. This allows for the storage and gradual processing of events without overwhelming the consumers, ensuring that the system remains stable and efficient during high-volume periods.
Page 272
Handle sudden bursts of events
We can also use the Producer-Consumer Pattern to buffer event bursts over a short period. We can queue and process events without extensively scaling consumers. In the example in Figure 5-2, a data processing organization periodically pulls logs from servers for processing, resulting in a burst of logs every time we fetch a new log file. If we publish the burst of logs directly to the log processors, they will become overloaded and fail. But by buffering with a queue, we store and process the logs at the capacity of the log processors. Further, as they are using a pull-based approach, the consumers will not be overloaded as excess events are buffered at the event queue.
How does the Producer-Consumer Pattern share workloads among multiple workers?
The Producer-Consumer Pattern shares workloads among multiple workers by allowing multiple log processors to consume events from the message broker in parallel and at their own pace. This ensures that events are processed quickly and that no processor remains idle while there are events in the queue. The pattern also uses FIFO semantics to prioritize the oldest events, mimicking real-world queue behavior.
Page 272
the Producer-Consumer Pattern can be used to share the workload among multiple workers. Taking the previous example of processing log events, we have multiple log processors consuming events from the message broker in parallel and at their own speed. As the log processors are competing to pull events, we can ensure that events are processed as soon as possible. This also ensures that events are processed as long as at least one log processor is available, and no log processor will idle as long as events remain in the queue. the Producer-Consumer Pattern also allows us to prioritize the oldest events by using FIFO semantics. This mimics queues in the real world: the first person in the queue will be served first. The Producer-Consumer pattern allows us to model the same event-processing semantics on cloud native applications.
What are some considerations when using message brokers in the Producer-Consumer Pattern?
When using message brokers in the Producer-Consumer Pattern, it is important to ensure at-least-once delivery guarantees, separate queues for different use cases, and handle bursts effectively. If the input rate consistently exceeds the consumption rate, it is necessary to scale the number of consumers to increase processing capacity.
Page 273
Considerations: Most message brokers provide support for an at-least-once delivery guarantee. If the consumer fails to acknowledge the event delivery or times out, the broker will send that event to another consumer, making sure that the event is processed by at least one consumer.
A single message broker can host multiple event queues. We recommend that each use case and operation has its own queue; for example, events updating customer information might have their own queue, while events updating payments will have their own queue. Mixing different events in a single queue requires us to improve consumers to differentiate between events and handle them appropriately; this complicates the design, and slows performance as the number of events they receive increases.
When using queues, we have to be careful to handle bursts. While queues buffer events, there should be enough capacity to process all produced events over a certain time period. If we are constantly getting bursts of events (as in the log processing example in Figure 5-2), and if the input rate to the queue is consistently higher than the consumption rate, the Producer-Consumer Pattern fails. To mitigate this risk, we should scale the number of consumers to increase consumption capacity.
The Producer-Consumer Pattern helps us build decoupled systems and allows us to independently add and remove producers and consumers, scaling overall event processing.
What is the main use of the Publisher-Subscriber Pattern in event-driven architecture?
The Publisher-Subscriber Pattern is primarily used for broadcasting information to multiple subscribers. For example, it can send notifications of tweets with a specific hashtag to all users who have subscribed to that hashtag, allowing efficient dissemination of information to interested parties.
Page 276
Broadcast events: the Publisher-Subscriber Pattern is ideal for broadcasting information. For example, let’s assume we are building a system like Twitter, and we can use the Publisher-Subscriber Pattern to send a notification of all tweets published about sports with #sports (the topic) to all users who have subscribed to that hashtag. The main advantage of the Publisher-Subscriber Pattern is that it enables us to notify all interested subscribers, instead of only a single user or application.
What delivery guarantee is typically associated with events produced by publishers in the Publisher-Subscriber Pattern?
Events produced by publishers in the Publisher-Subscriber Pattern typically have the at-most-once delivery guarantee. This means that subscribers may not receive events published during an outage, which is acceptable for scenarios where missing some updates is not critical, such as periodic weather updates.
Page 276
Deliver events with best effort: Typically, events produced by publishers have the at-most-once delivery guarantee. For instance, subscribers do not receive events published during an outage. Though you risk losing events, this approach is still useful for scenarios such as status updates—like publishing current weather periodically to the weather topic so subscribed people can plan what to wear when they go out. Even when some updates are missed, the subscribers can appropriately take corrective decisions based on future events.
When is the event delivery with best effort not suitable in the Publisher-Subscriber Pattern?
Event delivery with best effort is not suitable when missed events impact the function of the system. For example, tracking a topic to find out the closing date to apply for a state exam requires that subscribers receive all relevant events, which can be ensured with durable subscriptions to prevent missing critical information.
Page 277
Make sure all events are delivered to all subscribers: Event delivery with best effort is not suitable when missed events impact the function of the system. For example, someone might be tracking a topic to find out the closing date to apply for a state exam. A subscriber who misses that event will miss the deadline and miss the chance to sit for the exam. You can use durable subscriptions to ensure that subscribers receive missed events when they are online again.