Software Architecture Patterns, 2nd Edition-9781098134280
Software Architecture Patterns, 2nd Edition-9781098134280
SECOND EDITION
Mark Richards
Software Architecture Patterns
by Mark Richards
While the publisher and the author have used good faith efforts
to ensure that the information and instructions contained in
this work are accurate, the publisher and the author disclaim
all responsibility for errors or omissions, including without
limitation responsibility for damages resulting from the use of
or reliance on this work. Use of the information and
instructions contained in this work is at your own risk. If any
code samples or other technology this work contains or
describes is subject to open source licenses or the intellectual
property rights of others, it is your responsibility to ensure that
your use thereof complies with such licenses and/or rights.
978-1-098-13427-3
[LSI]
Chapter 1. Introduction
It’s all too common for developers to start coding an application
without a formal architecture in place. This practice usually
results in ill-defined components, creating what is commonly
referred to as a big ball of mud. These architectures are
generally tightly coupled, brittle, difficult to change, and lack a
clear vision or direction. It’s also very difficult to determine the
architectural characteristics of applications lacking a well-
defined architectural style. Does the architecture scale? What
are the performance characteristics of the application? How
easy is it to change the application or add new features? How
responsive is the architecture?
Architecture Classification
Architecture styles are classified as belonging to one of two
main architectural structures: monolithic (single deployment
unit) and distributed (multiple deployment units, usually
consisting of services). This classification is important to
understand because as a group, distributed architectures
support much different architecture characteristics than
monolithic ones. Knowing which classification of architecture
to use is the first step in selecting the right architecture for your
business problem.
Monolithic Architectures
Distributed Architectures
Technical Partitioning
Domain Partitioning
Description
Components within the layered architecture style are organized
into horizontal layers, each performing a specific role within
the application (such as presentation logic, business logic,
persistence logic, and so on). Although the number of layers
may vary, most layered architectures consist of four standard
layers: presentation, business, persistence, and database (see
Figure 3-1). In some cases, the business layer and persistence
layer are combined into a single business layer, particularly
when the persistence logic (such as SQL) is embedded within
the business layer components. Thus, smaller applications may
have only three layers, whereas larger and more complex
business applications may contain five or more layers.
Key Concepts
In this architecture style, layers can be either open or closed.
Notice in Figure 3-2 that each layer in the architecture is
marked as being closed. A closed layer means that as a request
moves from layer to layer, it must go through the layer right
below it to get to the next layer below that one. For example, a
request originating from the presentation layer must first go
through the business layer and then to the persistence layer
before finally hitting the database layer.
Examples
To illustrate how the layered architecture works, consider a
request from a business user to retrieve customer information
for a particular individual, as illustrated in Figure 3-4. Notice
the arrows show the request flowing down to the database to
retrieve the customer data, and the response flowing back up to
the screen to display the data.
Figure 3-4. An example of the layered architecture
Architecture Characteristics
Topology
The microkernel architecture style consists of two types of
architecture components: a core system and plug-in modules.
Application logic is divided between independent plug-in
modules and the basic core system, providing extensibility,
flexibility, and isolation of application features and custom
processing logic. Figure 4-1 illustrates the basic topology of the
microkernel architecture style.
Examples
A classic example of the microkernel architecture is the Eclipse
IDE. Downloading the basic Eclipse product provides you little
more than a fancy editor. However, once you start adding plug-
ins, it becomes a highly customizable and useful product for
software development. Internet browsers are another common
example using the microkernel architecture: viewers and other
plug-ins add additional capabilities that are not otherwise
found in the basic browser (the core system). As a matter of
fact, many of the developer and deployment pipeline tools and
products such as PMD, Jira, Jenkins, and so on are implemented
using microkernel architecture.
Architecture Characteristics
Topology
Event-driven architecture is an architecture style that relies on
asynchronous processing using highly decoupled event
processors that trigger events and correspondingly respond to
events happening in the system. Most event-driven
architectures consist of the following architectural components:
an event processor, an initiative event, a processing event, and an
event channel. These components and their relationships are
illustrated in Figure 5-1.
Figure 5-1. The main components of event-driven architecture
Example Architecture
To see how all of these components work together in a complete
event-driven architecture, consider the example illustrated in
Figure 5-2 where a customer wants to order a copy of
Fundamentals of Software Architecture by Mark Richards and
Neal Ford (O’Reilly). In this case, the initiating event would be
Place Order . This initiating event is received by the Order
Placement service, which then places the order for the book.
The Order Placement service in turn advertises what it did to
the rest of the system through a Order Placed processing
event.
The first difference has to do with the context of what you are
sending to the rest of the system. An event is telling others about
a state change or something you did. Examples of an event
include things like “I just placed an order,” or “I just submitted a
bid for an item.” A message, on the other hand, is a command or
request to a specific service. Examples of a message include
things like “apply a payment to this order,” “ship this item to
this address,” or “give me the customer’s email address.” Notice
the difference here—with an event, the service triggering the
event has no idea which services (or how many) will respond,
whereas a message is usually directed to a single known service
(for example, Payment ).
Figure 5-4. With messages, the receiver owns the message channel and contract
The type of event channel artifact is also a distinguishing factor
between event-driven systems and message-driven systems.
Typically, event-driven systems use publish-and-subscribe
messaging using topics or notification services when triggering
events, whereas message-driven systems typically use point-to-
point messaging using queues or messaging services when
sending messages. That’s not to say event-driven systems can’t
use point-to-point messaging—in some cases point-to-point
messaging is necessary to retrieve specific information from
another service or to control the order or timing of events in a
system.
Architecture Characteristics
Basic Topology
The microservices architecture style is an ecosystem made up
of single-purpose, separately deployed services that are
accessed typically through an API gateway. Client requests
originating from either a user interface (usually a
microfrontend) or an external request invoke well-defined
endpoints in an API gateway, which then forwards the user
request to separately deployed services. Each service in turn
accesses its own data, or makes requests to other services to
access data the service doesn’t own. The basic topology for the
microservices architecture style is illustrated in Figure 6-1.
Bounded Context
As mentioned earlier, each service typically owns its own data,
meaning that the tables belonging to a particular service are
only accessed by that service. For example, a Wishlist service
might own its corresponding wishlist tables. If other
services need wish list data, those services would have to ask
the Wishlist service for that information rather than
accessing the wishlist tables directly.
Unique Features
Microservices stands apart from all other architecture styles.
The three things that make the microservices architecture style
so unique are distributed data, operational automation, and
organizational change.
Architecture Characteristics
Examples
Space-based architecture is a very complicated and specialized
architecture style, and is primarily used for high-volume, highly
elastic systems that require very fast performance.
Architecture Characteristics
While this chart and report will help guide you in choosing the
right style, there is much more to consider when choosing an
architecture style. You must analyze all aspects of your
environment, including infrastructure support, developer skill
set, project budget, project deadlines, and application size, to
name a few. Choosing the right architecture style is critical,
because once an architecture is in place, it is very hard (and
expensive) to change.