DEV Community

ritaCosta93
ritaCosta93

Posted on

Event Driven Architecture

Event

Something that happens

  • Event Notification
  • Can contain data associated with the command
  • Just being a notification
  • Is immutable

Command

An order, expects a response.

  • Message

The Many Meanings of Event-Driven Architecture * Martin Fowler * GOTO 2017

Components

  • Producer
    • Creates the events
  • Broker
    • Redirects the events to the consumer
  • Consumer
    • Consumes the events from the broker

This is why the Event Driven Architecture is called a Publish/Subscribe Model

Benefits and Drawbacks

  • Benefits
    • Decoupling
    • Dependency Inversion
    • Scalability

Without event driven architecture

Service 1 —> Service 2

Service 1 needs to discover Service 2

  • That creates a dependency

With event driven architecture

Service 1 —> Event —> Service 2

  • We have decoupled the dependences:
    • The Service 1 is independent from service 2
    • The Service 2 is independent from service 1
    • The event is independent from the services
  • We can also invert the dependencies
    • The event can depend on server 1 or server 2

The services just need to know that the event exists

Imutability

The event can be consumed for by other systems.

Persistency

The event is persistent and counts on the broker for that, that creates a more stable system

Single Point of Failure

You don't need both services to be online, to receive the request.

After you've sent the event to the broker, the other service will get it.

The event will be persistent in the broker until the consumer receives it.

Drawbacks

  • Latency, you depend on the broker
  • Eventual consistency, if you have multiple services reading from the same event, they can be out of sync
  • Complexity, it's hard to track what is happening

When to use

  • When scalability is more important than performance
  • When we need data replication
  • Paralell Processing
  • Need decoupling

Discussion (0)