5 Must-Know Distributed Systems Design Patterns For Event-Driven Architectures - by Arslan Ahmad - Level Up Coding
5 Must-Know Distributed Systems Design Patterns For Event-Driven Architectures - by Arslan Ahmad - Level Up Coding
Open in app
Search
Member-only story
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 1/16
17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding
enabling real-time data processing, scalability, and system decoupling. This blog
post will serve as your roadmap to understanding the design patterns that lie at the
heart of these architectures. From the Publisher/Subscriber Pattern to Event
Sourcing, Backpressure, and more, we’ll dive deep into the strategies that underpin
modern distributed systems.
1. Publishers: These are the components that generate and send out messages, or
“events”. Publishers do not send the messages directly to specific recipients.
Instead, they categorize the messages into topics without knowing if any
subscribers will receive them.
2. Subscribers: These are the components that receive and process the messages.
Subscribers express interest in one or more topics, and only receive messages
that are of interest, without knowing which publishers, if any, there are.
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 2/16
17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding
Message Broker
The key feature of the Pub-Sub pattern is the decoupling of publishers and
subscribers. The publishers and subscribers don’t need to know each other. They
simply send or receive messages through the event channel or message broker. This
decoupling allows for greater scalability and adaptability in system design.
In other words, a component can publish a message, and any number of interested
components — zero, one, or more — can receive that message. This asynchronous
communication method allows for the development of loosely coupled and highly
scalable systems.
1. Event Producers: These are the sources of the events. They generate data that
becomes a part of the stream. This could be anything from user interactions in a
web app to data from IoT devices.
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 3/16
17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding
2. Event Stream: This is the sequence of events generated by the event producers.
Each event is usually a self-contained piece of data that represents a state
change in the system.
3. Event Consumers: These are the services or systems that consume the events.
They subscribe to the stream and perform actions based on the events they
receive.
4. Event Storage: This is where the event stream is stored, often in the order that
the events are produced. The stored stream can be used for real-time processing
(consumers react immediately to incoming events) or for historical analysis.
Platforms such as Apache Kafka, Amazon Kinesis, or Google Cloud Pub/Sub are
often used to implement event streaming.
Real-time processing: Since events are processed as they arrive, the system can
respond to events in real-time.
Scalability: This pattern can handle high volumes of events, making it suitable
for large, complex systems.
Auditability: Since all changes are recorded as a series of events, the history of
operations is available for auditing.
However, it’s worth noting that event streaming may not be suitable for all use cases,
especially when data consistency at all times is critical, or when there are strict
transactional requirements. In such cases, traditional database architectures might
be more suitable.
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 4/16
17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding
www.designgurus.io
1. Events: These are the fundamental building blocks of the Event Sourcing
Pattern. Each event represents a change to the application’s data. These events
are stored in the order they occur, creating a comprehensive log of all changes
made to the system’s state.
2. Event Store: This is the data store that records all the events. Each event is
appended to the event store and cannot be modified or deleted, ensuring the
immutability of the event log.
3. Replayability: Since all state changes are recorded, it’s possible to reproduce the
system’s state at any given point by replaying the events. This can be used to
debug issues, perform audits, or even rollback changes.
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 5/16
17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding
Auditability and Traceability: The log of events serves as an audit trail that
provides complete traceability of all actions taken in the application.
Temporal Querying: It enables the ability to query the state of the application at
any point in time.
Event Replay: Allows for the recreation of the system state as needed, which can
be very useful for debugging issues.
However, event sourcing can also add complexity to your application and may not
be suitable for all use cases. The additional storage needs, increased data handling,
and the need to manage and maintain event schemas are all important factors to
consider when deciding whether to use this pattern.
4. Backpressure Pattern
The Backpressure Pattern is a design principle used in various systems and
protocols to ensure stability under load. It’s often utilized in networking, streaming
data processing, and similar scenarios where you have to control the rate of data
flow between components of a system to prevent the system from becoming
overloaded.
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 6/16
17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding
Design Gurus has most comprehensive list of courses on system design and coding
interviews. Take a look at Grokking Microservices Design Patterns to master microservices
design patterns.
1. Buffering: The consumer maintains a buffer where incoming data is stored until
it can be processed. If the buffer fills up, the producer is instructed to slow
down or pause its data generation.
The goal of backpressure is to create a resilient system that can gracefully handle
load spikes and avoid catastrophic failures. It is used widely in data-intensive, real-
time systems, such as video streaming, real-time data processing, or high-load web
servers. Platforms like Akka, Reactive Streams in Java, and Node.js streams use
backpressure mechanisms.
5. Saga Pattern
The Saga pattern is a design pattern in microservices architecture, which provides a
mechanism to implement a distributed transaction that spans multiple services. The
main objective of the Saga pattern is to ensure data consistency across services in
scenarios where a distributed transaction might need to be managed in a decoupled,
asynchronous, and failure-tolerant manner.
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 7/16
17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding
The order service begins the Saga by starting the local transaction to create an
order.
If any of these steps fail, the Saga initiates compensating transactions to undo the
preceding steps and maintain data consistency. For instance, if the inventory service
finds that the item is out of stock, it will initiate a compensating transaction to
increase the customer’s credit limit and cancel the order.
Overall, the Saga pattern helps in maintaining data consistency across various
services in a microservices architecture without relying on distributed transactions.
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 8/16
17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding
But it does come with the added complexity of having to handle failures and design
compensating transactions.
Conclusion
In the realm of distributed systems, understanding design patterns is akin to
possessing the architect’s blueprint. As we’ve explored, patterns like Pub-Sub, Event
Sourcing, Backpressure, and others are foundational to crafting efficient, resilient,
and adaptable event-driven architectures. Though each has its own use cases and
trade-offs, their combined usage paves the way for robust systems that can manage
today’s data-driven workloads. Armed with the insights from this blog post, you’re
now better equipped to navigate the dynamic landscape of distributed systems and
harness the power of event-driven design patterns. Keep experimenting, keep
learning, and remember — each system is unique, requiring a tailored approach and
the right combination of patterns. Embrace the challenge and happy architecting!
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 9/16
17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding
Follow
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 10/16
17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding
What if you don’t like to practice 100s of coding questions before the interview?
5d ago 744 16
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 11/16
17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding
6d ago 76 1
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 12/16
17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding
Ketan Patel
Oct 9 397 3
Amit Verma
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 13/16
17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding
Jun 28 361 9
Lists
AI Regulation
6 stories · 623 saves
ChatGPT prompts
50 stories · 2235 saves
Parser
Jul 11 6
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 14/16
17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding
Bishwa Poudel
Nov 8 272 5
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 15/16
17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding
Jul 3 205 2
Oct 23 6.3K 28
https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 16/16