Event-Driven Architectures and AWS EventBridge

Learn about the event-driven architecture and how to implement it using AWS EventBridge.

In an event-driven architecture, the decoupled services interact with each other through events. An event can be any substantial change or important business event, such as a transaction, adding reviews, or sensory information. This software design pattern is commonly used in architectures made out of microservices.

A typical event-driven architecture has three important components, which are as follows:

  • Event producer: The component or system responsible for generating and publishing events. It can be any microservice or third-party software application that emits events. Also, CloudTrail events can be used as a producer.

  • Event router: This component routes the events from producer to consumer. An example of the event router is an event bus that maps the producer’s events to consumers.

  • Event consumer: This is the component or system that receives and responds to events. Event consumers subscribe to specific types of events and perform actions based on the occurrence of those events.

Solution architects can build an event-driven architecture in their cloud applications using Amazon EventBridge. Amazon EventBridge is an event management service. It allows us to connect components of a loosely coupled application through events. This spares the developers the hassle of writing code to trigger or invoke components. EventBridge is effectively used to route, filter, and process events among AWS services, SaaS applications, and custom applications.

Press + to interact

Routing events in EventBridge

Amazon EventBridge uses event buses and pipes to deliver events from a source to their destinations.

  • Event bus: An event bus delivers the events it receives to the targetsA target is the endpoint that receives an event sent by EventBridge. associated with it and is used when we want to deliver events from multiple sources to multiple events. We have the option of using the default EventBridge bus available in AWS or creating a customized bus according to our applications' requirements.

  • EventBridge pipes: EventBridge pipes are used to connect a source and a target and support point-to-point integration. Pipes allow us to filter and enrich the events sent to a destination. In event filtering, only a subset of events are sent to the destination based on the criteria we define. Whereas, in event enrichement, we can add additional data to an event sent by the source before delivering it to its destination. For example, we can add an object's metadata to an event generated when an object is uploaded in an S3 bucket using a Lambda function.

The following illustration gives an overview of how the EventBridge pipes work:

Press + to interact
EventBridge pipes
EventBridge pipes

EventBridge rules

EventBridge rules define the target for an event received by a source through the EventBridge buses or pipes. We can define multiple targets in a single rule (up to five targets can be defined in one rule for an event bus) to allow parallel processing. Rules are defined on the basis of an event pattern or a schedule.

  • Event-based rules: In the rules based on events, an event pattern is created that includes the fields and conditions that must be present in an event in order to send it to a target. For example, we can define the name of the DynamoDB table and the operation performed on it (such as the PutItem operation) in a rule that uses a Lambda function as a target.

  • Schedule-based rules: Rules based on a schedule are invoked at regular intervals in time. For example, we can invoke a Lambda function that sends notifications to consumers on an hourly basis. We can define this schedule by creating a CRON expression that runs the rules at a specific time or a rate expression that runs the rules at specific intervals.

Best practices while working with rules

Following are some of the things we must keep in mind while creating rules in Amazon EventBridge:

  • Granular rules: While creating a rule, provide specific conditions in the event pattern to ensure EventBridge doesn’t unnecessarily send these events to targets.

  • Define a single target: Even though EventBridge allows us to add multiple targets in a single rule, we should avoid doing so, as managing rules becomes easier if we have one target per rule.

  • Monitor rules: Once our rules are created, we must monitor these rules to ensure they are working as expected. This can be done using CloudWatch. We can also define alarms that are triggered when our rules behave unexpectedly.

Get hands-on with 1300+ tech skills courses.