a pattern language for microservices (#gluecon #gluecon2016)
TRANSCRIPT
![Page 1: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/1.jpg)
@crichardson
A pattern language for microservices
Chris Richardson
Founder of Eventuate.io Founder of the original CloudFoundry.com Author of POJOs in Action
@crichardson [email protected] http://eventuate.io
![Page 2: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/2.jpg)
@crichardson
Presentation goal
Why patterns and pattern languages?
A pattern language for microservices
![Page 3: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/3.jpg)
@crichardson
About Chris
![Page 4: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/4.jpg)
@crichardson
Agenda
Why a pattern language for microservices?
Core patterns: monolith vs. microservices
Distributed data management patterns
![Page 5: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/5.jpg)
@crichardson
Let’s imagine you are building a large, complex application,
e.g. an online store
![Page 6: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/6.jpg)
@crichardson
Successful software development
Architecture
Process OrganizationAgile Continuous delivery …
Small, autonomous, teams
![Page 7: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/7.jpg)
@crichardson
?Architecture
![Page 8: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/8.jpg)
@crichardson
No silver bullets
http://en.wikipedia.org/wiki/Fred_Brooks
![Page 9: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/9.jpg)
@crichardson
We need architecture and design patterns
Reusable solution to a problem
occurring in a particular context
![Page 10: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/10.jpg)
@crichardson
Patterns force you to consider tradeoffs
Resulting context
Benefits
Drawbacks
Issues to resolve
![Page 11: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/11.jpg)
@crichardson
Patterns force you to consider other patterns
Related patterns
Alternative solutions
Solutions to problems introduced by this pattern
![Page 12: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/12.jpg)
@crichardson
Microservices pattern language
http://microservices.io/
![Page 13: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/13.jpg)
@crichardson
Agenda
Why a pattern language for microservices?
Core patterns: monolith vs. microservices
Distributed data management patterns
![Page 14: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/14.jpg)
@crichardson
![Page 15: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/15.jpg)
@crichardson
The monolithic architecture
Tomcat
Browser
WAR
SQL database
HTML
REST/JSON
Client App
Simple to ….
Develop Test
Deploy Scale
Catalog Module
Reviews Module
Orders Module
StoreFront UI Module
![Page 16: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/16.jpg)
@crichardson
But successful
applications keep
growing ….
![Page 17: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/17.jpg)
@crichardson
Monolithic architecture
Process OrganizationAgile Continuous delivery …
Small, autonomous, teams
![Page 18: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/18.jpg)
@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
![Page 19: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/19.jpg)
@crichardson
Microservice architecture
Process OrganizationAgile Continuous delivery …
Small, autonomous, teams✔ ✔
![Page 20: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/20.jpg)
@crichardson
Drawbacks
Complexity
![Page 21: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/21.jpg)
@crichardson
DrawbacksComplexity of developing a distributed system
Implementing inter-process communication
Handling partial failures
Complexity of implementing business transactions that span multiple databases (without 2PC)
Complexity of testing a distributed system
Complexity of deploying and operating a distributed system
Managing the development and deployment of features that span multiple services
Fortunately solutions exists
![Page 22: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/22.jpg)
@crichardson
The benefits typically outweigh the drawbacks
for large, complex applications
![Page 23: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/23.jpg)
@crichardson
Issues to addressHow to deploy the services?
How do the services communicate?
How do clients of the application communicate with the services?
How to partition the system into services?
How to deal with distributed data management problems?
….
![Page 24: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/24.jpg)
@crichardson
Agenda
Why a pattern language for microservices?
Core patterns: monolith vs. microservices
Distributed data management patterns
![Page 25: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/25.jpg)
Data management patterns
![Page 26: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/26.jpg)
@crichardson
The Database
Shared database
Order Service Customer Service … Service
Order table Customer table …
orderTotal creditLimit
Tight coupling Simple and
ACID
![Page 27: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/27.jpg)
@crichardson
Database per service
Order Service Customer Service
Order Database Customer Database
Order table Customer table
orderTotal creditLimit
Loose coupling 😀 but more complex 😓 and….
![Page 28: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/28.jpg)
@crichardson
2PC (aka. distributed transactions)
are not viable choice for most modern applications
![Page 29: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/29.jpg)
@crichardson
Customer management
How to maintain data consistency without 2PC?
Order management
Order Service
placeOrder()
Customer Service
updateCreditLimit()
Customer
creditLimit ...
has ordersbelongs toOrder
total
Invariant: sum(open order.total) <= customer.creditLimit
?
![Page 30: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/30.jpg)
@crichardson
Event-driven architecture
![Page 31: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/31.jpg)
@crichardson
Use event-driven, eventually consistent order processing
Order Service
Customer Service
Order created
Credit Reserved
Credit Check Failed
Place Order
OR
![Page 32: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/32.jpg)
@crichardson
How atomically update database and publish an event
Order Service
Order Database
Message Broker
insert Order
publish OrderCreatedEvent
dual write problem
?
![Page 33: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/33.jpg)
@crichardson
Reliably publish events when state changes
![Page 34: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/34.jpg)
@crichardson
Use event-sourcingEvent table
Aggregate type
Event id
Aggregate id
Event data
Order 902101 …OrderApproved
Order 903101 …OrderShipped
Event type
Order 901101 …OrderCreated
![Page 35: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/35.jpg)
@crichardson
Replay events to recreate state
Order
state
OrderCreated(…) OrderAccepted(…) OrderShipped(…)
Events
Periodically snapshot to avoid loading all events
![Page 36: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/36.jpg)
But what about queries?
![Page 37: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/37.jpg)
@crichardson
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
![Page 38: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/38.jpg)
@crichardson
Command Query Responsibility Segregation (CQRS)
Command side
Commands
Aggregate
Event Store
Events
Query side
Queries
Materialized View
Events
POST PUT DELETE
GET
MongoDB Redis Neo4j SQL
ElasticSearch
More complex 😓 but high performance, scalable views 😀
![Page 39: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/39.jpg)
@crichardson
Many more patterns…
![Page 40: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/40.jpg)
@crichardson
Summary: Patterns and pattern languages are a great way to …
Think about technology
Discuss technology
Apply technology
![Page 41: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/41.jpg)
@crichardson
Summary: The Microservices pattern language is a great way to …
Think about microservices
Discuss microservices
Apply microservices (or not)
![Page 42: A pattern language for microservices (#gluecon #gluecon2016)](https://reader031.vdocuments.site/reader031/viewer/2022030305/58742ffa1a28ab72188b75e3/html5/thumbnails/42.jpg)
@crichardson
@crichardson [email protected]
http://eventuate.iohttp://plainoldobjects.com http://microservices.io
Questions?