DEV Community

Cover image for Understanding event driven architecture
Steve Yonkeu
Steve Yonkeu

Posted on

Understanding event driven architecture

Everyday a numerous number of applications are deployed, servers changed, architecture changes too. In this ever-evolving landscape of software development, architectures that support dynamic, real-time applications are increasingly in high demand. Among these, Event-Driven Architecture (EDA) stands out for its ability to facilitate highly responsive, scalable, and loosely coupled systems. This architecture style has gained prominence among world-leading companies, such as Netflix, Twitter, and Amazon, for its significant role in enabling real-time data processing, microservices communication, and the seamless handling of asynchronous events. Imagine a world where systems don't wait around for instructions, but instead react dynamically to the ever-changing tide of events. This is the essence of Event-Driven Architecture (EDA), a paradigm shift that's transforming software development.

The Essence of Event-Driven Architecture

EDA gif
Event-Driven Architecture revolves around the production, detection, consumption, and reaction to events. An event is a significant change in state, or an update, that something of interest has occurred within the system. EDA is designed to respond to these events asynchronously, allowing systems to react in real time without waiting for a response. This architecture comprises three main components: event producers, event routers (or brokers), and event consumers. Together, they create a dynamic environment where services can operate independently, improving system resilience and flexibility.

Understanding more about

Car in circulation
Some of us might not be used to the jargon to above, but I got you on this. Let's explore some life scenarios where an EDA can be experienced.

  1. Imagine you're running a restaurant kitchen. Instead of the chefs constantly asking the waiter "Are there any orders?", the waiter simply shouts, "Order up!" whenever a new order comes in. This is a simple example of how an EDA works. EDA mimics a busy kitchen where events (like "Order up!" shouts) signify important occurrences, such as user actions or system changes. Producers generate these events without awaiting responses, similar to waiters. Consumers, akin to chefs, react to these events, facilitated by a messaging system that distributes events, ensuring efficient communication and responsiveness across different parts of the system. This architecture enhances flexibility, scalability, and real-time processing capabilities.

  2. Imagine a car-based EDA, cars on a highway act as producers, broadcasting signals like lane changes or sudden brakes as events. Other cars, traffic systems, and emergency vehicles serve as consumers, reacting to these signals through a messaging system akin to airwaves or the road itself. This setup enhances safety by enabling quick reactions to avoid accidents, improves efficiency and traffic flow, allows for scalability by accommodating more cars without disruption, and ensures flexibility with diverse vehicle interactions. This analogy exemplifies EDA's dynamic and responsive nature in real-time situations.

  3. In a tag game analogy for EDA, the person tagging acts as the event producer, announcing "tagged!" without awaiting a reply. The others, as event consumers, react by running away, with the air serving as the messaging system to broadcast the "tagged!" alert. This setup illustrates EDA's benefits: fast reactions to keep the game lively, independent actions allowing players to strategize spontaneously, and adaptability to include new players at any time. This simple playground scenario captures EDA's essence—responding to events in a flexible, dynamic system.

Success Stories of Event-Driven Architecture

Dancing thing
Several global companies have successfully implemented EDA to enhance their operations and service offerings. For instance:

  • Netflix:
    Netflix has adeptly implemented Event-Driven Architecture (EDA) to orchestrate its vast, distributed microservices ecosystem. This architecture facilitates the seamless real-time processing of data crucial for personalizing user experiences across millions of devices worldwide. By leveraging EDA, Netflix can dynamically adjust its content recommendations, manage streaming quality in real-time, and swiftly handle changes in user preferences or system demands. This approach not only enhances user satisfaction through personalized viewing experiences but also optimizes resource utilization across Netflix's global infrastructure.

  • Twitter:
    Twitter employs an event-driven model to efficiently manage the massive flow of tweets and social interactions generated by its users every second. This model enables Twitter to ensure that updates, notifications, and tweets are delivered in a timely manner, despite the enormous volume of data. The use of EDA allows Twitter to filter, sort, and distribute this information effectively, ensuring that users receive relevant content and notifications instantaneously. This capability is crucial for maintaining the platform's relevance and responsiveness, contributing significantly to its user engagement and satisfaction.

  • Amazon:
    Amazon incorporates Event-Driven Architecture into its e-commerce platform to excel in real-time order processing, inventory management, and customer notifications. EDA enables Amazon to instantly update inventory levels, process orders as soon as they're placed, and communicate with customers about their order status, all in real-time. This system is key to Amazon's ability to provide a seamless shopping experience, from product discovery to delivery. By implementing EDA, Amazon can scale its operations efficiently, manage millions of products, and handle the dynamic nature of online shopping, ensuring customer satisfaction and operational excellence.

When to Use Event-Driven Architecture

Event-Driven Architecture shines in scenarios where applications or systems require real-time responsiveness, flexibility, and scalability. Here are a few situations where EDA is particularly beneficial:

  • Real-time Data Processing: Applications that require immediate processing of data, such as financial trading platforms or online gaming systems, benefit from EDA's capacity to handle data streams efficiently.
  • Microservices Communication: EDA supports loosely coupled microservices, enabling them to communicate and function independently, which is crucial for complex, distributed applications.
  • Asynchronous Workflows: Systems that involve long-running, asynchronous tasks can leverage EDA to improve performance and user experience by processing tasks in the background.
  • Complex Event Processing: In scenarios involving the analysis of multiple events to detect patterns, EDA facilitates the aggregation, filtering, and analysis of event streams in real time.

When Not to Use Event-Driven Architecture

