Skip to content

Commit

Permalink
Minor updates to event-driven architecture content.
Browse files Browse the repository at this point in the history
  • Loading branch information
applebyter committed Mar 16, 2024
1 parent 4327d7b commit 0d5d369
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 54 deletions.
37 changes: 18 additions & 19 deletions notes/event/content.tex
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ \section{Introduction}\label{sec:intro}

\filbreak
An auction system, as shown in figure \ref{fig:auction-architecture}, could be implemented as an event-driven architecture.
\begin{itemize}[nosep]
\item When a customer bids on an item, they initiate a bid \emph{event}.
\item Upon receiving the bid event, the event broker notifies the bid handler, which checks the bid against the current high bid and determines the new high bid.
\item The bid handler generates a new high bid event.
\item The event broker notifies the page update handler of the high bid event, which sends the new high bid to all pages displaying the item.
\item The bid notification handler is also notified of the high bid event and it sends an email to the bidder with the result of their bid.
\item And, the rebid notification handler is also notified of the high bid event.
If the previous high bidder is no longer the high bidder, they are sent an email asking if they would like to make another bid.
\begin{itemize}[topsep=2pt,partopsep=1pt,itemsep=1pt,parsep=1pt]
\item When a customer bids on an item, they initiate a \textit{bid event}.
\item Upon receiving the \textit{bid event}, the event broker notifies the bid handler, which checks the bid against the current high bid and determines the new high bid.
\item The bid handler generates a new \textit{high bid event}.
\item The event broker notifies the page update handler of the \textit{high bid event}, which sends the new high bid to all pages displaying the item.
\item The bid notification handler is also notified of the \textit{high bid event} and it sends an email to the bidder with the result of their bid.
\item And, the rebid notification handler is also notified of the \textit{high bid event}.
If the previous high bidder is no longer the high bidder, they are sent an email asking if they would like to make another bid.
\end{itemize}

\begin{figure}[h!]
Expand All @@ -67,15 +67,15 @@ \section{Broker Topology}

The broker topology consists of five elements.

\begin{description}
\begin{description}[topsep=6pt,partopsep=2pt,itemsep=4pt,parsep=4pt]
\item[Initiating Event] starts the flow of events.
\item[Event Broker] has \emph{event channels} that receive events waiting to be handled.
\item[Event Channel] holds events waiting to be processed by an event handler.
\item[Event Handler] accepts and processes events.
\item[Processing Event] sent by an event handler when it has finished processing an event.
\end{description}

% Possibly extend the auction example to make this more concrete?
%TODO Possibly extend the auction example to make this more concrete?
% It will need to show events being ignored by system, and handlers not sending events at the end of processing.
\begin{figure}[h!]
\begin{adjustwidth}{-10mm}{-10mm}
Expand All @@ -91,7 +91,7 @@ \section{Broker Topology}
Upon completion of handling the \emph{Initiating Event},
\emph{Event Handler A} sends \emph{Processing Event 1} to the appropriate channel in the event broker.
\emph{Event Handlers B} and \emph{C} accept this processing event and perform their actions.
When \emph{Event Handler C} finishes processing it sends \emph{Processing Event 2} to its channel.
When \emph{Event Handler C} finishes processing, it sends \emph{Processing Event 2} to its channel.
No event handler is designed to accept \emph{Processing Event 2}, so it is ignored.

Different event channels in the event broker provide a simple mechanism to coordinate the flow of events in a business process.
Expand All @@ -107,8 +107,8 @@ \section{Broker Topology}
Each event handler is a simple cohesive unit that performs a single processing task.
\end{definition}

The \emph{event handler cohesion principle} minimises the complexity of each handler,
and improves the ability of the system to scale only the tasks that need additional computing resources.
The \emph{event handler cohesion principle} minimises the complexity of each handler and
improves the ability of the system to scale only the tasks that need additional computing resources.

\vspace{1mm}
\begin{definition}[Event Handler Independence Principle]\label{def:independence}
Expand All @@ -128,7 +128,7 @@ \subsection{Extensibility}\label{sec:extensibility}
A new feature can be added by implementing an event handler to do something new when an event is received by the event broker.

In figure \ref{fig:broker-components}, when \emph{Event Handler C} finishes processing its event it sends \emph{Processing Event 2} to the event broker.
The diagram indicates that the system does not handle the event.
The diagram indicates that the system does not handle this event.
The purpose of doing this is to make it easier to extend the system.
Currently, the system may not need to do anything when \emph{Event Handler C} finishes processing,
but because it sends an event to indicate it has finished it means other tasks can be added to the system following \emph{Event Handler C}.
Expand Down Expand Up @@ -224,7 +224,7 @@ \subsection{Queues vs. Streams}
This is because there is a fixed set of rules about which event handlers process which events.

