0% found this document useful (0 votes)
52 views

5 Must-Know Distributed Systems Design Patterns For Event-Driven Architectures - by Arslan Ahmad - Level Up Coding

Distributed Systems Design Patterns

Uploaded by

Manoj Goyal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

5 Must-Know Distributed Systems Design Patterns For Event-Driven Architectures - by Arslan Ahmad - Level Up Coding

Distributed Systems Design Patterns

Uploaded by

Manoj Goyal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

17/11/2024, 17:01 5 Must-Know Distributed Systems Design Patterns for Event-Driven Architectures | by Arslan Ahmad | Level Up Coding

Open in app

Search

Member-only story

PATTERNS FOR EVENT-DRIVEN ARCHITECTURES

5 Must-Know Distributed Systems Design


Patterns for Event-Driven Architectures
Explore the Key Design Patterns That Power Today’s Robust Event-Driven Systems

Arslan Ahmad · Follow


Published in Level Up Coding
9 min read · May 26, 2023

Listen Share More

In our interconnected world, the power of distributed systems is leveraged more


than ever. Among these, event-driven architectures stand as a formidable paradigm,

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.

Here is the outline of this blog:

Patterns for Event-Driven Architectures


1. Publisher/Subscriber Pattern (Pub-Sub)
2. Event Streaming Pattern
3. Event Sourcing Pattern
4. Backpressure Pattern
5. Saga Pattern
Conclusion

1. Publisher/Subscriber Pattern (Pub-Sub)


The Publisher/Subscriber pattern, also known as Pub-Sub, is a messaging pattern
used in event-driven architectures and distributed systems. This pattern involves
two types of components — publishers and subscribers — and is characterized by
the following:

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.

3. Message Broker or Event Channel: This is the intermediary that distributes


events from publishers to subscribers. It manages the connections between the
publishers and subscribers and routes events appropriately.

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.

Popular implementations of the Pub-Sub pattern include Google’s Cloud Pub/Sub,


AWS’s Simple Notification Service (SNS), and the publish-subscribe model of
message brokers like RabbitMQ and Apache Kafka.

Take a look at Grokking Microservices Design Patterns to master these design


patterns for designing scalable, resilient, and more manageable systems.

2. Event Streaming Pattern


The Event Streaming Pattern is a design pattern often used in distributed systems
and event-driven architectures. In essence, it involves the continuous generation,
processing, and transport of events from various event producers to consumers.

Key components of an event streaming pattern typically include:

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.

The main benefits of this pattern include:

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.

Loose coupling: Event producers and consumers are decoupled, meaning a


change in one does not require a change in the other.

Resiliency: Because events are stored, they can be reprocessed if a consumer


fails the first time.

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.

Demystifying System Design Interviews: A Guide


Struggling with system design interviews? Unlock expert guidance,
strategies, and practice questions to ace your…

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

3. Event Sourcing Pattern


The Event Sourcing Pattern is a design pattern that dictates the storage of every state
change to an application’s data as a unique event in an ordered sequence, rather
than simply overwriting the data in a database.

Here’s a more detailed breakdown:

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.

4. Snapshotting: To speed up the recreation of state at a certain point, snapshots


can be used. Snapshots store the state of a system at a given point in time. When
the system needs to be recreated, it can start from the snapshot and then replay
only the events that occurred after the snapshot was taken.

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

The Event Sourcing Pattern offers several benefits:

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

The backpressure pattern is typically employed in a scenario where data is being


passed from a faster component (the producer) to a slower component (the
consumer). Without backpressure, the slower component can become overwhelmed
with data, resulting in a resource crunch, decreased performance, and potential
system failure.

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.

The way backpressure works is by providing a mechanism for the consumer to


signal the producer about its current capacity. This signaling can be explicit, where
the consumer sends feedback to the producer about its load, or implicit, where the
absence of an acknowledgment from the consumer is treated as a sign of overload.

Here are the two common strategies of applying backpressure:

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.

2. Dropping: In some cases, especially where real-time data is involved, outdated


or less critical data can be dropped. When the consumer can’t keep up, instead
of buffering more data, the system discards some incoming data.

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.

