Table Of ContentModern Java EE
Design Patterns
Building Scalable Architecture for
Sustainable Enterprise Development
Markus Eisele
Modern Java EE Design
Patterns
Building Scalable Architecture
for Sustainable Enterprise Development
Markus Eisele
Modern Java EE Design Patterns
by Markus Eisele
Copyright © 2016 O’Reilly Media. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA
95472.
O’Reilly books may be purchased for educational, business, or sales promotional use.
Online editions are also available for most titles (http://safaribooksonline.com). For
more information, contact our corporate/institutional sales department:
800-998-9938 or corporate@oreilly.com.
Editor: Brian Foster Interior Designer: David Futato
Production Editor: Shiny Kalapurakkel Cover Designer: Karen Montgomery
Copyeditor: Charles Roumeliotis Illustrator: Rebecca Demarest
Proofreader: Jasmine Kwityn
October 2015: First Edition
Revision History for the First Edition
2015-10-05: First Release
2016-01-15: Second Release
While the publisher and the author have used good faith efforts to ensure that the
information and instructions contained in this work are accurate, the publisher and
the author disclaim all responsibility for errors or omissions, including without limi‐
tation responsibility for damages resulting from the use of or reliance on this work.
Use of the information and instructions contained in this work is at your own risk. If
any code samples or other technology this work contains or describes is subject to
open source licenses or the intellectual property rights of others, it is your responsi‐
bility to ensure that your use thereof complies with such licenses and/or rights.
978-1-491-93982-6
[LSI]
Table of Contents
Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
1. Enterprise Development Today. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Enterprise Goals and Objectives 2
Resistant to Change and Economically Efficient 2
Developers Left Alone 3
Technology-Centric Versus Business-Centric 3
Aims and Scope 3
2. History of Java EE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Mistakes We Made 6
Evolution Continues with ESBs 7
Challenges and Lessons Learned 9
3. Designing Software for a Scalable Enterprise. . . . . . . . . . . . . . . . . . . 13
Greenfield Versus Brownfield 15
Domain-Driven Design 16
Service Characteristics 17
Microservices Best Practices 19
Independently Deployable and Fully Contained 26
Crosscutting Concerns 26
4. Java EE and Microservices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Matching the Real World 32
The Missing Pieces 34
Migration Approaches 35
iii
5. Microservices Design Pattern. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Common Principles 39
Aggregator Pattern 40
Proxy Pattern 41
Pipeline Pattern 42
Shared Resources 43
Asynchronous Messaging 44
6. Conclusion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
A. Additional Technologies and Team Considerations. . . . . . . . . . . . . . . 49
B. Further Resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
iv | Table of Contents
Acknowledgments
Writing books takes a lot more time than reading them—and it
requires a lot more people to be successful at it. I am thankful to
have had the technical support and creativity of Mark Little, Arun
Gupta, and Daniel Bryant throughout the writing process and
beyond.
I cannot forget my girls here. Thank you! I love you!™
v
CHAPTER 1
Enterprise Development Today
Enterprise is a noun. One of its meanings refers to a project or
undertaking, especially a bold or complex one. But it also refers
more generally to businesses or corporations. Used in the context of
software technology, the term encapsulates a mixture of these mean‐
ings, which is underlined by the inability to adopt new technologies
at a reasonable speed due to a large organization’s inability to move
quickly. Nevertheless, all those attributes and descriptions are very
personal based on specific work environments. And not everything
about this negative introduction is bad. The reasons behind this are
obvious: those complex undertakings or large organizations need a
much higher level of standardization than startups. Changing a
small thing for one out of a hundred projects might lead to unantici‐
pated problems.
One major technology that has become a standard platform across
most enterprises to build complex—and stable—applications is Java
Enterprise Edition (Java EE). And while this technology stack has
come a long way since its inception in 1998, it is still not meant to be
used for innovation and the adoption of more cutting-edge technol‐
ogies and development paradigms.
Nevertheless, innovation and constant improvement are the drivers
behind enterprises and enterprise-grade projects. Without innova‐
tion, there will be outdated and expensive infrastructure compo‐
nents (e.g., host systems) that are kept alive way longer than the
software they are running was designed for. Without constant vali‐
dation of the status quo, there will be implicit or explicit vendor
1
lock-in. Aging middleware runs into extended support and only a
few suppliers will still be able to provide know-how to develop for it.
Platform stacks that stay behind the latest standards attempt to
introduce quick and dirty solutions that ultimately produce techni‐
cal debt.
And typically every 5 to 10 years, the whole software industry, espe‐
cially in the enterprise integration or enterprise application space,
spits out a new methodology or architectural style that promises to
make everything 10 times more productive, agile, flexible, and
responsive. As a result, we’ve seen everything from the creation of
enterprise application integration, web services, and service-
oriented architecture (SOA) to component-based architectures and
enterprise service buses (ESBs).
Enterprise Goals and Objectives
As technology has evolved, the decision makers in enterprise IT
departments have implemented new capabilities and processes
across their organizations. Thus, IT has changed operations and
turnaround for the better. But besides this technical standardization
and forward march of progress in internal operations and cost cut‐
ting, these departments are still accused of not understanding the
needs of the business. Operations and buying decisions are still
focused on generating quick results from investments and long-term
cost savings. These results ignore the need for new business require‐
ments or market developments, such as the still growing mobile
market or the new communication style of a whole generation.
Resistant to Change and Economically
Efficient
Speaking of this mismatch, operations and business have always fol‐
lowed completely distinct goals while working on the greater good.
Operations and sourcing have won out mostly. It’s an easier business
case to calculate how much a corporation-wide standardization for a
Java EE application server can produce in savings than to examine
the individual lines of source code and maintenance that must be
dealt with for each individual project. And it’s not only the differ‐
ence in mindset behind this. It’s also about long-term support and
license agreements. Instead of changing the foundation and every‐
2 | Chapter 1: Enterprise Development Today