Streams work well when there are multiple event handlers responding to events,
particularly when event handlers may choose to ignore some events based on various conditions.
particularly when event handlers may choose to ignore some events based on certain conditions.
Streams mean that the event broker or channels do not need to be notified if an event handler wants to ignore an event.
Because streams store events permanently, data analysis of the system's behaviour can be done by processing past events.
Streams work well for social media platforms as monetisation of the platform depends on analysing user behaviour.
Expand All @@ -246,6 +246,7 @@ \subsection{Queues vs. Streams}

Streams also enable \emph{event sourcing} as a persistence mechanism.
Event sourcing stores every event, and its associated state, rather than storing and updating system state.
System state at any earlier point in time can be recreated from the event history.
This makes it easier to analyse how the system is used and what changes happen to the state over time.

% Add example broker-based event-driven architecture for Sahara.
Expand Down Expand Up @@ -399,8 +400,7 @@ \section{Broker vs. Mediator Topologies}\label{sec:broker-vs-mediator}

\bigskip\noindent
\textbf{Broker Advantages}

\begin{itemize}
\begin{itemize}[topsep=8pt,partopsep=4pt,itemsep=6pt,parsep=6pt]
\item Greater scalability because the broker just distributes event notifications and does not have state,
it is easier to federate the broker to provide greater throughput.
\item Greater reliability because the broker does not coordinate the business process.
Expand All @@ -410,8 +410,7 @@ \section{Broker vs. Mediator Topologies}\label{sec:broker-vs-mediator}

\noindent
\textbf{Mediator Advantages}

\begin{itemize}
\begin{itemize}[topsep=8pt,partopsep=4pt,itemsep=6pt,parsep=6pt]
\item Allows for more complex business process logic and error handling.
\item Can store process state and restart a process after recovering from an error.
\end{itemize}
Expand Down
113 changes: 78 additions & 35 deletions slides/event/main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
\Large\item Send message
\Large\item Wait for response
\Large\item Continue processing
\end{itemize}
\end{itemize}
\vspace{3mm}
\item Asynchronous Communication ~~~~~~\includegraphics[width=8mm]{../../shared/images/thumbs-up.png}
\item<2-> Asynchronous Communication ~~~~~~\includegraphics[width=8mm]{../../shared/images/thumbs-up.png}
\begin{itemize}
\Large\item Send message
\Large\item Continue processing
Expand Down Expand Up @@ -84,7 +84,7 @@
\item Bid Processor could send back a high bid event or an async message.
}

\definition{Event Handler Cohesion Principle}{Each event handler is a simple cohesive unit that performs a single processing task.}
\definition{Event Handler Cohesion Principle}{Each event handler is a simple cohesive unit that performs a \highlight{single} processing task.}

\definition{Event Handler Independence Principle}{Event handlers should not depend on the implementation of any other event handler.}

Expand All @@ -108,9 +108,9 @@
\begin{itemize}
\Large\item Notifies event handlers of events
\Large\item Event handlers send processing events when they finish processing
\end{itemize}
\end{itemize}
\vspace{3mm}
\item[Mediator] Manages the business process
\item[Mediator]<2-> Manages business process
\begin{itemize}
\Large\item Event queue of initiating events
\Large\item Event mediator sends processing events to event handlers
Expand All @@ -129,6 +129,10 @@
\note[itemize]{
\item Step through event process.
\item Describe idea of channels.
\item Send final processing event, even if it is not handled.
\begin{itemize}
\item Easier to extend in the future.
\end{itemize}
}