Here is a brief overview of how the Saga pattern works:

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

1. Local Transactions: Each Saga is a sequence of local transactions. Each local


transaction updates the database and then publishes an event to trigger the next
local transaction in the Saga.

2. Compensating Transactions: Each local transaction has a corresponding


compensating transaction that undoes the changes that were made in the local
transaction.

3. Coordinator: The Saga has a coordinator that centralizes the decision-making


process. When a local transaction fails to complete, the coordinator executes the
compensating transactions to maintain data consistency.

Here is an example: suppose you have a microservice architecture for an e-


commerce application. A customer places an order, which involves three services —
the order service, the customer service, and the inventory service. These services
need to work together to complete the order:

The order service begins the Saga by starting the local transaction to create an
order.

The customer service decreases the customer’s credit limit.

The inventory service decreases the inventory.

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!

Take a look at Grokking Microservices Design Patterns to master these


microservices design patterns for designing scalable, resilient, and more
manageable systems.

12 Microservices Patterns I Wish I Knew Before the System Design


Interview
Mastering the Art of Scalable and Resilient Systems with Essential
Microservices Design Patterns
levelup.gitconnected.com

Mastering the System Design Interview: A Complete Guide


Mastering the System Design Interview: A Complete Guide Unlock
the path to acing system design interviews with our…
www.designgurus.io

System Design Interview Survival Guide (2023): Preparation


Strategies and Practical Tips
System Design Interview Preparation: Mastering the Art of System
Design.
levelup.gitconnected.com

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

System Design Interview Technology Microservices Event Driven Architecture

Follow

Written by Arslan Ahmad


15K Followers · Writer for Level Up Coding

Founder www.designgurus.io | Formally a software engineer @ Facebook, Microsoft, Hulu, Formulatrix |


Entrepreneur, Software Engineer, Writer.

More from Arslan Ahmad and Level Up Coding

Arslan Ahmad in Level Up Coding

Don’t Just LeetCode; Follow the Coding Patterns Instead

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?

Sep 16, 2022 10.8K 78

Attila Vágó in Level Up Coding

The M4 Mac Mini, Everything A Developer Must Know


Let’s see just how much the 16 GB M4 Mac mini can deliver to software engineers. Might it even
turn out to be the best developer machine…

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

Senthil E in Level Up Coding

LangGraph for Healthcare: A Comprehensive Technical Guide


Building Production-Ready Medical Operations Agents

6d ago 76 1

Arslan Ahmad in Level Up Coding

10 Golden Heuristics for Solving a Coding Question in an Interview


How to prepare smartly for coding interviews?

Dec 6, 2022 1.2K 5

See all from Arslan Ahmad

See all from Level Up Coding

Recommended from Medium

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

My interview experience for Software Architect — Java position.


Recently I gave interview for Solution Architect — Java role in one of the leading service based
companies. I am sharing here list of…

Oct 9 397 3

Amit Verma

The Software Architect: Demystifying 18 Software Architecture Patterns.


In-Depth Overview of 18 Essential Software Architecture Design Patterns.

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

Generative AI Recommended Reading


52 stories · 1502 saves

Tech & Tools


21 stories · 349 saves

Parser

Resilience in Microservices: Bulkhead vs Circuit Breaker


By Andoni Aberasturi Ramirez, at 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

10 Coding Practices Every Senior Developer Swears By


If you’ve ever wondered why senior developers seem to write code that not only works but
lasts, the secret is in their coding practices…

Nov 8 272 5

Fahim ul Haq in Grokking the Tech Interview

Cracking Amazon System Design Interview: Top Questions and Answer


When I talk to my friends at Amazon, I can’t help but wish that I’d had the chance to be on their
interviewing teams. I’ve already had my…

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

Abdur Rahman in Stackademic

Python is No More The King of Data Science


5 Reasons Why Python is Losing Its Crown

Oct 23 6.3K 28

See more recommendations

https://medium.com/gitconnected/stay-ahead-of-the-curve-5-must-know-distributed-systems-design-patterns-for-event-driven-7515121a28ae 16/16

You might also like