这是indexloc提供的服务,不要输入任何密码

What is event-driven architecture?

Businesses increasingly need systems that can react instantaneously to a wide array of triggers, from customer interactions to sensor readings. Traditional request-response models, while valuable, may not always offer the necessary agility or scalability for these dynamic environments. Event-driven architecture (EDA) can offer a powerful paradigm for building responsive, resilient, and scalable applications. It's a software architecture pattern that can promote the production, detection, consumption of, and reaction to events.

Understanding event-driven architecture

Event-driven architecture defined

Event-driven architecture is a model for designing software applications where services are loosely coupled and communicate through the production and consumption of events. An "event" signifies a meaningful occurrence or a change in system state. This could be anything from a customer placing an order, a sensor detecting a change in temperature, a new file being uploaded to storage, or a database record being updated.

Unlike traditional request-driven models where a service explicitly calls another and waits for a response, EDA allows services to operate asynchronously. A service that generates an event (the "producer" or "publisher") simply announces that the event has happened. Other services (the "consumers" or "subscribers") that are interested in that type of event can then react to it independently and in their own time.

Key components in an EDA typically include:

  • Event producers: Applications or services that generate events
  • Event consumers (or subscribers): Applications or services that receive and process events
  • Event channel (or event bus, message broker, event router): The intermediary infrastructure that ingests events from producers and filters, and delivers them to interested consumers; this component is crucial for decoupling producers from consumers

How does event-driven architecture work?

The workflow in an event-driven architecture generally follows a consistent pattern.

  • Event occurrence and production: A significant action takes place within a service or system. For example, a user might click a "submit order" button on an ecommerce website. The service responsible for handling this initial action (the event producer) generates an event object containing relevant information about what happened, such as order ID, items, and customer details.
  • Event transmission: The producer sends this event to an event channel. This channel is a dedicated piece of infrastructure, like a message queue or a publish-subscribe (pub/sub) system, designed to handle the flow of events.
  • Event filtering and routing (by the event channel): The event channel receives the event. It may then apply filtering rules or route the event based on its type, content, or topic to various downstream consumers that have registered an interest in such events. For instance, an "order_placed" event might be routed to an inventory service, a notification service, and a shipping service.
  • Event consumption and processing: Interested services (consumers) receive the event from the channel. Each consumer processes the event asynchronously and independently. Continuing the ecommerce example:
  • The inventory service might decrease stock levels for the ordered items
  • The notification service could send an order confirmation email to the customer
  • The shipping service might initiate the logistics process

Benefits of event-driven architecture

Adopting an event-driven architecture can offer numerous advantages, particularly for complex, distributed systems.

Enhanced scalability

Services in an EDA are loosely coupled and can be scaled independently. If an "order processing" service is under heavy load, you can scale up just that service without impacting, for example, the "user notification" service.

Improved resilience and fault tolerance

Event-driven architecture can help application robustness by isolating service failures. The decoupled nature ensures that a malfunction in one consumer service typically doesn't propagate and cause a complete system failure.

Increased agility and flexibility

Developers can add, modify, or remove services with minimal impact on other parts of the system. New services can subscribe to existing event streams to add new functionality without requiring changes to the original event producers.

Real-time responsiveness

Event-driven architecture helps systems to respond to events with notable immediacy. This capability is particularly valuable for applications where swift action is paramount, including fraud detection, real-time analytics, and operational monitoring.

Simplified integration

EDA can serve as a flexible backbone for integrating disparate systems, including legacy applications, modern microservices, and third-party services. Each system can publish and consume events without needing direct point-to-point integrations with every other system.

Extensibility

Adding new features or reacting to existing events in new ways often involves simply deploying a new consumer service that subscribes to the relevant event stream.

Solve your business challenges with Google Cloud

New customers get $300 in free credits to spend on Google Cloud.

Use cases of event-driven architecture

The characteristics of EDA can make it well suited for a wide range of applications across various industries.

EDA is a common pattern for enabling communication and data flow between microservices. Instead of direct, synchronous API calls that can create tight coupling, microservices can publish events when their state changes, and other microservices can subscribe to these events to react accordingly.

Applications dealing with high-velocity data streams, such as IoT sensor data, application logs, social media feeds, or financial market data, can use EDA to process, analyze, and react to this information in real time. This can help power dashboards, alerting systems, or automated decision-making processes.

From managing inventory levels in response to sales, to processing orders through various stages (payment, shipping, fulfillment), to sending customer notifications, EDA can help manage the complex, asynchronous workflows inherent in online retail. If a payment processing service is slow, the order event can still be captured and processed by other services like inventory reservation.

Many business processes are inherently event-driven. For example, an insurance claim submission (event) can trigger a series of downstream activities: fraud checking, assessment, customer communication, and finally, payment processing. EDA can help model and automate these workflows effectively.

When data needs to be kept consistent across multiple systems or data stores, EDA can be used. A change in one database (an event) can be published, allowing other databases or caches to subscribe to these change events and update themselves.

Serverless functions (like Cloud Run functions) are often designed to be event driven. They execute in response to various event triggers, such as an object being uploaded to cloud storage, a message arriving in a queue, or an HTTP request. EDA is a natural fit for building applications using serverless components.

Real-time fraud detection, stock market monitoring, and trade processing are critical financial applications that benefit from the low latency and high throughput capabilities of EDA.

How does Google Cloud use event-driven architecture?

Google Cloud provides a robust suite of services that can enable customers to build and deploy powerful event-driven applications. The platform itself leverages event-driven principles to help deliver scalable and resilient services. For customers building event-driven solutions, Google Cloud offers several key managed services:

  • Pub/Sub: This is a globally distributed, scalable, and reliable real-time messaging service that acts as the event bus or message broker in an EDA. Pub/Sub helps services publish events and other services to subscribe to these events asynchronously. It decouples publishers from subscribers and supports features like "at-least-once" delivery, push and pull subscriptions, and message filtering.
  • Eventarc: Eventarc can provide a standardized way to manage the flow of events by connecting event sources (like Cloud Storage bucket changes, BigQuery job completions, or custom application events) to event consumers. It allows developers to easily trigger Cloud Run services, Cloud Run functions, or Workflows in response to events.
  • Cloud Run: This fully managed compute platform lets you run your stateless containers, making them invocable through HTTP requests or by events from Pub/Sub (often via Eventarc). Using Cloud Run functions, you can deploy small, single-purpose pieces of code (functions) that respond to a wide array of events without needing to manage servers or runtime environments. Within event-driven architecture, Cloud Run services can be highly effective as event consumers, processing workloads triggered by these events.
  • Workflows: A fully managed orchestration platform that allows you to define, deploy, and manage serverless workflows. Workflows can be triggered by events (via Eventarc or Pub/Sub) and can coordinate calls to various Google Cloud services and HTTP-based APIs that can make them suitable for orchestrating complex event-driven business processes.
  • Dataflow: For complex event processing (CEP) and stream analytics, Dataflow can provide a unified stream and batch data processing platform. It can ingest event streams from Pub/Sub, perform sophisticated transformations, aggregations, and analyses, and then output results to other systems or trigger further actions.

Take the next step

Start building on Google Cloud with $300 in free credits and 20+ always free products.

Google Cloud