Navigating the Seas of Event-Driven Architecture: Understanding Eventual Consistency, Availability Over Consistency, and More

In the realm of distributed systems and Event-Driven Architecture (EDA), certain principles and trade-offs play a pivotal role in shaping the design and behavior of applications. In this article, we’ll set sail on the seas of EDA, exploring concepts such as eventual consistency, prioritizing availability over consistency, UI responsiveness, state distribution across systems, and the « reading your own write » problem.

First here’s a funny illustration of eventual consistency, from Imbattable, by Pascal Jousselin http://pjousselin.free.fr

No, let dive in a real world example around e-commerce :


Eventual Consistency: Synchronizing Waves of Change

Eventual consistency is a cornerstone of EDA, acknowledging that, in a distributed system, not all components will instantaneously reflect the same state. Consider a scenario in an online shopping application where a user places an order. The Order Service publishes an event indicating the change in the order status, and the Notification Service subscribes to this event to notify the user.

// Order Service publishes an event
public class OrderPlacedEvent
{
    public int OrderId { get; set; }
    // other order details...
}

// Notification Service subscribes to the event
public class OrderPlacedEventHandler
{
    public void Handle(OrderPlacedEvent orderPlacedEvent)
    {
        // Send a notification to the user about the order
        SendNotification(orderPlacedEvent.OrderId, "Your order is placed!");
    }

    private void SendNotification(int orderId, string message)
    {
        // Code to send a notification to the user
    }
}

Due to network delays or processing times, there might be a delay between placing the order, updating the order status, and sending the notification. Eventual consistency ensures that, over time, the user receives a notification consistent with the order status.

Availability Over Consistency: Sailing Through Storms

In the vast ocean of distributed systems, the principle of availability over consistency is akin to navigating through storms. Consider an e-commerce application with multiple microservices: Product Service, Order Service, and Notification Service. If the Notification Service experiences a temporary outage, the Order Service continues processing orders, prioritizing availability. The core functionality remains operational even if some services are temporarily unavailable.

UI Instant Response: Riding the Waves of Responsiveness

In the user interface (UI) of our online shopping application, immediate confirmation of actions enhances user experience. For example, when a user places an order, the UI may instantly confirm the order submission without waiting for notifications or order status updates. This instant responsiveness provides users with immediate feedback, even if other processes take some time to complete.

State Split Across Systems: Archipelago of Autonomy

Distributing state across systems is akin to creating an archipelago of autonomy. Each microservice, such as the Product Service and Order Service, manages its own state independently. This distribution enhances system availability and allows each service to operate autonomously.

Reading Your Own Write Problem: Navigating the Waters of Consistency

The « reading your own write » problem surfaces when a user writes data (e.g., places an order) and immediately queries the system for the latest information. Due to eventual consistency, there might be a brief delay before the latest data is fully propagated. Careful design considerations, such as implementing read-after-write consistency or providing clear user feedback, are essential to address this challenge.

In conclusion, the seas of Event-Driven Architecture are dynamic and require thoughtful navigation. Embracing eventual consistency, prioritizing availability over consistency when needed, ensuring UI responsiveness, distributing state across systems, and addressing the « reading your own write » problem are key elements in designing resilient and responsive distributed systems.

As we continue to explore the horizons of distributed systems, these principles will serve as our compass, guiding us through the challenges and opportunities that lie ahead. So, set your sails, fellow architects, and embark on the journey of building robust and scalable systems in the ever-evolving world of EDA.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *