Microservices Vs Service Oriented Architecture
Microservices Vs Service Oriented Architecture
ServiceOriented Architecture
Mark Richards
First Edition
978-1-491-94161-4
[LSI]
Table of Contents
Foreword. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
1. The World of Service-Based Architectures. . . . . . . . . . . . . . . . . . . . . . . 1
Service Contracts
Service Availability
Security
Transactions
Too Much Complexity?
2
5
7
8
9
11
14
17
19
22
24
30
33
35
36
vii
Contract Decoupling
39
5. Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
viii
| Table of Contents
Foreword
One of the fascinating aspects of software engineering is how great
concepts endure, but their execution and application are regularly
reinvented using the tools and practices of the day. The rise of
microservices patterns and practices is a great example of this pro
cess.
Skeptics may dismiss microservices as little more than the serviceoriented architecture (SOA) practices of the 2000s, reheated. The
reality is that microservices are an example of convergent evolution,
emerging from modern development, testing, and deployment tech
niques and shaped by the democratizing influence of open source.
The resulting incarnation of SOA is transforming our industry.
Whats the nature of this transformation? Early adopters report that
when used with an agile and autonomous approach to engineering
structures and a DevOps approach to delivery, the microservices
approach enables a much quicker cadence of application develop
ment. In turn, software developers welcome this, having learned
their trade in the fast-moving, app-driven world of services and
applications. The net result is faster innovation, and a potential
competitive advantage for Internet-facing organizations that
embrace these practices.
The power of microservices comes from their non-prescriptive
nature. There is no formal, slow-moving, industry-driven specifica
tion; rather, the microservices approach has emerged as a pattern of
development that has been practiced and refined by pioneers. Born
in the modern Web, microservices are interconnected using a thin
layer of simple APIs and the lingua franca of HTTP. At NGINX, we
are incredibly proud of our role in accelerating, securing, scaling,
and delivering microservices-based applications. As the HTTP
connective tissue of modern applications, NGINX serves as both
the stable entry point to a microservices-based application, and the
traffic manager for communication between the microservices
themselves.
The lack of a prescriptive industry specification is sure to raise
many, many questionsespecially if you have experience with pre
vious SOA practices. Microservices have at times been billed as
SOA done right, but is that really the case? And what exactly did
Preface
xi
CHAPTER 1
Both microservices architecture and SOA are considered servicebased architectures, meaning that they are architecture patterns that
place a heavy emphasis on services as the primary architecture com
ponent used to implement and perform business and nonbusiness
functionality. Although microservices and SOA are very different
architecture styles, they share many characteristics.
One thing all service-based architectures have in common is that
they are generally distributed architectures, meaning that service
components are accessed remotely through some sort of remoteaccess protocolfor example, Representational State Transfer
(REST), Simple Object Access Protocol (SOAP), Advanced Message
Queuing Protocol (AMQP), Java Message Service (JMS), Microsoft
Message Queuing (MSMQ), Remote Method Invocation (RMI),
or .NET Remoting. Distributed architectures offer significant
advantages over monolithic and layered-based architectures, includ
ing better scalability, better decoupling, and better control over
development, testing, and deployment. Components within a dis
tributed architecture tend to be more self-contained, allowing for
better change control and easier maintenance, which in turn leads to
applications that are more robust and more responsive. Distributed
architectures also lend themselves to more loosely coupled and
modular applications.
Service Contracts
A service contract is an agreement between a (usually remote) ser
vice and a service consumer (client) that specifies the inbound and
outbound data along with the contract format (XML, JavaScript
Object Notation [JSON], Java object, etc.). Creating and maintaining
service contracts is a difficult task that should not be taken lightly or
treated as an afterthought. As such, the topic of service contracts
deserves some special attention in the scope of service-based archi
tecture.
In service-based architecture you can use two basic types of service
contract models: service-based contracts and consumer-driven con
tracts. The real difference between these contract models is the
degree of collaboration. With service-based contracts, the service is
the sole owner of the contract and is generally free to evolve and
change the contract without considering the needs of the service
consumers. This model forces all service consumers to adopt new
service contract changes, whether or not the service consumers need
or want the new service functionality.
Consumer-driven contracts, on the other hand, are based on a closer
relationship between the service and the service consumers. With
2
Service Availability
Service availability and service responsiveness are two other consid
erations common to all service-based architectures. Although both
of these topics relate to the ability of the service consumer to com
municate with a remote service, they have slightly different mean
ings and are addressed by service consumers in different ways.
Service availability refers to the ability of a remote service to accept
requests in a timely manner (e.g., establishing a connection to the
remote service). Service responsiveness refers to the ability of the ser
vice consumer to receive a timely response from the service. The
diagram in Figure 1-3 illustrates this difference.
Although the end result of these error conditions is the same (the
service request cannot be processed), they are handled in different
ways. Since service availability is related to service connectivity,
there is not much a service consumer can do except to retry the con
nection for a set number of times or queue the request for later pro
cessing if possible.
Service responsiveness is much more difficult to address. Once you
successfully send a request to a service, how long should you wait
for a response? Is the service just slow, or did something happen in
the service to prevent the response from being sent?
Addressing timeout conditions can be one of the more challenging
aspects of remote service connectivity. A common way to determine
reasonable timeout values is to first establish benchmarks under
load to get the maximum response time, and then add extra time to
account for variable load conditions. For example, lets say you run
some benchmarks and find that the maximum response time for a
particular service request is 2,000 milliseconds. In this case you
might double that value to account for high load conditions, result
ing in a timeout value of 4,000 milliseconds.
Although this may seem like a reasonable solution for calculating a
service response timeout, it is riddled with problems. First of all, if
the service really is down and not running, every request must wait
four seconds before determining that the service is not responding.
This is inefficient and annoying to the end user of the service
request. Another problem is that your benchmarks may not have
been accurate, and under heavy load the service response is actually
averaging five seconds rather than the four seconds you calculated.
In this case the service is in fact responding, but the service con
sumer will reject every request because the timeout value is set too
low.
A popular technique to address this issue is to use the circuit breaker
pattern. If the service is not responding in a timely manner (or not
at all), a software circuit breaker will be thrown so that service con
sumers dont have to waste time waiting for timeout values to occur.
The cool thing is that unlike a physical circuit breaker, this pattern
can be implemented to reset itself when the service starts respond
ing or becomes available. There are numerous open-source imple
mentations of the circuit breaker pattern, including Ribbon from
Netflix. You can read more about the circuit breaker pattern in
Michael Nygards book Release It! (Pragmatic Bookshelf).
When dealing with timeout values, try to avoid the use of global
timeout values for every request. Instead, consider using contextbased timeout values, and always make these externally configurable
so that you can respond quickly for varying load conditions without
having to rebuild or redeploy the application. Another option is to
create smart timeout values embedded in your code that can
adjust themselves based on varying load conditions. For example,
the application could automatically increase the timeout value in
response to heavy load or network issues. As load decreases and
response times become faster, the application could then calculate
the average response time for a particular request and lower the
timeout value accordingly.
Security
Because services are generally accessed remotely in service-based
architectures, it is important to make sure the service consumer is
allowed to access a particular service. Depending on your situation,
service consumers may need to be both authenticated and author
ized. Authentication refers to whether the service consumer can con
nect to the service, usually through sign-on credentials using a user
name and password. In some cases authentication is not enough: the
fact that service consumers can connect to a service doesnt neces
sarily mean that they can access all of the functionality in that ser
vice. Authorization refers to whether or not a service consumer is
allowed to access specific business functionality within a service.
Security was a major issue with early SOA implementations. Func
tionality that used to be located in a secure silo-based application
was suddenly available globally to the entire enterprise. This issue
created a major shift in how we think about services and how to
protect them from consumers who should not have access to them.
With microservices, security becomes a challenge primarily because
no middleware component handles security-based functionality.
Instead, each service must handle security on its own, or in some
cases the API layer can be made more intelligent to handle the secu
rity aspects of the application. One security design I have seen
implemented in microservices that works well is to delegate authen
tication to a separate service and place the responsibility for authori
Security
Transactions
Transaction management is a big challenge in service-based archi
tectures. Most of the time when we talk about transactions we are
referring to the ACID (atomicity, consistency, isolation, and durabil
ity) transactions found in most business applications. ACID transac
tion are used to maintain database consistency by coordinating mul
tiple database updates within a single request so that if an error
occurs during processing, all database updates are rolled back for
that request.
Given that service-based architectures are generally distributed
architectures, it is extremely difficult to propagate and maintain a
transaction context across multiple remote services. As illustrated in
Figure 1-4, a single service request (represented by the box next to
the red X) may need to call multiple remote services to complete the
request. The red X in the diagram indicates that it is not feasible to
use an ACID transaction in this scenario.
10
CHAPTER 2
Service Taxonomy
The term service taxonomy refers to how services are classified
within an architecture. There are two basic types of service classifi
cationsservice type and business area. Service type classification
refers to the type of role the service plays in the overall architecture.
For example, some services might implement business functionality,
11
12
13
15
16
Service Granularity
One of the bigger differences from a services perspective between
microservices and SOA is service granularity. As the name suggests,
microservices are small, fine-grained services. More specifically, ser
vice components within a microservices architecture are generally
single-purpose services that do one thing really, really well. With
SOA, service components can range in size anywhere from small
application services to very large enterprise services. In fact, it is
common to have a service component within SOA represented by a
large product or even a subsystem.
Interestingly enough, one of the biggest challenges originally facing
SOA was service granularity. Not understanding the impact of ser
vice granularity, architects frequently designed services that were
too fine-grained, resulting in chatty and poorly performing applica
tions. Architects and component designers quickly learned that
large, coarse-grained services with views into the data were the way
to go. For example, rather than fine-grained getter and setter serv
ices like GetCustomerAddress, GetCustomerName, UpdateCustomer
Name, and so on, architects and shared services teams adopted an
approach of having an enterprise Customer service that handled
more coarse-grained update and retrieval data views, delegating the
lower-level getters and setters to application-level services that were
not exposed remotely to the enterprise. In this manner, operations
such as GetCustomerDemographics or GetCustomerInformation
would return a bulk of customer data related to that context rather
than each individual field.
This difference in granularity naturally relates to differences in ser
vice component scope and functionality. With microservices, the
service component functionality (what the service actually does)
tends to be very small, sometimes implemented through only one or
two modules. With SOA, services tend to encompass much more
business functionality, sometimes implemented as complete subsys
tems (e.g., claims-processing engines or warehousing systems).
However, more typically SOA relies on multiple services to complete
a single business request, whereas microservices architecture gener
ally does not. I discuss this topic in more detail in the Service
Orchestration section of the next chapter.
Whether you are using a microservices architecture or SOA, design
ing services with the right level of granularity is not an easy task.
Service Granularity
17
18
19
20
CHAPTER 3
Comparing Architecture
Characteristics
21
found in the SOA architecture pattern and the optional API layer
found in the microservices architecture pattern.
Component Sharing
Microservices and SOA are inherently different when it comes to
sharing components. SOA is built on the concept of a share-asmuch-as-possible architecture style, whereas microservices architec
ture is built on the concept of a share-as-little-as-possible architec
ture style. In this section I explore the differences between these two
concepts as they relate to microservices and SOA.
Component sharing is one of the core tenets of SOA. As a matter of
fact, component sharing is what enterprise services are all about. For
example, consider a large retail company, as illustrated in Figure 3-1,
that has many applications associated with the processing of an
order, such as a customer-management system, warehousemanagement system, and order-fulfillment system. All of these sys
tems have their own version of an Order service. In this example,
lets assume that the process to update an order requires special
business logic. This means that the special processing logic needs to
be replicated across several applications in the enterprise, requiring
additional verification and coordination among these applications.
The other thing to notice in Figure 3-1 is that each system in this
example has its own database, so each system might have a sightly
different representation of an order.
22
23
25
26
27
28
29
30
31
number for Apple, Inc. (2046251), look up and add the symbol
(AAPL), and convert the date from 04/23/15 to 2015.04.23.
vice consumer and service must use the same protocol. In SOA, you
can mix and match them as much as you want.
33
34
CHAPTER 4
Comparing Architecture
Capabilities
In the last chapter I showed you how architecture patterns can help
define basic architectural characteristics. In this chapter I take a sim
ilar approach, but instead of architecture characteristics I focus on
the architecture capabilities that are described through the patterns.
By looking at an architecture pattern you can tell if applications will
likely be scalable, maintainable, and extensible, and if they will be
relatively easy to develop, test, and deploy.
In this chapter I compare microservices and SOA by focusing on
three major architectural capabilitiesthe size of the application
each architecture pattern supports, the type of systems and compo
nents that can be integrated using each architecture pattern, and
finally the ability of the architecture pattern to support contract
decoupling.
Application Scope
Application scope refers to the overall size of the application that an
architecture pattern can support. For example, architecture patterns
such as the microkernel or pipeline architecture are better suited for
smaller applications or subsystems, whereas other patterns such as
event-driven architecture are well-suited for larger, more complex
applications. So where do the microservices and SOA patterms fit
along this spectrum?
35
Heterogeneous Interoperability
Heterogeneous interoperability refers to the ability to integrate with
systems implemented in different programming languages and plat
forms. For example, you might have a situation in which a single
36
Heterogeneous Interoperability
37
38
Contract Decoupling
Contract decoupling is the holy grail of abstraction. Imagine being
able to communicate with a service using different data in a message
format that differs from what the service is expectingthat is the
very essence of contract decoupling.
Contract decoupling is a very powerful capability that provides the
highest degree of decoupling between service consumers and serv
ices. This capability allows services and service consumers to evolve
Contract Decoupling
39
40
<trade>
<acct>321109</acct>
<symbol>AAPL</symbol>
<shares>1000</shares>
<date>2015-10-12</date>
</trade>
41
42
CHAPTER 5
Summary
43
can view Enterprise Messaging: JMS 1.1 and JMS 2.0 Fundamentals
(OReilly video) and Enterprise Messaging: Advanced Topics and
Spring JMS (OReilly video).
44
Chapter 5: Summary