nanyang-system-developers

Event-Driven Architecture

Introduction

In a more “traditional” application, the app might:

  1. call some functions, or make an API request
  2. check the data for changes
  3. If there are changes to be handled, handle the changes
  4. If there are no changes, wait/sleep for a suitable interval
  5. Repeat steps 1-4 in an infinite loop, or until an exit signal is received.

This pattern is simple, but suffers the following limitations:

Mitigation

Event-driven architecture (EDA) is a software design pattern centred around events. Events are packets of data containing:

Changes to data are signalled using events.

An app subscribes to events, usually by attaching a handler i.e. a function/method that is called when an event is received. Such apps are called subscribers.

An app can also emit events, whenever it has caused or triggered a data change. Such apps are called publishers (alt. producers).

An app can be both a subscriber and a publisher.

The exchange of events between subscribers and publishers is mediated by an event broker (alt. message brokers, message queue).

Benefits of Event-Driven Architecture

Example: User Registration Workflow

  1. Event Producer: A web application generates a "user.registered" event.
  2. Event Broker: The event is sent to a message queue.
  3. Event Consumers:
    • A notification service sends a welcome email.
    • An analytics service logs the registration event.

Further Reading