\point[Event Broker Façade]{
Expand Down Expand Up @@ -159,26 +163,28 @@
\end{frame}
\note[itemize]{
\item Step through event process.
\item Highlight multiple mediators as common implementation.
\item Multiple mediators is common -- \highlight{one} per domain.
\item Discuss internals of mediators: event queue and event channels.
}

%TODO Add component diagram showing internals of one mediator container.

\begin{frame}{Extensibility}
\vspace{1mm}
{\LARGE
\begin{itemize}
\item New behaviour for existing event
{\Large
{\vspace{1mm}\Large
\begin{description}
\item[Broker] Implement event handler \& register with broker
\begin{itemize}
\item Existing ignored event hooks
\large\item Existing ignored event hooks
\end{itemize}
\item[Mediator] Implement event handler \& modify mediator logic
\end{description}
}
\vspace{3mm}
\item New event
\item<2-> New event
{\Large
\begin{description}
\item[Broker] Implement event \& event handler, create event channel, modify broker façade
Expand All @@ -189,6 +195,8 @@
}
\end{frame}

%TODO Add diagrams showing adding new event handler & adding new event to Broker topology.

%\begin{frame}{Broker Topology}
% \begin{adjustwidth}{-10mm}{-10mm}
% \centering
Expand All @@ -200,27 +208,61 @@
% \item Describe idea of channels.
%}

%TODO Add diagrams showing adding new event handler & adding new event to Mediator topology.

%\begin{frame}{Extensibility -- Mediator}
% \vspace{1mm}
% {\LARGE
% \begin{itemize}
% \item New behaviour for existing event
% {\vspace{1mm}\Large
% \begin{description}
% \item[Mediator] Implement event handler \& modify mediator logic
% \end{description}
% }
% \vspace{3mm}
% \item<2-> New event
% {\Large
% \begin{description}
% \item[Mediator] Implement event \& event handler, modify mediator logic
% \end{description}
% }
% \end{itemize}
% }
%\end{frame}
%
%\begin{frame}{Mediator Topology}
% \begin{adjustwidth}{-10mm}{-10mm}
% \centering
% \includegraphics[trim=195 195 195 195,clip,width=1.43\paperheight]{../../notes/event/diagrams/mediator-components.png}
% \end{adjustwidth}
%\end{frame}
%\note[itemize]{
% \item Step through event process.
% \item Highlight process control performed by mediator.
%}

\begin{frame}{Scalability}
\vspace{1mm}
{\LARGE
\begin{itemize}
\item Event handlers deployed independently
\begin{itemize}
\Large\item Scaled independently to manage load
\end{itemize}
\end{itemize}
\vspace{3mm}
\item Event broker federated
\item<2-> Event broker federated
\begin{itemize}
\Large\item Distributed across multiple compute nodes
\end{itemize}
\end{itemize}
\vspace{3mm}
\item Event mediators for different domains
\item<3-> Event mediators for different domains
\begin{itemize}
\Large\item Distributes loads by domain\\(e.g. browse \& search, account, \& order events)
\begin{itemize}
\item Scaled independently to manage load
\large\item Scaled independently to manage load
\end{itemize}
\end{itemize}
\end{itemize}
\end{itemize}
}
\end{frame}
Expand All @@ -232,22 +274,22 @@
\item Channels can be implemented as queues
\begin{itemize}
\Large\item FIFO behaviour
\end{itemize}
\end{itemize}
\vspace{3mm}
\item Multiple front of queue pointers
\item<2-> Multiple front of queue pointers
\begin{itemize}
\Large\item For each event handler
\end{itemize}
\end{itemize}
\vspace{3mm}
\item Event removed when event handlers finish
\item<3-> Event removed when event handlers finish
\begin{itemize}
\Large\item Retry if a handler fails
\end{itemize}
\end{itemize}
\vspace{3mm}
\item Events persisted until removed
\item<4-> Events persist until removed
\begin{itemize}
\Large\item Recovery from broker failure
\end{itemize}
\end{itemize}
\end{itemize}
}
\end{frame}
Expand All @@ -259,23 +301,24 @@
\item Channels can be implemented as streams
\begin{itemize}
\Large\item Events are saved permanently
\end{itemize}
\end{itemize}
\vspace{3mm}
\item Handlers notified when event added to stream
\item<2-> Handlers notified when event added to stream
\begin{itemize}
\Large\item Observer pattern
\end{itemize}
\end{itemize}
\vspace{3mm}
\item Handlers process events at their own pace
\item<3-> Handlers process events at their own pace
\begin{itemize}
\Large\item Cardiac arrest alarm vs. heart rate graph
\end{itemize}
\end{itemize}
\vspace{3mm}
\item Events history
\item<4-> Events history
\begin{itemize}
\Large\item Redo processing
\vspace{0.5mm}
\Large\item Review processing activities
\end{itemize}
\end{itemize}
\end{itemize}
}
\end{frame}
Expand All @@ -290,15 +333,15 @@
\Large\item Easier sequencing of steps in business process
\Large\item ``Exactly once'' semantics
\Large\item eCommerce system
\end{itemize}
\end{itemize}
\vspace{3mm}
\item Stream
\item<2-> Stream
\begin{itemize}
\Large\item Very large number of events or handlers
\Large\item Handlers can ignore events
\Large\item Analysis of past activity
\Large\item Event sourcing
\end{itemize}
\end{itemize}
\end{itemize}
}
\end{frame}
Expand All @@ -311,9 +354,9 @@
\vspace{3mm}
\item[Broker] events have occurred
\vspace{3mm}
\item[Mediator] smart pipe
\item[Mediator]<2-> smart pipe
\vspace{3mm}
\item[Mediator] events are commands to process
\item[Mediator]<2-> events are commands to process
\end{description}
}
\end{frame}
Expand All @@ -333,7 +376,7 @@
}
\end{column}
\begin{column}{0.59\textwidth}
{\LARGE
{\onslide<2->\LARGE
\highlight{Mediator Advantages}
\begin{itemize}
\item Complex business process logic
Expand Down

0 comments on commit 0d5d369

Please sign in to comment.