reimagining monoliths with ddd - red hat · not a full introduction to domain driven design (ddd)...
TRANSCRIPT
![Page 1: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/1.jpg)
REIMAGINING MONOLITHS WITH DDDUsing domain-driven design to reimagine monolithic applications in a world of microservices
Eric Murphy and Aleš NosekRed Hat Consulting ArchitectsMay 8, 2019
![Page 2: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/2.jpg)
INTRODUCTIONS
Eric Murphy● Architect● App Dev Center of Excellence
Fun Fact: Co-authored Creating Applications with Mozilla, O’Reilly, 2002
Aleš Nosek● Red Hat Certified Architect● Consulting, West Region
Fun Fact: Worked at SUSE on open source projects, then worked on proprietary products. Felt guilty, so came to work on open source at Red Hat!
![Page 3: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/3.jpg)
● Not a full introduction to Domain Driven Design (DDD)● Practical focus on DDD — Keep it simple, stupid (KISS principle)● Technical, rather than high level
○ Show me the code!○ Special focus on using Quarkus/Vert.x, but transferable to other
technologies● Consider using DDD with monolithic architecture as the preferred choice
for brand new applications○ Take today’s advice back to your team
TODAY’S DISCUSSION
![Page 4: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/4.jpg)
SOA AND MONOLITHS
2012: DREAD FOR
X
![Page 5: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/5.jpg)
MICROSERVICES!
2012: HYPE FOR
✓
![Page 6: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/6.jpg)
SERVERLESS (FUNCTIONS)!
2018: HYPE FOR
✓
![Page 7: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/7.jpg)
MONOLITHS
2012-2018: DISDAIN FOR
X
![Page 8: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/8.jpg)
MONOLITHS
Today: RETHINKING
?
![Page 9: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/9.jpg)
Not all apps should be microservices or functions
WHY RETHINK MONOLITHS?
![Page 10: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/10.jpg)
Monoliths can easily be split into microservices or functions
if designed correctly
WHY RETHINK MONOLITHS?
![Page 11: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/11.jpg)
Domain-Driven Design (DDD) can guide you in building
monoliths that are decomposable
WHY RETHINK MONOLITHS?
![Page 12: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/12.jpg)
You don’t have to be “locked in” to a monolithic architecture when building a monolithic
application
WHY RETHINK MONOLITHS?
![Page 13: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/13.jpg)
DOMAIN-DRIVEN DESIGN (DDD)
![Page 14: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/14.jpg)
● Merge your business domain with software modeling● Special focus on:
○ Capturing how users interact with the software (via event storming activities)
○ Identifying clusters of domain objects in the system (aggregates)○ Finding boundaries within business domain (bounded context)
● Check https://en.wikipedia.org/wiki/Domain-driven_design for a great summary!
● Warning: DDD content is often very academic and dry, but invaluable to modeling a domain and effectively designing modern software
DOMAIN-DRIVEN DESIGN (DDD)
![Page 15: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/15.jpg)
● Domain-Driven Design Quickly● Summary of Eric Evan’s definitive book● Online version available for free (Google it)
RECOMMENDED READING
![Page 16: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/16.jpg)
16
● Facilitated group learning practice using Gamestorming and the principles of domain-driven design (DDD)
● https://openpracticelibrary.com/practice/event-storming/● Red Hat Open Innovation Labs leverages the Event Storming practice●
EVENT STORMING
![Page 17: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/17.jpg)
17
![Page 18: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/18.jpg)
● Events which help define the internal functionality of the software● Commands (Actions) initiated by a user or policy/procedure● Aggregates (Entities) which maintain application state
○ Aggregate Root which is the top level of an Aggregate hierarchy■ May identify transactional boundaries within the software
● May identify separate services or microservices● Bounded Context which identifies boundaries between business domains
○ May identify separate applications or services● Read Models which allow data to be efficiently retrieved● Screen Layouts which visually represent data to a user (optional)
EVENT STORMING OUTPUTS
![Page 19: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/19.jpg)
● Events● Commands (Actions)● Aggregates (Entities)● Bounded Context (Services)● Read Models (Data Views)● Screen Layouts
EVENT STORMING OUTPUTS (SIMPLIFIED)
![Page 20: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/20.jpg)
● Events → PhotoCreated● Commands (Actions) → createPhoto()● Aggregates (Entities) → Photo● Bounded Context (Services) → PhotoService● Read Models (Data Views) → PhotoWithLikes
○ Combines data from two bounded contexts, photos, and likes○ We will see the details in our example application
● Screen Layouts → Add Photo page●
EVENT STORMING (TO CODE)
![Page 21: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/21.jpg)
BUILDING A (MODULAR) MONOLITH WITH AN EYE TOWARDS
MICROSERVICES
![Page 22: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/22.jpg)
1. Source Control Modularity○ Utilize multiple Git repositories for 1 monolithic application○ Scale your application development across teams (programming in the large)
2. Build Modularity○ Utilize Maven Modules or Gradle Projects for building discrete application components
3. Code Modularity○ Utilize Java (9+) modules to provide granular (package level) contractual guarantees during
compile time○ Separate API code from Implementation code○ Emit and listen for events for cross-module communication
■ Don’t call another module’s code directly4. Data Modularity
○ Do not create tight coupling of data between modules
4 LEVELS OF MONOLITHIC MODULARITY
![Page 23: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/23.jpg)
✓ Source Control Modularity✓ Build Modularity✓ Code Modularity✓ Data Modularity
New:
5. Deployment Modularity○ Deploying multiple microservices/functions instead of one application○ May involve partitioning data into separate deployed databases○ Inter-service rather than intra-service communication
■ Propagate events between services using a network transport○ User interface or clients must use multiple services
(potentially through an API aggregator)
5 LEVELS OF MICROSERVICE MODULARITY
Warning: Distributed System!
![Page 24: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/24.jpg)
DDD SUPPORTS DEPLOYMENT MODULARITY
● Partitioned microservices/functions○ Commands (Actions) - separate API per microservice○ Bounded Context (Services)
● Partitioned microservice/function data stores○ Aggregates (Entities)○ Read Models (Data Views)
■ Screen Layouts● Inter-service communication (event-based)
○ Events - propagated through a distributed bus between services in an asynchronous manner
●
![Page 25: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/25.jpg)
By leveraging DDD and modularity, you can build an
application that may be either a monolith or microservices
WHAT’S THE POINT?
![Page 26: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/26.jpg)
PHOTO GALLERY SAMPLE APPLICATION
![Page 27: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/27.jpg)
PHOTO GALLERY SAMPLE APPLICATION
●○ Photos Service○ Likes Service○ Query Service
![Page 28: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/28.jpg)
PHOTO GALLERY SAMPLE APPLICATION
● Photo Gallery Monolith○ Photos Service○ Likes Service ○ Query Service
Option #1
![Page 29: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/29.jpg)
PHOTO GALLERY SAMPLE APPLICATION
●○ Photos Microservice○ Likes Microservice○ Query Microservice
Option #2
![Page 30: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/30.jpg)
Same code, same modular design, different deployment
options
WHAT’S THE POINT?
![Page 31: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/31.jpg)
Monolithic deployments avoid problems of distributed systems
WHAT’S THE POINT?
![Page 32: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/32.jpg)
Monolithic is simpler, but you still have opportunity to scale
out in future with microservices
WHAT’S THE POINT?
![Page 33: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/33.jpg)
DEMO
![Page 34: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/34.jpg)
TAKEAWAYS
1. Learn the basics of DDD, but you don’t have to be an expert2. Learn about Event Storming, and consider adopting the practice in your
organization3. Implement the 4 + 1 levels of modularity to easily switch from monolith to
microservice, and maybe even serverless functions!4. Leverage an event/message bus to communicate between services by passing
eventsa. Local bus for monolith (ie. Vert.x Event Bus)b. Distributed bus for microservices/functions (i.e. Kafka)
![Page 35: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/35.jpg)
TAKEAWAYS
5. Consider starting with a monolith first and break it apart later, only when necessary
![Page 36: REIMAGINING MONOLITHS WITH DDD - Red Hat · Not a full introduction to Domain Driven Design (DDD) Practical focus on DDD — Keep it simple, stupid (KISS principle) ... SOA AND MONOLITHS](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec59f1b8be32d4a160ceffa/html5/thumbnails/36.jpg)