While EDA offers significant advantages, it is not suitable for all scenarios. Here are situations where an alternative architecture might be more appropriate:

  • Simple, Monolithic Applications: For applications with straightforward workflows and minimal real-time data processing, a monolithic architecture might be simpler and more cost-effective.
  • Low Latency Critical Systems: While EDA supports real-time processing, the inherent latency in propagating events through brokers might not meet the strict latency requirements of some systems.
  • Limited Development Resources: Small teams or projects with limited expertise in asynchronous programming and distributed systems may struggle with the complexity of EDA.

Pros and Cons

Pros Cons
Scalability EDA allows systems to scale more efficiently by decoupling services and distributing processing.
Flexibility Changes to one part of the system can be made independently, reducing the impact on the overall system.
Real-Time Responsiveness EDA supports real-time data processing and immediate response to events.
Loose Coupling Services in an EDA are loosely coupled, enhancing system resilience and making it easier to update or replace components.

Grab this

Micheal Jackson Eating
Event-Driven Architecture (EDA) is a dynamic and responsive design paradigm embraced by leading companies like Netflix, Twitter, and Amazon to enhance real-time data processing, system flexibility, and user engagement. By leveraging events, producers, consumers, and messaging systems, EDA facilitates scalable, loosely coupled, and efficient systems. Despite its complexity and testing challenges, EDA's benefits in scalability, real-time responsiveness, and flexibility make it a powerful choice for modern, distributed applications.

Let's wrap up

Jumping into conclusion
EDA offers a powerful paradigm for building responsive, scalable, and flexible systems. Its adoption by industry giants like Netflix, Twitter, and Amazon speaks volumes about its potential to handle complex, real-time data and operations. However, the decision to implement EDA should be weighed against the system's requirements, organizational capabilities, and potential challenges. When appropriately applied, EDA can transform the way businesses operate, enabling them to thrive in the fast-paced, data-driven world of today.

Top comments (16)

efpage profile image
Eckehard • Edited

Most readers will not be in the situation to implement Amazon for new, so we should ask: does this serve for everyday tasks.

If you use any UI-library like React, you have no choice. React uses a state based reactivity. This reduces the intellectual burden on the developer, as it manages state transitions automatically. But this comes at a price: You just recognize that a state has changed, but not, why. And it can be challenging to find the right timing. If you call the rendering loop on every input, the system can be overloaded. If you use some kind of throtteling, the system may feel slow.

Event based systems are much different, as they can react much more specific. They exactliy know, when and why a state has changed. So the reaction can be very specific. The downside is, that they exactly need to know the dependencies that are affected by an event. If a page is quite complex, it might be impossible to maintain all dependencies manually, so you need some automatic tools to help you.

For small systems, the easiest form of event driven architecture can be achieved using event handlers. Each DOM element can have numerous handlers like onclick(). The event fires in the moment the user clicks. This works pretty well, but the downside is, that all participants need to know each other. Larger systems may use a centralized broker or dispatcher, like described above. This allows a more organized way to handle events.

It is often not possible to mix both architectures, though this would be the ideal approach to get the optimum speed and convenience. If you know a system that manages to use that kind of "hybrid" approach, please let me know.

yokwejuste profile image
Steve Yonkeu

So it's good to keep in mind that react has an event driven approach but as for architecture is something really different.

efpage profile image

Could you explain this a bit more? Surely reconciliation will be triggered by user actions, but in my understanding this is different from an EDA. In EDA Events trigger specific actions, while in a state based approach all events trigger the same action.

Thread Thread
yokwejuste profile image
Steve Yonkeu


adaptive-shield-matrix profile image
Adaptive Shield Matrix • Edited

I think the "When Not to Use Event-Driven Architecture" is wrong.
It is only right if you make the architectural assumptions of using multiple microservices.
If you use a simpler, in-memory variants none of the downsides apply.

I would add that you can use event driven architecture in a monolith.
And you are not required/forced to use a bus or message broker and especially not as a separate microservice.
In a monolith you can just call the code/event handlers directly in a giant switch/if statement/function.

You can even replace the message brocker with a database like postgres.
There is a whole article on how to use postgres as a job queue and it can be used the same to distribute messages as well

And you can simplify even further by using sqlite -> so everything is just a single service. Sqlite is even more stable/tested/used than any other database out where.

That's why its so hard to write articles about technological/architectural decisions, because every little detail is important and can completely turn around and/or negate any pro-con comparison.

yokwejuste profile image
Steve Yonkeu

Thanks for your insightful comment! You've highlighted an important aspect of Event-Driven Architecture (EDA)—its flexibility and adaptability across different architectural styles, not just in microservices. Indeed, incorporating EDA within a monolithic application can leverage in-memory or database-based event handling, sidestepping the need for a dedicated message broker. Your mention of using databases like PostgreSQL or SQLite as alternatives for message distribution illustrates the versatility of EDA in accommodating various implementation strategies. This underscores the necessity of considering specific project requirements and contexts when discussing the pros and cons of architectural choices. I appreciate the reminder that technology discussions should account for the nuances that can significantly influence decision-making.

nyangweso profile image
Rodgers Nyangweso

very descriptive, piece here, thanks for sharing

yokwejuste profile image
Steve Yonkeu

You're welcome 🚀

saroarhossain57 profile image
Saroar Hossain

Easiest to understand the architecture. Thanks sir!

yokwejuste profile image
Steve Yonkeu

You're welcome

ptakeda profile image

Well written article and very well explained. Congrats !

yokwejuste profile image
Steve Yonkeu

Thanks 😌

ellouloufisher profile image

Event driven has existed since the dawn of computer.

yokwejuste profile image
Steve Yonkeu

Definitely 😅

ribinkroy profile image

One of the best article. Thank you and keep doing it

yokwejuste profile image
Steve Yonkeu