Beruflich Dokumente
Kultur Dokumente
Design
Patterns
for
Java Applications
Arun Gupta
Vice President, Developer Advocacy
@arungupta, blog.arungupta.me
arun@couchbase.com
Monolith Application
UI CSS
CSS
Database
Load HTML
HTML Cache
HTML
HTML JPA
Balancer HTML
Business Logic
HTML
HTML HTML
HTML HTML
HTML
CDI REST JSF
DB
Monolith Application
EAR
EAR
Load Cache
Balancer WAR
WAR
WAR
JAR
JAR
JAR
JAR
DB
Advantages of
Monolith Application
• Simple to develop
Monolith Application
Version 1
UI Database Version 2
HTML UI HTML
HTML Database Version 3
HTML
HTML UI HTML
HTML Database
HTML
Business Logic Version 4
HTML HTML
HTML
HTML
HTML HTML HTML
HTML HTML Logic
Business
HTML UI Database
HTML
HTML
HTML HTMLBusiness
HTML HTML Logic
HTMLHTML
HTML HTML
HTML
HTML HTML
HTML HTML
HTML
Business Logic
HTML
HTML HTML
HTML HTML
HTML
Disadvantages of
Monolith Application
👱
Order
👱👱 🙍🙍
Business Logic
👱👱 🙍🙍
User
👱
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.”
–Melvin Conway
http://www.melconway.com/Home/Committees_Paper.html
ic s
is t
te r
c
ara
C h
Teams around business
capability
Order User
👱👱 🙍🙍 👱👱 🙍🙍
👱 👱
Catalog
👱👱 🙍🙍
👱
ic s
is t
te r
c
hara
C
1
DO
THING
ic s
is t
te r
c
hara
C
With great
power, comes great
responsibility
http://techblog.netflix.com/2012/02/fault-tolerance-in-high-volume.html
ic s
is t
te r
c
hara
C
ic s
is t
te r
c
hara
C
100% automated
ic s
is t
te r
c
hara
C
REST vs Pub/Sub
P1
GET
C1
PUT P2
C2
POST P3
Queue C3
DELETE
P4
ic s
is t
te r
c
ara
C h
“Smart endpoints
Dumb pipes”
SOA
• SOA 2.0
• Hipster SOA
• SOA++
SOA 2.0?
• Conway’s Law
• Service Discovery
• Immutable VM
Strategies for decomposing
Strategies for decomposing
Load
Balancer WAR
WAR
JAR
JAR
JAR
JAR
DB
Service A
Cache DB
WAR
Aggregator Pattern #1
Load
Balancer Service A
Cache DB
WAR
Aggregator Service B
Aggregator Cache DB
WAR
Service C
Cache DB
WAR
Proxy Pattern #2
Load
Balancer Service A
Cache DB
WAR
Proxy Service B
Aggregator Cache DB
WAR
Service C
Cache DB
WAR
Chained Pattern #3
Load
Balancer
WAR
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 Pages Classes Config Files
User C C C
S O O
S M M Database
Catalog M M
J O O
Order S N N
Shopping Cart UI
Classes
Config Files
discover register
register discover register
Service Registry
Monolith vs Microservice
Monolith Microservice
26 (Service registration/
Classes 12
discovery, Application)
http://blog.arungupta.me/monolithic-microservices-refactoring-javaee-applications/
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