@crichardson
A pattern language for
microservices
Chris Richardson
Microservice architecture consultant and trainer
Founder of Eventuate.io
Founder of the original CloudFoundry.com
Author of POJOs in Action and Microservices Patterns
@crichardson
chris@chrisrichardson.net
http://adopt.microservices.io
Copyright © 2021. Chris Richardson Consulting, Inc. All rights reserved
@crichardson
Presentation goal
Why patterns and pattern
languages?
A pattern language for
microservices
@crichardson
About Chris
http://adopt.microservices.io
@crichardson
Discounts
35% discount
mpimeusp40
$170 discount coupon
MBNKXFVQ
http://adopt.microservices.io
@crichardson
Agenda
Why a pattern language for microservices?
Core patterns: Monolith vs. Microservices
Distributed data patterns
@crichardson
In 1986…
http://en.wikipedia.org/wiki/Fred_Brooks
@crichardson
Yet almost 30 years later
developers are still
passionately arguing over
“silver bullets”
Functional programming
@crichardson
Suck/Rock Dichotomy
Spring vs. Java EE
JavaScript vs. Java
Functional programming vs. Object-oriented
http://nealford.com/memeagora/2009/08/05/suck-rock-dichotomy.html
Containers vs. Virtual Machines
@crichardson
Gartner Hype Cycle
http://upload.wikimedia.org/wikipedia/commons/b/bf/Hype-Cycle-General.png
It’s
awesome
It’s not
awesome
Trade-offs
understood
@crichardson
We need a better way
to discuss and think
about technology
@crichardson
What’s a pattern?
Reusable solution
to a problem
occurring
in a context
(and its consequences)
@crichardson
Alternative
Pattern
The structure of a pattern
Pattern
Benefits
Drawbacks
Issues
Alternative
Pattern
Pattern
that
addresses
issue
Context
Problem
Solution
aka the situation
(conflicting) issues/
requirements/etc to
address
Forces
Consequences
Pattern language
A collection of
related patterns
that solve problems
in a particular
domain
http://en.wikipedia.org/wiki/A_Pattern_Language
Motivating
Pattern
Solution
Pattern
Solution
Pattern A
Solution
Pattern B
Generic
Pattern
Specific
Pattern
Has
issue
Solves
issue
Alternative
solutions
Refines
@crichardson
Architecture
Splitting
Reassembling
Operations
@crichardson
The pattern language guides you
when developing an architecture
What architectural decisions you must make (a.k.a. problems
to solve)
For each decision/problem:
Available patterns
Trade-offs of each pattern
@crichardson
Agenda
Why a pattern language for microservices?
Core patterns: Monolith vs. Microservices
Distributed data patterns
@crichardson
Success triangle
Process: Lean + DevOps/Continuous Delivery & Deployment
Organization:
Network of small,
loosely coupled, teams
Architecture: ???
IT must deliver software
rapidly, frequently, reliably and
sustainably
Businesses must be
nimble, agile and
innovate faster
S/W
VUCA
Development in high performing
organizations
“Complete their work without communicating and
coordinating with people outside their team”
“Make large-scale changes to the design of their system
without depending on other teams to make changes in
their systems or creating significant work for other teams”
….
Loose design-time coupling/
modularity
=
@crichardson
Architectural requirements for
DevOps:
• Testability
• Deployability
@crichardson
Successful applications live for a long time, e.g. 10 years,
20 years, …
BUT
Technology changes: Programming languages,
frameworks, …
Time
Technology A Technology B
V1 V2 V3 V…
Importance
The importance of a technology changes over time
@crichardson
Architecting for sustainable
software development
Evolvability/Modularity
Must be able to incrementally upgrade
the technology stack
API encapsulates the
technology stack
@crichardson
The context, problem and
forces
Context: IT must deliver software rapidly, frequently, reliably and sustainably
Problem: what’s the architecture?
Forces
Simplicity
Testability
Deployability
Modularity / Loose coupling
Evolvability (of technology stack)
@crichardson
Pattern: monolithic
architecture
*Or multiple tightly coupled (via database) services
The monolithic architecture
is an architectural style
that structures the application
as a single* executable
component
@crichardson
Tomcat/App. Server
Food To Go: Monolithic
architecture
Browser/
Client
WAR/EAR
MySQL
Database
Delivery
management
Order
Management
Kitchen
Management
Web UI
Restaurant
Management
HTML
REST/JSON
The application
@crichardson
Many teams, one application
Orders
Team
FTGO
application
Kitchen
Team
Automated deployment pipeline
Source code repository
Delivery
Team
Production
Benefits and drawbacks
Benefits
Simplicity of development: ACID
transactions, local method/function
calls
Simplicity of operations: one
application
Drawbacks
Potentially large codebase
overwhelms developers
Single technology stack
Teams cannot deploy changes
independently
Entire application subject to
regulatory requirements
Potentially slow deployment pipeline
Poor fault isolation
@crichardson
Issues
How to enable many developers to
frequently commit their changes?
How to improve productivity by enabling
developers to work on part of the
application?
How to enable teams to work
independently?
How to accelerate deployment pipeline?
Merge Queue
Modular
Monolith
Parallelization
@crichardson
Many teams, modular monolith
Order
Module
Orders
Team
Deployment
pipeline
Source code repository
Kitchen
Module
Kitchen
Team
Deployment
pipeline
Source code repository
Delivery
Module
Delivery
Team
Deployment
pipeline
Source code repository
Production
Deployment
pipeline
FTGO
application
Assembles
and tests
Pattern: microservice
architecture
Highly maintainable and
testable
Minimal lead time (time from
commit to deploy)
Loosely coupled
Independently deployable
Implements a business
capability
Owned/developed/tested/
deployed by a small team
An architectural
style
that structures an
application as a
set of deployable/
executable units,
a.k.a. services
A service is:
@crichardson
Food to Go: Microservice
architecture
Browser
Mobile
Application
API
Gateway
Order
Service
Restaurant
Service
Delivery
Service
…
Service
Order
Database
Restaurant
Database
Delivery
Database
…
Database
REST
REST
JavaScript
Message
Broker
@crichardson
Loosely coupled teams and
services
Order
Service
Orders
Team
Automated deployment pipeline
Source code repository
Kitchen
Service
Kitchen
Team
Automated deployment pipeline
Source code repository
Delivery
Service
Delivery
Team
Automated deployment pipeline
Source code repository
Working independently > 80% of the time
Production
Benefits and drawbacks
Benefits
Multiple technology stacks/
incremental evolution
Teams can deploy changes
independently
Fast deployment pipeline
Improved fault isolation
Drawbacks
Potential complexity of
distributed architecture:
eventual consistency, inter-
service communication
More complex operations:
observability and
troubleshooting
@crichardson
Many issues: how to …?
Deployment
Define services
Observe
UI
Communication
Test
Cross cutting concerns
@crichardson
Agenda
Why a pattern language for microservices?
Core patterns: Monolith vs. Microservices
Distributed data patterns
@crichardson
Applying the data patterns
@crichardson
What’s the database
architecture?
Context:
You have applied the Microservice Architecture pattern
Forces:
Services must be loosely coupled - both design-time and
runtime
Database per
Service
Shared
database
Pattern: Shared database
Benefits:
Simple, familiar ACID
transactions
Drawbacks:
Design-time coupling
Runtime coupling
Order Service
Customer
Service
Database
Order
Table
Customer
Table
Pattern: Database per Service
Benefits:
Loose design-time
coupling
Loose runtime coupling
Drawbacks:
More complex, eventual
consistency
Orders Service
Customer
Service
Order
Database
Customer
Database
How to implement
transactions?
Context:
You have applied the
Microservice architecture and
Database per service patterns
Problem:
How to implement
transactions that span
services/databases?
Forces:
Services must be loosely
coupled
Database per
Service
Saga
2PC
Pattern: 2PC
Benefits
Simplicity of ACID transactions
Drawbacks
Tight runtime coupling
Challenging to recover from
coordinator failures
Not supported by all databases
https://en.wikipedia.org/wiki/Two-phase_commit_protocol
Pattern: Saga
Benefits
Loose runtime coupling
Drawbacks
Complexity of eventual
consistency
How to implement queries?
Context:
You have applied the
Microservice architecture and
Data per service patterns
Problem:
How to implement queries
that span services?
Forces:
Services must be loosely
coupled
Database per
Service
CQRS
API
Composition
Pattern: API Composition
Benefits:
Simple
Drawbacks:
Tight runtime coupling
Potentially inefficient
Not transactionally
consistent
Pattern: CQRS
Benefits:
Loose runtime coupling
Efficient queries
Drawbacks:
Cost and complexity of
replication
Not transactionally
consistent
@crichardson
Summary: Patterns and pattern
languages are a great way to …
Think about technology
Discuss technology
Choose technology
@crichardson
Summary: The Microservices pattern
language is a great way to …
Think about microservices
Discuss microservices
Choose microservices (or not)
@crichardson
@crichardson chris@chrisrichardson.net
http://adopt.microservices.io
Questions?
mpimeusp40 MBNKXFVQ

A pattern language for microservices - June 2021