Design Accelerator: Why I Hate the Outbox Pattern
Summary
TLDRIn this tutorial, Von Vernon critiques the outbox pattern commonly used in event-driven architectures. While it ensures atomicity between entity persistence and event publication, Von argues that its typical implementation introduces inefficiencies and data synchronization issues. He suggests a more robust approach using a journal table for long-term event persistence and a subscription model to manage independent consumers more efficiently. This alternative avoids unnecessary database operations, reduces complexity, and ensures that events are consistently and idempotently processed, providing a better solution for high-throughput, scalable systems.
Takeaways
- π The Outbox Pattern ensures domain events and entities are persisted together in the same transaction to prevent data synchronization issues.
- π While the Outbox Pattern solves certain problems, it can lead to unnecessary complexity and performance issues when implemented incorrectly.
- π One of the main criticisms of the Outbox Pattern is treating domain events as ephemeral, which undermines their long-term value in the system.
- π Domain events should be preserved and not deleted once processed, as they provide critical insight into the domain and system operations over time.
- π The typical implementation of the Outbox Pattern involves moving events to a 'sent' table, adding additional database load and complexity.
- π The Outbox Pattern may introduce concurrency issues, especially in scenarios where events are processed multiple times or fail during transmission.
- π An alternative approach to the Outbox Pattern is the Subscription Pattern, which provides better long-term handling of domain events and event-sourcing.
- π In the Subscription Pattern, a Journal Table stores domain events, and a Subscription Table tracks the progress of different consumers processing those events.
- π The Subscription Pattern ensures events can be replayed, are not deleted prematurely, and helps manage multiple consumer subscriptions independently.
- π Consumers of domain events must be idempotent to handle scenarios where events are retried or resent, ensuring consistent processing despite failures.
- π Using the Subscription Pattern, each consumer's position is tracked, allowing for efficient management of event consumption without unnecessary repetition of processed events.
Q & A
What is the main issue Von Vernon has with the outbox pattern?
-Von Vernon argues that while the outbox pattern solves some problems by ensuring transactional consistency between entity persistence and event publishing, it introduces performance overhead and architectural complexity. He believes that treating domain events as ephemeral and deleting them after they are sent can lead to important events being lost or discarded.
What does the outbox pattern aim to solve in event-driven architectures?
-The outbox pattern ensures that domain events are persisted together with the entities they correspond to, in the same transaction. This ensures that if there is a failure in event publishing, both the entity and event can be rolled back, preventing data inconsistency.
Why does Von Vernon consider events to be valuable and not something to be discarded?
-Von Vernon considers domain events to be valuable because they represent significant facts about the domain model. Events should be preserved, not ephemeral, to ensure they can be reviewed or retried if necessary, and to maintain accurate, long-term records.
What problem does Von Vernon highlight with the 'sent' table in the outbox pattern?
-The problem with using a 'sent' table in the outbox pattern is that it introduces additional complexity and database overhead. Moving events from an outbox table to a 'sent' table within a transaction can lead to performance issues, especially in high-throughput systems.
What alternative does Von Vernon propose to the outbox pattern?
-Von Vernon proposes using a 'Journal' table instead of an outbox table. The Journal pattern allows domain events to be stored long-term and can be used to manage subscriptions for multiple consumers. It also decouples event persistence from event publishing.
What is the purpose of the 'Journal' table in Von Vernon's alternative approach?
-The 'Journal' table serves as a long-term storage for domain events and can support multiple types of subscriptions. It tracks the position of each subscriber in the event stream, allowing consumers to process events independently without risking data inconsistencies.
How does the Journal table handle subscriptions differently from the outbox pattern?
-In the Journal pattern, subscriptions are tracked in a separate table. Each subscriberβs progress is recorded with a position or ID, which indicates the last event they processed. This approach allows for independent event consumption at different rates for each subscriber.
Why is idempotency important in Von Vernon's proposed subscription management system?
-Idempotency is crucial because it ensures that events can be safely retried in case of failure. If an event is delivered more than once, the system should process it only once, preventing duplicate actions or errors in the downstream systems.
What are the potential risks of not updating the subscription position after sending events?
-If the subscription position is not updated after sending events, some events may be resent. This can result in duplicate processing of events, leading to inconsistency or unnecessary load on the system. This is why Von Vernon stresses updating the subscription position only after all events have been successfully sent.
What systems or industries might benefit from Von Vernon's proposed Journal pattern?
-Systems that require high throughput, such as e-commerce platforms or other applications with high volume, low-value transactions, would benefit from the Journal pattern. This approach also works well for systems with independent subscriptions, allowing each consumer to track their own position in the event stream.
Outlines
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowMindmap
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowKeywords
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowHighlights
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowTranscripts
This section is available to paid users only. Please upgrade to access this part.
Upgrade NowBrowse More Related Video
Outbox Pattern: Fixing event failures in an event-driven architecture
The Biggest Issue With Event-Based Architecture (Day 10 of 100 to Scale)
The Pattern You MUST Learn in .NET
What is Event Driven Architecture (EDA)?
Apache Kafka in 15 minutes
Database Indexes: What do they do? | Systems Design Interview: 0 to 1 with Google Software Engineer
5.0 / 5 (0 votes)