Event-Driven Microservices
Event-Driven Microservices
Microservices
The Architect’s Guide to Building a Responsive,
Elastic and Resilient Microservices Architecture
“Ifincrease
we are to exponentially
agility through
microservices, we need to
replace our static, stove-piped,
monolithic thinking.
JONATHAN SCHABOWSKY
All rights reserved. No part of this work may be reproduced, or stored in a retrieval system, or transmitted in any form
or by any means, electronic, mechanical, photocopying, recording, or otherwise without permission from Solace.
Solace
535 Legget Drive, 3rd Floor
Ottawa, Ontario K2K 3B8
Canada
Phone: +1 613-271-1010
Web: solace.com
TABLE OF CONTENTS
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
Databases + CQRS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
About Solace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5 Event-Driven Microservices
INTRODUCTION
Many organizations migrate to microservices architecture for one reason: Agility. The
ability to very quickly create and modify components in a way that offers bottom line
business value is mission critical in a world where your competitors are a click away
and time to market is everything. But the speed with which you develop components
is just one piece of the puzzle.
How quickly can you integrate them with significant risks or barriers to agility:
the rest of your system? How completely
• Brittleness of distributed processing;
can you embrace innovative new
techniques and technologies? • Ecosystem integration challenges; and,
1 Event-Driven Microservices
“Application leaders engaged
in digital transformation
initiatives must add ‘event
thinking’ to their technical,
organizational and cultural
strategies.
YEFIM NATIS
GARTNER
Source: Gartner “Business Events, Business Moments and Event Thinking in Digital
Business,” 4 August 2017, Yefim Natis
THE SERVICE DECOMPOSITION PARADOX
The theory of microservices is simple: you make each microservice, the larger
achieve better agility, scalability and your service count, the more the fallacies
reusability by breaking monolithic of distributed computing impact stability
applications into small, purpose-specific and user experience/system performance.
microservices. This makes it mission critical to establish
an architecture and implementation that
The real-world implementation of
minimizes latency while handling the
microservices is, as always, more
realities of network and service outages.
complicated than that. This is in large part
because of the fallacies of distributed Much of the tooling related to
computing – a set of false assumptions microservices involve the use of CI/
that programmers and architects make CD, automated infrastructure, DevOps
when they enter the world of distributed and agile software development. A
applications. This list was written in 1994 great example would be Pivotal Cloud
by L. Peter Deutsch and others at Sun Foundry, which gives developers an easy
Microsystems, but it holds true today. way to create, test, deploy and update
microservices using modern, cloud-native
THE FALLACIES OF DISTRIBUTED
COMPUTING techniques.
3 Event-Driven Microservices
with many of the guiding principles of In the days of SOA, you’d create massive
microservices such as DevOps and self- monolithic services that directly
service. But it’s eventing/messaging that implemented all facets of the use case as
best deals with the idiosyncrasies of a set of services orchestrated using BPEL
distributed computing and is the key to engines or an ESB. They weren’t reusable
unlocking the potential of microservices and were difficult to scale because ESBs/
architecture. BPEL orchestration moved too much
logic into the network, leading to “dumb
LogicMonitor
THE INTEGRATION CONUNDRUM
Because all microservices need data for When you add it all up, there are
processing, and since 12-Factor Apps impedance mismatches everywhere you
are stateless, data needs to come from look:
somewhere. Acquiring data for greenfield
1. Updates to legacy systems are slow, but
systems is easy, but microservices almost
microservices need to be fast and agile;
always come to be as a side effect of digital
transformation, modernization or the need 2. Legacy systems use old communication
to build new capabilities at a more rapid mediums, but microservices use modern
pace. So you’re almost always dealing with open protocols and APIs;
an ecosystem of legacy systems; some will
3. Legacy systems are nearly always on
be modernized, others will remain as is for
premise and at best use virtualization,
the foreseeable future.
but microservices rely on clouds and
The existing business ecosystem is IaaS abstraction;
the unavoidable burden that most
4. IoT systems use highly specialized
businesses must deal with when they
protocols, but most microservices APIs
start their microservices journey. Most
and frameworks don’t natively support
existing systems live on premises, while
them; and,
microservices live in private and public
clouds. The ability for data to transit the 5. Mobile devices may use REST but also
often unstable and unpredictable world of require asynchronous communication,
wide area networks (WANs) is tricky and but most API gateways only support
time consuming. Then we need to factor synchronous RESTful interactions.
for the emergence of and specialization
How can an organization resolve all of
caused by IoT, mobile devices and big data.
these mismatches?
The volume and variety of these systems
results in a very large upfront risk to
microservices initiatives.
5 Event-Driven Microservices
THE INCREDIBLE DANCING MICROSERVICES
As I described earlier, the smaller the and the performance will suffer, if not be
service, the less value it discretely ruined.
offers the end user – value comes from
Dancing is different. A choreographer
orchestration. Historically, orchestration
listens to a song and creates a routine
was handled by a central component like
based on events in the music. The dancers
BPEL engines or ESBs, or, these days, API
may do completely different moves or
gateways.
steps from each other, but as long as it was
I’ll use a musical analogy to explain the choreographed together based on those
problem with that approach. audio cues (or events) then the routine
will be a success. Even if someone messes
Most composers create music by trial and
up by doing the wrong step or losing the
error (just like a software developer). Their
beat, the show can continue because each
output? Musical scores containing sheets
dancer is listening to the music for their
of music which will be played by each
specific event rather than being told what
instrument. For this analogy each musician
to do by an orchestrator.
is like a microservice. If the composer
is writing for a heavy metal band, there To bring it back to microservices, a given
are only a few instruments (guitar, bass, microservice will perform a series of steps
drummer, vocalist) and a conductor isn’t within the code which is an example of
needed. micro-orchestration. The input or output
of a microservice is a data event which has
But a symphony orchestra consists of
domain significance. The key is that since
around one hundred musicians playing a
the microservice is merely producing an
wide range of instruments. In this instance,
event, it does not have knowledge of if or
they absolutely need a conductor to ensure
when it will be processed. Other services
that every musician starts playing at the
register their interest in an event or set of
right moment, stays on beat, speeds up
events and react accordingly. Just like a
and slows down when necessary, plays
dancer executing the steps of the routine.
louder or softer.
Ironically, the common enabling theme
Unfortunately, if the conductor can’t between microservice execution and a
communicate with the musicians – or dance move is the event (data event or
even just a section or potentially a single audio event).
musician – things will quickly fall apart
THE COPERNICAN SHIFT TO EVENTS
FROM DATA-CENTRIC TO EVENT-CENTRIC IT PRIORITY – A COPERNICAN SHIFT
7 Event-Driven Microservices
If we are to exponentially increase agility platform. Just like how our sensory
through microservices, we need to replace system fires events to the central nervous
our static, stove-piped, monolithic thinking system for interpretation. In the world of
with a desire to get the right event to the microservices, we need a central nervous
right service at the right time. system that can:
sign you are still thinking in the paradigm terms of “service A will call service B which
9 Event-Driven Microservices
The alternative is to follow the philosophy • Enables fine-grained scaling. Each
of choreography. Going back to the analogy service can be independently scaled up
of dance, services should react to changes or down based on demand. This ensures
in their environment just like a dancer a good user experience and is less
reacts to musical cues. The benefits are wasteful of compute resources.
immense:
• Easy to add new services. Due to less
• Better agility. Agile development coupling, a new service can come online,
teams are more independent and are consume events and implement new
significantly less impacted by changes to functionality without changes to any
other services. other service.
• Services are smaller/simpler. Each This litany of benefits doesn’t come for
service is not required to have complex free; there is no such thing as a free lunch.
error handling for downstream service or
Consistency of state then becomes an
network failures.
area of focus, because a service, being
• Less service coupling. Services have no temporarily down, means that the event
knowledge about the existence of other state changes may not be processed
services. immediately. Fundamentally, how do we
deal with this negative side effect?
11 Event-Driven Microservices
DATABASES + CQRS
since, yes, the events at the center of our Public void createAccount(name,
universe must be persisted somewhere. acctMetadata)
If you separate command actions such as What you do sacrifice with CQRS is
create, update and delete from query, you consistency, but you enhance both
essentially have segregated events which performance and availability and, as
change domain state from the queries mentioned earlier, embracing eventual
which do not. It is these events which move consistency alleviates this concern for most
your thinking back into events being the use cases.
13 Event-Driven Microservices
capture (CDC) on the underlying databases. It’s easier to integrate modern systems
An example of this technique with Oracle and devices. For example, IoT devices
databases is to leverage Golden Gate, are inherently event-driven, social media
a CDC utility. As events occur they are platforms are stream-enabled, and even
written to the database. By capturing these many JEE applications utilize message
changes and treating them as events you driven beans (MDB) which can easily be
can leverage them in our microservices exploited. The key is to avoid allowing
platform. This eliminates any impact on integrations to lead you back into the non-
existing systems, and the need to make event-driven world.
costly code changes. Most of the work
here is transforming CDC events into the
domain data structure.
Let’s face it, while AJAX provides a user A better approach would be to use an
experience that seems asynchronous to asynchronous protocol such as MQTT or
the user, under the covers it’s just polling WebSocket. The web application opens
web resources. If the polling interval is a connection, subscribes to the data the
too long, user experience suffers and they user wants, and waits for events to stream
cause unnecessary load on the system by to the browser. User experience is better
attempting to refresh. because events are arriving in real-time,
and it will save your business money as
Conversely, if the polling interval is
bandwidth and compute resources aren’t
too short, the chance that an update
wasted on pointless requests.
has actually occurred is low and again
resources are wasted. As more and more
15 Event-Driven Microservices
sync and ready for action. Historically, this many cases the same event was stored
was done at a data store level where each in multiple locations. A great side effect
database type used its own replication of designing your system around events
mechanism. instead of data is enabling your business
to continue executing through potentially
This was complex as it involved many
disastrous situations as though nothing
components and different strategies.
had happened.
It was also really expensive because in
Microservices Survey.
Lack of Modernization. Messaging itself has been around a long time.
1
Fifteen years ago, there was no agile development — waterfall ruled the
day and messaging infrastructure was managed by specialized teams.
Today, the concept of DevOps and its associated agility means that
developers cannot wait for messaging infrastructure to be installed,
configured and data made available. Everything must be automated,
DevOps-friendly and self-service. This means that while messaging is the
right tool, the tools are no longer compatible with the agility needs and
requirements of today. This is magnified by the promises of speed, scale
and the agility of microservices architecture.
2
into discrete services there is a point where latency will increase and
performance will decrease, impacting user experience and your ability to
satisfy SLAs. The need for the eventing/messaging platform to be as low
latency as possible has direct implication on the ultimate success of the
implementation. When this occurs, the initial reaction is to reverse course
and construct larger, more monolithic, less reusable and agile services
to decrease network hops and thus latency. This step completely undoes
many benefits of microservices but, in many cases, the enterprise is locked
in due to proprietary APIs and wirelines and therefore takes the path of
least resistance.
Proprietary Protocols and APIs. Years ago there weren’t any standard
3
wirelines or protocols, so IBM, TIBCO and other enterprise messaging
companies implemented their own. Today, they do so because they
(correctly!) worry that open standards will increase competition and
enable their customers to easily abandon their product as competitors
innovate and differentiate their offerings. Most vendors implement, at
most, a single standard wireline or open API, thereby constraining the
languages in which microservices can be implemented and excluding the
larger ecosystem of events such as those from IoT devices. This reduces
the overall value and agility that microservices provide and results in
integration shims intended to unify data movement.
Poor Stability. No service will ever achieve 100% availability and no
4
system will operate perfectly at all times. Bugs within service, network
outages, and poison messages are all real examples of how services can
slow down or tax the microservices ecosystem. When these off-nominal
events occur, we as architects expect that our foundational services, such
as messaging, weather the storm, buffer the requests, and ensure no data
loss. It turns out the reality is that many messaging systems work well until
these scenarios occur. In other words, they let us down when the going
gets tough. Ironically, this is when we needed them the most!
5
platforms that can’t be deployed in their competitor’s clouds or on
premises where many businesses maintain core business functions.
Legacy messaging systems cannot easily be deployed into cloud
environments and some simply cannot because of their use of multicast.
Deployability is an important consideration given today’s climate of ever-
evolving cloud strategies. The pain to migrate can be large when the
decision to move towards hybrid and/or multi-cloud architectures arises.
6
are extremely common for both economic and continuity of operations.
All of these strategies require events to be propagated across WANs in
a reliable, secure and performant way. Since legacy messaging products
were originally used in datacenter environments, they respond poorly to
the common WAN attributes of jitter and slow round-trip times.
7
gateway space is booming. This component is necessary because in many
cases B2B and web applications need to integrate using web-friendly APIs
such as REST/HTTP. These interactions, where they represent domain
change events, must be quickly transformed into events for downstream
processing. API management and gateways simply do not attempt to
enable the interactions between event-driven microservices, nor do
they enable many asynchronous protocols for streaming events to web
applications.
19 Event-Driven Microservices
CONCLUSION
While event-driven microservices may world. Engineered as a modern eventing
seem difficult initially, they are the future platform, Solace can be deployed in every
of most microservices and IT strategies. cloud and platform as a service, and can
Choosing the right eventing/messaging easily span WANs. It supports DevOps
platform is one of the most critical steps automation and provides an almost
in the path to realizing the vast benefits of completely self-service experience for
microservices. developers. Solace is the only stable and
performant solution that fits the unique
Architects and developers simply need
needs of microservices architects.
a platform that has been engineered to
thrive in today’s modern, rapidly-evolving
R
solace.com