Event-Driven Architecture
An architectural style where services communicate by publishing and reacting to events rather than calling each other directly.
Event-Driven Architecture (EDA) is an architectural style where services communicate by producing and consuming events instead of calling each other directly. When something meaningful happens in one part of the system, it publishes an event. Other services subscribe to events they care about and react independently.
This decoupling is the main selling point. The service that publishes an event doesn't need to know who consumes it or what they do with it. You can add new consumers without touching the publisher, and you can scale consumers independently. You can process events asynchronously, which often improves performance and user experience.
But there are some costs. Debugging is harder because there's no single request flow to trace. You're dealing with Eventual Consistency, which means data across services won't be in sync right away. Messages can be delivered more than once, so your handlers need to be idempotent. Events can arrive out of order. You need proper observability understand what's happening across services.
The Outbox Pattern is essential for reliable event publishing. Without it, you risk scenarios where you save data to the database but fail to publish the event (or vice versa). The outbox ensures both happen atomically by storing events in the same database transaction as your data changes.
References
- Introducing Watermill - Go event-driven applications library — Watermill is a Go library for working efficiently with message streams. It is intended as a library for building event-driven applications, enabling event sourcing, CQRS, RPC over messages, sagas.
- Distributed Transactions in Go: Read Before You Try — Discusses event-driven patterns as a practical alternative to distributed transactions. Covers designing event-driven systems, testing them, and monitoring message queues.
- Durable Background Execution with Go and SQLite — Event-Driven Architecture (EDA) is the industry best practice for supporting durable execution. However, most EDA production systems are not provably durable.
- Live website updates with Go, SSE, and htmx — Shows practical event-driven architecture for real-time features using Server-Sent Events. Running production-grade event-driven systems comes with many advantages, but it's not trivial.
- Shipping an AI Agent that Lies to Production: Lessons Learned — Event-driven patterns turned out to be a good fit for working with LLMs. Behind the scenes, there are many moving parts, and most need no input from the user. Failures and retries are hidden behind a single response.
- Event-Driven Architecture: The Hard Parts — Dedicated episode on real-world challenges of event-driven architecture. Covers observability, the outbox pattern, event design, and when synchronous systems are a better fit.
- Synchronous vs Asynchronous Architecture — Discussion on trade-offs between synchronous and asynchronous communication using message queues and event-driven architecture. Covers organizational scalability and common pitfalls.
- Watermill: from a hobby project to 8k stars on GitHub — Story of how Watermill grew from a need to make building event-driven applications as easy as HTTP handlers. Covers key decisions in building the event-driven library.