12. The microservice architecture is an
architectural style that
structures an application as a
set of loosely coupled, services
organized around business capabilities
16. @crichardson
Microservice architecture = functional
decomposition Catalog
Service
Review
Service
Order
Service
…
Service
Catalog
Database
Review
Database
Order
Database
…
Database
17. @crichardson
Microservice architecture = functional
decomposition
Browser
Mobile
Device
Store
Front UI
API
Gateway
Catalog
Service
Review
Service
Order
Service
…
Service
Catalog
Database
Review
Database
Order
Database
…
Database
HTML
REST
REST
18. @crichardson
Microservices enable continuous delivery
and deployment
Process:
Continuous delivery/deployment
Organization:
Small, agile, autonomous,
cross functional teams
Architecture:
Microservice architecture
Enables
Enables
Enables
Successful
Software
Development
19. @crichardson
Microservices enable continuous delivery
and deployment
Process:
Continuous delivery/deployment
Organization:
Small, agile, autonomous,
cross functional teams
Architecture:
Microservice architecture
Enables
Enables
Enables
Successful
Software
Development
Services improve
testability
and
deployability
20. @crichardson
Microservices enable continuous delivery
and deployment
Process:
Continuous delivery/deployment
Organization:
Small, agile, autonomous,
cross functional teams
Architecture:
Microservice architecture
Enables
Enables
Enables
Successful
Software
Development
Services improve
testability
and
deployability
Teams own services
24. Using Redis within a service
Caching
High performance database
Catalog
Service
Catalog
DB
25. @crichardson
Using Redis for inter-service communication
API
Gateway
Catalog
Service
Review
Service
…
Service
Pub/Sub
Need Product
Details X
GET /product/X
Need … Need … Need …Info Info Info
34. @crichardson
When using microservices:
How to decompose an application into services?
How to deploy an application’s services?
How to handle cross cutting concerns?
Which communication mechanisms to use?
How do external clients communicate with the services?
How does a client discover the network location of a service instance?
How to prevent a network or service failure from cascading to other services?
How to maintain data consistency and implement queries?
How to make testing easier?
How to understand the behavior of an application and troubleshoot problems?
How to implement a UI screen or page that displays data from multiple services?
37. @crichardson
The structure of a pattern encourages
objectivity
Resulting context
Name
Context
Problem
Related patterns
Forces
Solution
38. @crichardson
The structure of a pattern encourages
objectivity
Resulting context
The situation
Name
Context
Problem
Related patterns
Forces
Solution
39. @crichardson
The structure of a pattern encourages
objectivity
Resulting context
The situation
Name
Context
Problem
Related patterns
The issues that must be
addressed
Forces
Solution
40. @crichardson
The structure of a pattern encourages
objectivity
Resulting context
The situation
Name
Context
Problem
Related patterns
The issues that must be
addressed
Forces
Solution
Benefits
Drawbacks
Issues
41. @crichardson
The structure of a pattern encourages
objectivity
Resulting context
The situation
Name
Context
Problem
Related patterns
The issues that must be
addressed
Forces
Solution
Benefits
Drawbacks
Issues
Patterns that are alternative
solutions
Patterns that address the issues
42. @crichardsonMicroservice patterns
Communication patterns
Core
Cross-cutting concerns Security
Deployment
Maintaining data consistency
Database architecture
External API
Reliability
Discovery
Communication style
Testing
Observability
UI
Decomposition
API gateway
Client-side discovery
Server-side
discovery
Service registry
Self registration
3rd party registration
Multiple Services
per host
Single Service per
Host
Service-per-
Container
Service-per-VM
Messaging
Remote Procedure
Invocation
Database per
Service
Event-driven
architectureShared
database
Microservice
Chassis
Backend for front end
Event
sourcing
Transaction
log tailing
Database
triggers
Application
events
Monolithic
architecture
Microservice
architecture
CQRS
Motivating
Pattern
Solution
Pattern
Solution A Solution B
General Specific
Serverless
deployment
Circuit BreakerAccess Token
Domain-specific
Externalized
configuration
Service Integration
Contract Test
Service
Component Test
Exception
tracking
Distributed
tracing
Audit logging
Application
metrics
Log
aggregation
Health check
API
Service deployment
platform
Server-side page
fragment
composition
Client-side UI
composition
Decompose by
business capability
Decompose by
subdomain
Application patterns
Infrastructure patterns
Application Infrastructure patterns
Microservices pattern language: http://microservices.io
43. @crichardsonMicroservice patterns
Communication patterns
Core
Cross-cutting concerns Security
Deployment
Maintaining data consistency
Database architecture
External API
Reliability
Discovery
Communication style
Testing
Observability
UI
Decomposition
API gateway
Client-side discovery
Server-side
discovery
Service registry
Self registration
3rd party registration
Multiple Services
per host
Single Service per
Host
Service-per-
Container
Service-per-VM
Messaging
Remote Procedure
Invocation
Database per
Service
Event-driven
architectureShared
database
Microservice
Chassis
Backend for front end
Event
sourcing
Transaction
log tailing
Database
triggers
Application
events
Monolithic
architecture
Microservice
architecture
CQRS
Motivating
Pattern
Solution
Pattern
Solution A Solution B
General Specific
Serverless
deployment
Circuit BreakerAccess Token
Domain-specific
Externalized
configuration
Service Integration
Contract Test
Service
Component Test
Exception
tracking
Distributed
tracing
Audit logging
Application
metrics
Log
aggregation
Health check
API
Service deployment
platform
Server-side page
fragment
composition
Client-side UI
composition
Decompose by
business capability
Decompose by
subdomain
Application patterns
Infrastructure patterns
Application Infrastructure patterns
Microservices pattern language: http://microservices.io
44. @crichardsonMicroservice patterns
Communication patterns
Core
Cross-cutting concerns Security
Deployment
Maintaining data consistency
Database architecture
External API
Reliability
Discovery
Communication style
Testing
Observability
UI
Decomposition
API gateway
Client-side discovery
Server-side
discovery
Service registry
Self registration
3rd party registration
Multiple Services
per host
Single Service per
Host
Service-per-
Container
Service-per-VM
Messaging
Remote Procedure
Invocation
Database per
Service
Event-driven
architectureShared
database
Microservice
Chassis
Backend for front end
Event
sourcing
Transaction
log tailing
Database
triggers
Application
events
Monolithic
architecture
Microservice
architecture
CQRS
Motivating
Pattern
Solution
Pattern
Solution A Solution B
General Specific
Serverless
deployment
Circuit BreakerAccess Token
Domain-specific
Externalized
configuration
Service Integration
Contract Test
Service
Component Test
Exception
tracking
Distributed
tracing
Audit logging
Application
metrics
Log
aggregation
Health check
API
Service deployment
platform
Server-side page
fragment
composition
Client-side UI
composition
Decompose by
business capability
Decompose by
subdomain
Application patterns
Infrastructure patterns
Application Infrastructure patterns
Microservices pattern language: http://microservices.io
45. @crichardsonMicroservice patterns
Communication patterns
Core
Cross-cutting concerns Security
Deployment
Maintaining data consistency
Database architecture
External API
Reliability
Discovery
Communication style
Testing
Observability
UI
Decomposition
API gateway
Client-side discovery
Server-side
discovery
Service registry
Self registration
3rd party registration
Multiple Services
per host
Single Service per
Host
Service-per-
Container
Service-per-VM
Messaging
Remote Procedure
Invocation
Database per
Service
Event-driven
architectureShared
database
Microservice
Chassis
Backend for front end
Event
sourcing
Transaction
log tailing
Database
triggers
Application
events
Monolithic
architecture
Microservice
architecture
CQRS
Motivating
Pattern
Solution
Pattern
Solution A Solution B
General Specific
Serverless
deployment
Circuit BreakerAccess Token
Domain-specific
Externalized
configuration
Service Integration
Contract Test
Service
Component Test
Exception
tracking
Distributed
tracing
Audit logging
Application
metrics
Log
aggregation
Health check
API
Service deployment
platform
Server-side page
fragment
composition
Client-side UI
composition
Decompose by
business capability
Decompose by
subdomain
Application patterns
Infrastructure patterns
Application Infrastructure patterns
Microservices pattern language: http://microservices.io
47. @crichardsonMicroservice patterns
Communication patterns
Core
Cross-cutting concerns Security
Deployment
Maintaining data consistency
Database architecture
External API
Reliability
Discovery
Communication style
Testing
Observability
UI
Decomposition
API gateway
Client-side discovery
Server-side
discovery
Service registry
Self registration
3rd party registration
Multiple Services
per host
Single Service per
Host
Service-per-
Container
Service-per-VM
Messaging
Remote Procedure
Invocation
Database per
Service
Event-driven
architectureShared
database
Microservice
Chassis
Backend for front end
Event
sourcing
Transaction
log tailing
Database
triggers
Application
events
Monolithic
architecture
Microservice
architecture
CQRS
Motivating
Pattern
Solution
Pattern
Solution A Solution B
General Specific
Serverless
deployment
Circuit BreakerAccess Token
Domain-specific
Externalized
configuration
Service Integration
Contract Test
Service
Component Test
Exception
tracking
Distributed
tracing
Audit logging
Application
metrics
Log
aggregation
Health check
API
Service deployment
platform
Server-side page
fragment
composition
Client-side UI
composition
Decompose by
business capability
Decompose by
subdomain
Application patterns
Infrastructure patterns
Application Infrastructure patterns
Microservices pattern language: http://microservices.io
48. @crichardsonMicroservice patterns
Communication patterns
Core
Cross-cutting concerns Security
Deployment
Maintaining data consistency
Database architecture
External API
Reliability
Discovery
Communication style
Testing
Observability
UI
Decomposition
API gateway
Client-side discovery
Server-side
discovery
Service registry
Self registration
3rd party registration
Multiple Services
per host
Single Service per
Host
Service-per-
Container
Service-per-VM
Messaging
Remote Procedure
Invocation
Database per
Service
Event-driven
architectureShared
database
Microservice
Chassis
Backend for front end
Event
sourcing
Transaction
log tailing
Database
triggers
Application
events
Monolithic
architecture
Microservice
architecture
CQRS
Motivating
Pattern
Solution
Pattern
Solution A Solution B
General Specific
Serverless
deployment
Circuit BreakerAccess Token
Domain-specific
Externalized
configuration
Service Integration
Contract Test
Service
Component Test
Exception
tracking
Distributed
tracing
Audit logging
Application
metrics
Log
aggregation
Health check
API
Service deployment
platform
Server-side page
fragment
composition
Client-side UI
composition
Decompose by
business capability
Decompose by
subdomain
Application patterns
Infrastructure patterns
Application Infrastructure patterns
Microservices pattern language: http://microservices.io
49. @crichardsonMicroservice patterns
Communication patterns
Core
Cross-cutting concerns Security
Deployment
Maintaining data consistency
Database architecture
External API
Reliability
Discovery
Communication style
Testing
Observability
UI
Decomposition
API gateway
Client-side discovery
Server-side
discovery
Service registry
Self registration
3rd party registration
Multiple Services
per host
Single Service per
Host
Service-per-
Container
Service-per-VM
Messaging
Remote Procedure
Invocation
Database per
Service
Event-driven
architectureShared
database
Microservice
Chassis
Backend for front end
Event
sourcing
Transaction
log tailing
Database
triggers
Application
events
Monolithic
architecture
Microservice
architecture
CQRS
Motivating
Pattern
Solution
Pattern
Solution A Solution B
General Specific
Serverless
deployment
Circuit BreakerAccess Token
Domain-specific
Externalized
configuration
Service Integration
Contract Test
Service
Component Test
Exception
tracking
Distributed
tracing
Audit logging
Application
metrics
Log
aggregation
Health check
API
Service deployment
platform
Server-side page
fragment
composition
Client-side UI
composition
Decompose by
business capability
Decompose by
subdomain
Application patterns
Infrastructure patterns
Application Infrastructure patterns
Microservices pattern language: http://microservices.io
50. @crichardsonMicroservice patterns
Communication patterns
Core
Cross-cutting concerns Security
Deployment
Maintaining data consistency
Database architecture
External API
Reliability
Discovery
Communication style
Testing
Observability
UI
Decomposition
API gateway
Client-side discovery
Server-side
discovery
Service registry
Self registration
3rd party registration
Multiple Services
per host
Single Service per
Host
Service-per-
Container
Service-per-VM
Messaging
Remote Procedure
Invocation
Database per
Service
Event-driven
architectureShared
database
Microservice
Chassis
Backend for front end
Event
sourcing
Transaction
log tailing
Database
triggers
Application
events
Monolithic
architecture
Microservice
architecture
CQRS
Motivating
Pattern
Solution
Pattern
Solution A Solution B
General Specific
Serverless
deployment
Circuit BreakerAccess Token
Domain-specific
Externalized
configuration
Service Integration
Contract Test
Service
Component Test
Exception
tracking
Distributed
tracing
Audit logging
Application
metrics
Log
aggregation
Health check
API
Service deployment
platform
Server-side page
fragment
composition
Client-side UI
composition
Decompose by
business capability
Decompose by
subdomain
Application patterns
Infrastructure patterns
Application Infrastructure patterns
Microservices pattern language: http://microservices.io
51. @crichardsonMicroservice patterns
Communication patterns
Core
Cross-cutting concerns Security
Deployment
Maintaining data consistency
Database architecture
External API
Reliability
Discovery
Communication style
Testing
Observability
UI
Decomposition
API gateway
Client-side discovery
Server-side
discovery
Service registry
Self registration
3rd party registration
Multiple Services
per host
Single Service per
Host
Service-per-
Container
Service-per-VM
Messaging
Remote Procedure
Invocation
Database per
Service
Event-driven
architectureShared
database
Microservice
Chassis
Backend for front end
Event
sourcing
Transaction
log tailing
Database
triggers
Application
events
Monolithic
architecture
Microservice
architecture
CQRS
Motivating
Pattern
Solution
Pattern
Solution A Solution B
General Specific
Serverless
deployment
Circuit BreakerAccess Token
Domain-specific
Externalized
configuration
Service Integration
Contract Test
Service
Component Test
Exception
tracking
Distributed
tracing
Audit logging
Application
metrics
Log
aggregation
Health check
API
Service deployment
platform
Server-side page
fragment
composition
Client-side UI
composition
Decompose by
business capability
Decompose by
subdomain
Application patterns
Infrastructure patterns
Application Infrastructure patterns
Microservices pattern language: http://microservices.io
53. @crichardson
Loose coupling = encapsulated data
Order Service Customer Service
Order Database Customer Database
Order table
Customer
table
orderTotal creditLimit
55. @crichardson
Cannot use ACID transactions
BEGIN TRANSACTION
…
SELECT ORDER_TOTAL
FROM ORDERS WHERE CUSTOMER_ID = ?
…
SELECT CREDIT_LIMIT
FROM CUSTOMERS WHERE CUSTOMER_ID = ?
…
INSERT INTO ORDERS …
…
COMMIT TRANSACTION
56. @crichardson
Cannot use ACID transactions
BEGIN TRANSACTION
…
SELECT ORDER_TOTAL
FROM ORDERS WHERE CUSTOMER_ID = ?
…
SELECT CREDIT_LIMIT
FROM CUSTOMERS WHERE CUSTOMER_ID = ?
…
INSERT INTO ORDERS …
…
COMMIT TRANSACTION
Private to the Order
Service
Private to the
Customer Service
57. @crichardson
Cannot use ACID transactions
BEGIN TRANSACTION
…
SELECT ORDER_TOTAL
FROM ORDERS WHERE CUSTOMER_ID = ?
…
SELECT CREDIT_LIMIT
FROM CUSTOMERS WHERE CUSTOMER_ID = ?
…
INSERT INTO ORDERS …
…
COMMIT TRANSACTION
Private to the Order
Service
Private to the
Customer Service
Distributed transactions
60. @crichardson
Saga
Instead: use event-driven sagas
Distributed transaction
Order
Service
Customer
Service
Local transaction
Order
Service
Local transaction
Customer
Service
Local transaction
Order
Service
Event
Event
X
63. @crichardson
Order Service
Saga-based, eventually consistent order processing
Customer Service
Create Order
Customer
creditLimit
creditReservations
...
Order
state
total
…
Event Handler
Event Handler
64. @crichardson
Order Service
Saga-based, eventually consistent order processing
Customer Service
Order created
Create Order
Customer
creditLimit
creditReservations
...
Order
state
total
…
Event Handler
Event Handler
reserveCredit()
65. @crichardson
Order Service
Saga-based, eventually consistent order processing
Customer Service
Order created
Credit Reserved
Credit Check Failed
Create Order
OR Customer
creditLimit
creditReservations
...
Order
state
total
…
Event Handler
Event Handler
reserveCredit()
66. @crichardson
Order Service
Saga-based, eventually consistent order processing
Customer Service
Order created
Credit Reserved
Credit Check Failed
Create Order
OR Customer
creditLimit
creditReservations
...
Order
state
total
…
approve()/reject()
Event Handler
Event Handler
reserveCredit()
68. @crichardson
Event sourcing: event-centric persistence
Service
Event Store
save events
and
publish
Event table
Entity type
Event
id
Entity
id
Event
data
Event
type
Every state change event
69. @crichardson
Event sourcing: event-centric persistence
Service
Event Store
save events
and
publish
Event table
Entity type
Event
id
Entity
id
Event
data
Event
type
Order 901101 …OrderCreated
Every state change event
70. @crichardson
Event sourcing: event-centric persistence
Service
Event Store
save events
and
publish
Event table
Entity type
Event
id
Entity
id
Event
data
Order 902101 …OrderApproved
Event
type
Order 901101 …OrderCreated
Every state change event
71. @crichardson
Event sourcing: event-centric persistence
Service
Event Store
save events
and
publish
Event table
Entity type
Event
id
Entity
id
Event
data
Order 902101 …OrderApproved
Order 903101 …OrderShipped
Event
type
Order 901101 …OrderCreated
Every state change event
73. @crichardson
How to find recent, valuable customers?
SELECT *
FROM CUSTOMER c, ORDER o
WHERE
c.id = o.ID
AND o.ORDER_TOTAL > 100000
AND o.STATE = 'SHIPPED'
AND c.CREATION_DATE > ?
74. @crichardson
How to find recent, valuable customers?
SELECT *
FROM CUSTOMER c, ORDER o
WHERE
c.id = o.ID
AND o.ORDER_TOTAL > 100000
AND o.STATE = 'SHIPPED'
AND c.CREATION_DATE > ?
Customer
Service
Order Service
75. @crichardson
How to find recent, valuable customers?
SELECT *
FROM CUSTOMER c, ORDER o
WHERE
c.id = o.ID
AND o.ORDER_TOTAL > 100000
AND o.STATE = 'SHIPPED'
AND c.CREATION_DATE > ?
Customer
Service
Order Service
What if event
sourcing is
used?
76. @crichardson
How to find recent, valuable customers?
SELECT *
FROM CUSTOMER c, ORDER o
WHERE
c.id = o.ID
AND o.ORDER_TOTAL > 100000
AND o.STATE = 'SHIPPED'
AND c.CREATION_DATE > ?
Customer
Service
Order Service
What if event
sourcing is
used?…. is no longer easy
80. @crichardson
Food to Go example - on github.com
http://bit.ly/redis-pia
94619:Monday [0700_2:1430, 1130_1:1430, ...]
94619:Tuesday [0700_2:1430, 1130_1:1430, ...]
… …
Restaurant
View
Updater
Service
Restaurant
View
Query
Service
ZRANGEBYSCORE
Event Store
Restaurant
events Materialized view of
restaurant locations
and opening hours
GET
available
restaurants
ZADD
ZREM
Sorted sets
83. @crichardson
Summary
Organize into small, agile, autonomous teams responsible for one or more
microservices
Use an event-driven architecture based on event sourcing and CQRS
84. @crichardson
Summary
Organize into small, agile, autonomous teams responsible for one or more
microservices
Use an event-driven architecture based on event sourcing and CQRS
Use Redis throughout a microservices architecture