Pattern Description: Chapter 4. Microservices Architecture Pattern
Pattern Description: Chapter 4. Microservices Architecture Pattern
Pattern Description: Chapter 4. Microservices Architecture Pattern
Microservices Architecture
Pattern
Pattern Description
Regardless of the topology or implementation style you chose, there are
several common core concepts that apply to the general architecture
pattern. The first of these concepts is the notion of separately deployed
units. As illustrated in Figure 4-1, each component of the microservices
architecture is deployed as a separate unit, allowing for easier deployment
through an effective and streamlined delivery pipeline, increased
scalability, and a high degree of application and component decoupling
within your application.
Perhaps the most important concept to understand with this pattern is the
notion of a service component. Rather than think about services within a
microservices architecture, it is better to think about service components,
which can vary in granularity from a single module to a large portion of
the application. Service components contain one or more modules (e.g.,
Java classes) that represent either a single-purpose function (e.g.,
providing the weather for a specific city or town) or an independent
portion of a large business application (e.g., stock trade placement or
determining auto-insurance rates). Designing the right level of service
component granularity is one of the biggest challenges within a
microservices architecture. This challenge is discussed in more detail in
the following service-component orchestration subsection.
Pattern Topologies
While there are literally dozens of ways to implement a microservices
architecture pattern, three main topologies stand out as the most common
and popular: the API REST-based topology, application REST-based
topology, and the centralized messaging topology.
The API REST-based topology is useful for websites that expose small,
self-contained individual services through some sort of API (application
programming interface). This topology, which is illustrated in Figure 4-2,
consists of very fine-grained service components (hence the name
microservices) that contain one or two modules that perform specific
business functions independent from the rest of the services. In this
topology, these fine-grained service components are typically accessed
using a REST-based interface implemented through a separately deployed
web-based API layer. Examples of this topology include some of the
common single-purpose cloud-based RESTful web services found by
Yahoo, Google, and Amazon.
If you find you need to orchestrate your service components from within
the user interface or API layer of the application, then chances are your
service components are too fine-grained. Similarly, if you find you need to
perform inter-service communication between service components to
process a single request, chances are your service components are either
too fine-grained or they are not partitioned correctly from a business
functionality standpoint.
The shared database can handle information needs, but what about shared
functionality? If a service component needs functionality contained within
another service component or common to all service components, you can
sometimes copy the shared functionality across service components
(thereby violating the DRY principle: don’t repeat yourself). This is a
fairly common practice in most business applications implementing the
microservices architecture pattern, trading off the redundancy of repeating
small portions of business logic for the sake of keeping service
components independent and separating their deployment. Small utility
classes might fall into this category of repeated code.
Considerations
The microservices architecture pattern solves many of the common issues
found in both monolithic applications as well as service-oriented
architectures. Since major application components are split up into
smaller, separately deployed units, applications built using the
microservices architecture pattern are generally more robust, provide
better scalability, and can more easily support continuous delivery.
Another advantage of this pattern is that it provides the capability to do
real-time production deployments, thereby significantly reducing the need
for the traditional monthly or weekend “big bang” production
deployments. Since change is generally isolated to specific service
components, only the service components that change need to be
deployed. If you only have a single instance of a service component, you
can write specialized code in the user interface application to detect an
active hot-deployment and redirect users to an error page or waiting page.
Alternatively, you can swap multiple instances of a service component in
and out during a real-time deployment, allowing for continuous
availability during deployment cycles (something that is very difficult to
do with the layered architecture pattern).
One final consideration to take into account is that since the microservices
architecture pattern is a distributed architecture, it shares some of the same
complex issues found in the event-driven architecture pattern, including
contract creation, maintenance, and government, remote system
availability, and remote access authentication and authorization.
Pattern Analysis
The following table contains a rating and analysis of the common
architecture characteristics for the microservices architecture pattern. The
rating for each characteristic is based on the natural tendency for that
characteristic as a capability based on a typical implementation of the
pattern, as well as what the pattern is generally known for. For a
side-by-side comparison of how this pattern relates to other patterns in this
report, please refer to Appendix A at the end of this report.
Overall agility
Rating: High
Ease of deployment
Rating: High
Testability
Rating: High
Performance
Rating: Low
Scalability
Rating: High
Ease of development
Rating: High