Microservices Design Patterns
Microservices Design Patterns
Design
Patterns
forJava Applications
Arun GuptaVice President, Developer Advocacy
@arungupta, blog.arungupta.me
[email protected]
Monolith Application
UI CSS
CSS Databas
e Cache
Load HTML
Balancer HTML
HTML HTML
JPA
HTML
Business Logic
HTML
HTML HTML
HTML HTML
HTML DB
CDI REST JSF
Monolith Application
EAR
Load
EAR Cache
Balancer
WAR
WAR
WAR
JAR
JAR
JAR
JAR
DB
Advantages of Monolith
Application
Simple to develop
Monolith Application
Version 1
UI CS
S
Databa Version 2
se
HTML
HTML
UI CS
HTML
HTML
S
Databa Version 3
se
HTML
HTML
UI CS
HTML
HTML
S
Databa
Business Logic Version 4
se
HTML HTML
HTML
HTML
HTML HTML
HTMLBusiness
HTML
HTML
HTML
Logic UI CS
S
Databa
se
HTML
HTML
HTML HTMLBusiness
HTML HTML Logic
HTML
HTML HTML HTML
HTML
HTML HTML
HTML HTML
HTML
Business Logic
HTML
HTML HTML
HTML HTML
HTML
Disadvantages of
Monolith Application
👱👱 🙍🙍
👱
Persistence Catalog
👱 🙍
👱👱 🙍
Any organization that designs a system (defined
more broadly here than just information systems)
will inevitably produce a design whose structure is a
copy of the organization's communication structure.
“Any organization that designs a
system (defined more broadly here than
just information systems) will inevitably
produce a design whose structure is a copy
“Type a quote communication
of the organization's here.”
structure.”–Melvin Conway
–Johnny Appleseed
Teams around business
Characteristics
capability
Order User
👱👱 🙍🙍 👱👱 🙍🙍
👱 👱
Catalog
👱👱 🙍🙍
👱
Single Responsibility
Characteristics
Principle
DO
THING
Explicitly Published
Characteristics
interface
Independently replaceable
Characteristics
and upgradeable
Characteristics
“you build
With great
power, comes
great
responsibility
100% automated
Sync or Async
Characteristics
Messaging
Characteristics
REST vs Pub/Sub
P1
GET
C1
PUT P2
C2
POST P3 Queu
e
C3
DELETE
P4
“Smart endpointsDumb
Characteristics
pipes”
Domain driven design (full-stack developer)
SOA 2.0
Hipster SOA
SOA++
SOA 2.0?
Conway’s Law
Service Discovery
Immutable VM
Strategies for
decomposing
JAR
JAR
JAR
JAR DB
Service A Cache DB
WAR
Aggregator Pattern #1
Load
Balancer Service A Cache DB
WAR
Aggregator
Aggregator Cache DB
Service B
WAR
Service C Cache DB
WAR
Proxy Pattern #2
Load
Balancer Service A Cache DB
WAR
Proxy
Aggregator Cache DB
Service B
WAR
Service C Cache DB
WAR
Chained Pattern #3
Load
Balancer
Cache DB
Service A
WAR
Service C Service D
WAR WAR
Cache DB
Cache DB Cache DB
Shared Resources #5
Load
Balancer
Service B
WAR
Cache DB
Service A
WAR
Service C Service D
WAR WAR
Cache DB
Cache DB
Async Messaging #5
Load
Balancer
Service B
WAR
Queue
Cache DB
Service A
WAR
Service C Service D
WAR WAR
Cache DB
Cache DB Cache DB
dzone.com/refcardz/getting-started-with-microservices
Advantages of
microservices
Easier to develop, understand, maintain
http://www.codingthearchitecture.com/2014/07/06/distributed_big_balls_of_mud.html
DRY
CoC
YAGNI
Web Classes Config
Pages C
Files
User C
C C
S
O
O
M
M
O
Databas
S M
Catalog M
M
M
e
O
O
J N
N
O
Order S N
Shopping Cart UI
Classes
Config Files
discover reg
register discover
Databas Databas Databas
e e e
Service Registry
Monolith vs
Microservice
Monolith Microservice
5 (Contracts, Order,
Archives 1
User, Catalog, Web)
Web 8 8
pages
4 (persistence.xml,
Config
web.xml, load.sql, 12(3 per archive)
Files
template.xhtml)
26 (Service
Classes 12 registration/discovery,
Application)
Archive
24 KB ~52 KB total
Size
http://blog.arungupta.me/monolithic-microservices-refactoring-ja
Design Considerations
UI and Full stack
REST Services
http://martinfowler.com/bliki/MicroservicePremium.html
References
github.com/arun-gupta/microservices
github.com/javaee-samples/docker-java
dzone.com/refcardz/getting-started-with-microservices