From "Fundamentals of Software Architecture"
🎧 Listen to Summary
Free 10-min PreviewError Handling, Data Loss Prevention, and Communication Patterns in Event-Driven Architecture
Key Insight
Error handling in asynchronous workflows is crucial and can be addressed by the workflow event pattern, a reactive architecture pattern emphasizing resiliency and responsiveness. In this pattern, an event consumer experiencing an error delegates it immediately to a workflow processor and continues processing the next message, ensuring responsiveness is maintained. The workflow processor then attempts to programmatically repair the original data, for instance, stripping ' SHARES' from '8756 SHARES' in a trade instruction example, and resubmitting the corrected message for reprocessing. If automated repair fails, the message is sent to a dashboard for manual correction and resubmission, though this process can lead to messages being processed out of sequence.
Preventing data loss is a primary concern in event-driven architectures, as messages can be lost at multiple points. Three common areas of data loss (message not reaching the queue, event processor crashing after de-queuing, or inability to persist to the database due to data error) can be mitigated. The first is solved by using persisted message queues combined with synchronous send, ensuring messages are either with the producer or persisted by the broker. The second is addressed by client acknowledge mode, which keeps a de-queued message in the queue until successfully processed. The third is managed through ACID transactions with last participant support (LPS), guaranteeing data persistence and message removal from the queue only after successful database commit.
Beyond core processing, event-driven architecture provides unique communication patterns. Broadcast capabilities allow event producers to send messages without needing to know which, if any, event processors will receive them or what they will do with the information. This is vital for patterns like eventual consistency and complex event processing. For scenarios requiring an immediate response from an event consumer, 'request-reply' messaging facilitates pseudo-synchronous communication. This is typically implemented using a correlation ID in the message header, allowing the producer to filter for its specific reply, or by creating a temporary queue for each request, with the correlation ID method generally preferred for high-volume scenarios due to lower overhead.
📚 Continue Your Learning Journey — No Payment Required
Access the complete Fundamentals of Software Architecture summary with audio narration, key takeaways, and actionable insights from Mark Richards, Neal Ford.