Event-driven Architecture using the Outbox Pattern

Introduction

I am not good at definitions, so I am going to steal some from microservices.io:

Event-driven Architecture

Use an event-driven, eventually consistent approach. Each service publishes an event whenever it update its data. Other service subscribe to events. When an event is received, a service updates its data.

Outbox Pattern

The solution is for the service that sends the message to first store the message in the database as part of the transaction that updates the business entities. A separate process then sends the messages to the message broker.

As a side-project, I have implemented a python library called outbox. It uses Async Python, SQLAlchemy (with the async extension) and aio-pika as a library to interact with RabbitMQ. Apart from that, it is made to be as standalone as possible; you should be able to use this with any async framework, although in my head it is going to be FastAPI.

This is my attempt at understanding Event-driven Architecture. We are going to write some pseudocode that implements a hypothetical service, explaining my thought process along the way.