SlideShare uma empresa Scribd logo
1 de 21
Baixar para ler offline
The Little Pattern That Could
Leveraging the Power of Repositories
Tobias Goeschel
Sr Solutions Architect, FSI
Amazon Web Services
Before we start: A disclaimer
To teach anything meaningful with code exercises in two hours is challenging.
I have provided exercises and example code that I think will make this possible.
The code is available on GitHub, so you can play with it for yourself:
https://github.com/weltraumpirat/repository_workshop.git
Of course, this is nowhere near real-life. Please do not take it as a template to design your DDD application by. It is
just one possible implementation, and in many aspects incomplete and/or imperfect.
Of course, I am not a Java expert. In fact, I haven’t coded anything serious in Java in years. I chose Java, because it
has some characteristics that illustrate the effect of repositories. You can help me improve by sending pull requests!
Of course, I am very opinionated, anyway. Sorry not sorry.
The pictures in this slide deck were created with the help of MidJourney and Photoshop AI. Similarities to real people
and/or artwork are purely coincidental.
Once upon a time,…
Your company, ChopShop Inc., has recently seen a fast
expansion in business, and the demand for new features
is ever increasing. The CTO has noticed a sharp increase in
delivery times, and as a team, you are quick to assert that
the code has become unmaintainable in its current
form:
It is entangled and messy, business logic is distributed across
many modules, it takes hours to
fi
nd bugs, and
fi
xes in one
place often break things somewhere else. The solution is
clear: Microservices.
You know that microservices are hard to get right, and you
want to take no chances. You decide to introduce Domain
Driven Design, successfully run an EventStorming,
identifying bounded contexts and aggregates, and start
separating code into proper modules.
Exercise #1
You have made progress. But inside of each module, there’s still quite a
mess. Rest controllers are huge, containing both domain logic and
database queries via JPA. Someone on the team makes good arguments to
continue the refactoring towards Hexagonal Architecture.
What are some concrete actions you should take?
Examine the ShoppingCartController class and discuss
options with your teammates.
Hint #1
The code has full test coverage, it looks better than most code bases,
and it looks like we already have repositories…
Why do we still need to refactor?
Try to imagine a codebase like this, but at scale -
hundreds, thousands of classes like this.
What could be problematic about the current solution?
Hint #2
Hexagonal Architecture requires a clear separation of the domain
logic from the REST API, the database, third party frameworks, and
all other technical details. That means, other parts can depend on the
core, but never vice versa.
What are possible adapters that you could build?
How can you make sure dependencies always point inward,
not outward?
Exercise #2
Your team has been quick to isolate the RestController logic from the
domain core, and decide to refactor to CQRS. Now it’s time to
introduce a “proper” DDD Repository.
What are the necessary steps for the refactoring?
Examine the use cases (Commands and Queries)
and their implementations,
then identify steps to take with your teammates.
The Repository Pattern in DDD
A repository is essentially an interface that hides the details of data access
from the domain core. Different storage mechanisms can be attached by creating
individual implementations, e.g. for
fi
le-based storage or per database engine.
The interface itself is part of the domain core, the implementation belongs to
its environment.
Domain objects can pass to the repository and back into the core. They map to
serializable data objects. But careful: Business methods must never be
invoked outside of the domain core!
There are two kinds of repositories: Collection- and Persistence-oriented.
Collection-Oriented Repositories
Collection-oriented repositories act like a collection: They have
add(), remove(), addAll() and removeAll(), as well as
fi
nder
methods that allow to search by attribute values.
Since a collection does not explicitly notice changes on its member
objects, all changes have to be recorded and explicitly “
fl
ushed” to
the database.
Persistence-Oriented Repositories
Persistence-oriented repositories are save()-based.
They make changes more explicit by requiring an extra method call:
Any change to a member object is persisted instantaneously by calling
save() on the repository.
Changes that are not explicitly persisted will be lost.
The rule of thumb is:
Go with collection-oriented, unless it creates dif
fi
culties in your context.
Hint #1
Repositories should map to domain objects,
not data transfer objects or database tables.
What is the difference?
Be mindful of aggregate boundaries.
Hint #2
Your teammates are worried about data integrity.
Where should you place transaction logic?
Exercise #3
The team has successfully implemented aggregates and a collection-
based repository. However, your tests are still very slow - they have to
initialize the full Spring context to run, resulting in hours of waiting every
week. As a result, more and more colleagues skip tests entirely, resulting in
more bugs and rework, which not only led to a number of embarrassing
incidents, but also further slows down the delivery.
How could those tests be improved? Examine the test
code, as well as the newly introduced repository logic, then
discuss and implement measures with your teammates.
Hint #1
All the business logic is now cleanly separated from technical details. It
should be testable without external dependencies.
Using polymorphism, what could be a quick way to fully isolate the
core?
Hint #2
Dependency injection is just a fancy way of passing
constructor parameters.
You can eliminate all the expensive setup by making good use of those.
Exercise #4
You’ve deployed your new microservices on Kubernetes. One month later, your boss
calls: The AWS bill is staggering! She urges you to get those spendings down ASAP!
Your team investigates, and after looking at some CloudWatch logs, you realize the usage
patterns of your app are spiky, high traf
fi
c times appear random, and there is a lot
of idle time - the system should not be running 24/7!
You decide to ditch the containers and go full serverless,
con
fi
dent that your system is modular, and should be easy to split up.
Discuss the necessary steps.
What about your current solution could be problematic?
Hint #1
Serverless apps are best mapped to individual use cases.
Hint #2
The collection based repository keeps a lot of in-memory state.
This is not helpful and may result in longer runtimes, higher memory
consumption, and potential race conditions.
What could you do to
fi
x it?
Let’s stay in touch!
https://mastodon.social/@weltraumpirat
https://linkedin.com/in/w3ltraumpirat
https://twitter.com/w3ltraumpirat

Mais conteúdo relacionado

Mais procurados

Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...Vietnam Open Infrastructure User Group
 
Continuous Lifecycle London 2018 Event Keynote
Continuous Lifecycle London 2018 Event KeynoteContinuous Lifecycle London 2018 Event Keynote
Continuous Lifecycle London 2018 Event KeynoteWeaveworks
 
DevOps to DevSecOps Journey..
DevOps to DevSecOps Journey..DevOps to DevSecOps Journey..
DevOps to DevSecOps Journey..Siddharth Joshi
 
Ceph Day Beijing - Ceph All-Flash Array Design Based on NUMA Architecture
Ceph Day Beijing - Ceph All-Flash Array Design Based on NUMA ArchitectureCeph Day Beijing - Ceph All-Flash Array Design Based on NUMA Architecture
Ceph Day Beijing - Ceph All-Flash Array Design Based on NUMA ArchitectureDanielle Womboldt
 
SRE and GitOps for Building Robust Kubernetes Platforms.pdf
SRE and GitOps for Building Robust Kubernetes Platforms.pdfSRE and GitOps for Building Robust Kubernetes Platforms.pdf
SRE and GitOps for Building Robust Kubernetes Platforms.pdfWeaveworks
 
[DEVOPS DDAY 2019] La transformation DEVOPS de la DSI de Pôle emploi
[DEVOPS DDAY 2019] La transformation DEVOPS de la DSI de Pôle emploi[DEVOPS DDAY 2019] La transformation DEVOPS de la DSI de Pôle emploi
[DEVOPS DDAY 2019] La transformation DEVOPS de la DSI de Pôle emploiJean-Yves Babut
 
Room 2 - 3 - Nguyễn Hoài Nam & Nguyễn Việt Hùng - Terraform & Pulumi Comparin...
Room 2 - 3 - Nguyễn Hoài Nam & Nguyễn Việt Hùng - Terraform & Pulumi Comparin...Room 2 - 3 - Nguyễn Hoài Nam & Nguyễn Việt Hùng - Terraform & Pulumi Comparin...
Room 2 - 3 - Nguyễn Hoài Nam & Nguyễn Việt Hùng - Terraform & Pulumi Comparin...Vietnam Open Infrastructure User Group
 
CI/CD Tools Universe: The Ultimate List
CI/CD Tools Universe: The Ultimate ListCI/CD Tools Universe: The Ultimate List
CI/CD Tools Universe: The Ultimate ListPlutora
 
ArgoCD Meetup PPT final.pdf
ArgoCD Meetup PPT final.pdfArgoCD Meetup PPT final.pdf
ArgoCD Meetup PPT final.pdfamanmakwana3
 
DevOps, Common use cases, Architectures, Best Practices
DevOps, Common use cases, Architectures, Best PracticesDevOps, Common use cases, Architectures, Best Practices
DevOps, Common use cases, Architectures, Best PracticesShiva Narayanaswamy
 
Gitops: a new paradigm for software defined operations
Gitops: a new paradigm for software defined operationsGitops: a new paradigm for software defined operations
Gitops: a new paradigm for software defined operationsMariano Cunietti
 
STG301_Deep Dive on Amazon S3 and Glacier Architecture
STG301_Deep Dive on Amazon S3 and Glacier ArchitectureSTG301_Deep Dive on Amazon S3 and Glacier Architecture
STG301_Deep Dive on Amazon S3 and Glacier ArchitectureAmazon Web Services
 
VisiQuate: Azure cloud migration case study
VisiQuate: Azure cloud migration case studyVisiQuate: Azure cloud migration case study
VisiQuate: Azure cloud migration case studyLeonid Nekhymchuk
 
Fundamentals of DevOps and CI/CD
Fundamentals of DevOps and CI/CDFundamentals of DevOps and CI/CD
Fundamentals of DevOps and CI/CDBatyr Nuryyev
 
How to contribute to OpenStack
How to contribute to OpenStackHow to contribute to OpenStack
How to contribute to OpenStackOpsta
 
Jenkins, pipeline and docker
Jenkins, pipeline and docker Jenkins, pipeline and docker
Jenkins, pipeline and docker AgileDenver
 

Mais procurados (20)

Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
Room 1 - 3 - Lê Anh Tuấn - Build a High Performance Identification at GHTK wi...
 
Continuous Lifecycle London 2018 Event Keynote
Continuous Lifecycle London 2018 Event KeynoteContinuous Lifecycle London 2018 Event Keynote
Continuous Lifecycle London 2018 Event Keynote
 
DevSecOps - The big picture
DevSecOps - The big pictureDevSecOps - The big picture
DevSecOps - The big picture
 
DevOps to DevSecOps Journey..
DevOps to DevSecOps Journey..DevOps to DevSecOps Journey..
DevOps to DevSecOps Journey..
 
Ceph Day Beijing - Ceph All-Flash Array Design Based on NUMA Architecture
Ceph Day Beijing - Ceph All-Flash Array Design Based on NUMA ArchitectureCeph Day Beijing - Ceph All-Flash Array Design Based on NUMA Architecture
Ceph Day Beijing - Ceph All-Flash Array Design Based on NUMA Architecture
 
SRE and GitOps for Building Robust Kubernetes Platforms.pdf
SRE and GitOps for Building Robust Kubernetes Platforms.pdfSRE and GitOps for Building Robust Kubernetes Platforms.pdf
SRE and GitOps for Building Robust Kubernetes Platforms.pdf
 
[DEVOPS DDAY 2019] La transformation DEVOPS de la DSI de Pôle emploi
[DEVOPS DDAY 2019] La transformation DEVOPS de la DSI de Pôle emploi[DEVOPS DDAY 2019] La transformation DEVOPS de la DSI de Pôle emploi
[DEVOPS DDAY 2019] La transformation DEVOPS de la DSI de Pôle emploi
 
Room 2 - 3 - Nguyễn Hoài Nam & Nguyễn Việt Hùng - Terraform & Pulumi Comparin...
Room 2 - 3 - Nguyễn Hoài Nam & Nguyễn Việt Hùng - Terraform & Pulumi Comparin...Room 2 - 3 - Nguyễn Hoài Nam & Nguyễn Việt Hùng - Terraform & Pulumi Comparin...
Room 2 - 3 - Nguyễn Hoài Nam & Nguyễn Việt Hùng - Terraform & Pulumi Comparin...
 
CI/CD Tools Universe: The Ultimate List
CI/CD Tools Universe: The Ultimate ListCI/CD Tools Universe: The Ultimate List
CI/CD Tools Universe: The Ultimate List
 
Quick and Solid - Baremetal on OpenStack | Rico Lin
Quick and Solid - Baremetal on OpenStack | Rico LinQuick and Solid - Baremetal on OpenStack | Rico Lin
Quick and Solid - Baremetal on OpenStack | Rico Lin
 
ArgoCD Meetup PPT final.pdf
ArgoCD Meetup PPT final.pdfArgoCD Meetup PPT final.pdf
ArgoCD Meetup PPT final.pdf
 
DevOps, Common use cases, Architectures, Best Practices
DevOps, Common use cases, Architectures, Best PracticesDevOps, Common use cases, Architectures, Best Practices
DevOps, Common use cases, Architectures, Best Practices
 
Gitops: a new paradigm for software defined operations
Gitops: a new paradigm for software defined operationsGitops: a new paradigm for software defined operations
Gitops: a new paradigm for software defined operations
 
Gitops Hands On
Gitops Hands OnGitops Hands On
Gitops Hands On
 
STG301_Deep Dive on Amazon S3 and Glacier Architecture
STG301_Deep Dive on Amazon S3 and Glacier ArchitectureSTG301_Deep Dive on Amazon S3 and Glacier Architecture
STG301_Deep Dive on Amazon S3 and Glacier Architecture
 
VisiQuate: Azure cloud migration case study
VisiQuate: Azure cloud migration case studyVisiQuate: Azure cloud migration case study
VisiQuate: Azure cloud migration case study
 
Fundamentals of DevOps and CI/CD
Fundamentals of DevOps and CI/CDFundamentals of DevOps and CI/CD
Fundamentals of DevOps and CI/CD
 
How to contribute to OpenStack
How to contribute to OpenStackHow to contribute to OpenStack
How to contribute to OpenStack
 
DevOps - Motivadores e Benefícios
DevOps - Motivadores e BenefíciosDevOps - Motivadores e Benefícios
DevOps - Motivadores e Benefícios
 
Jenkins, pipeline and docker
Jenkins, pipeline and docker Jenkins, pipeline and docker
Jenkins, pipeline and docker
 

Semelhante a Workshop - The Little Pattern That Could.pdf

System design for Web Application
System design for Web ApplicationSystem design for Web Application
System design for Web ApplicationMichael Choi
 
Introduction to Behavior Driven Development
Introduction to Behavior Driven Development Introduction to Behavior Driven Development
Introduction to Behavior Driven Development Robin O'Brien
 
Architecting a Large Software Project - Lessons Learned
Architecting a Large Software Project - Lessons LearnedArchitecting a Large Software Project - Lessons Learned
Architecting a Large Software Project - Lessons LearnedJoão Pedro Martins
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure rupeshchanchal
 
From Duke of DevOps to Queen of Chaos - Api days 2018
From Duke of DevOps to Queen of Chaos - Api days 2018From Duke of DevOps to Queen of Chaos - Api days 2018
From Duke of DevOps to Queen of Chaos - Api days 2018Christophe Rochefolle
 
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedJoão Pedro Martins
 
How can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdfHow can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdfMindfire LLC
 
We continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShellWe continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShellPVS-Studio
 
Front-End Modernization for Mortals
Front-End Modernization for MortalsFront-End Modernization for Mortals
Front-End Modernization for Mortalscgack
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernizationdevObjective
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Luis Valencia
 
Care and feeding notes
Care and feeding notesCare and feeding notes
Care and feeding notesPerrin Harkins
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal PerformancesVladimir Ilic
 
Ci tips and_tricks_linards_liepins
Ci tips and_tricks_linards_liepinsCi tips and_tricks_linards_liepins
Ci tips and_tricks_linards_liepinsLinards Liep
 
Design Patterns
Design PatternsDesign Patterns
Design Patternsimedo.de
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)guestebde
 
Devops interview questions 2 www.bigclasses.com
Devops interview questions  2  www.bigclasses.comDevops interview questions  2  www.bigclasses.com
Devops interview questions 2 www.bigclasses.combigclasses.com
 

Semelhante a Workshop - The Little Pattern That Could.pdf (20)

Codeigniter
CodeigniterCodeigniter
Codeigniter
 
System design for Web Application
System design for Web ApplicationSystem design for Web Application
System design for Web Application
 
10 Ways To Improve Your Code
10 Ways To Improve Your Code10 Ways To Improve Your Code
10 Ways To Improve Your Code
 
Introduction to Behavior Driven Development
Introduction to Behavior Driven Development Introduction to Behavior Driven Development
Introduction to Behavior Driven Development
 
Architecting a Large Software Project - Lessons Learned
Architecting a Large Software Project - Lessons LearnedArchitecting a Large Software Project - Lessons Learned
Architecting a Large Software Project - Lessons Learned
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
 
From Duke of DevOps to Queen of Chaos - Api days 2018
From Duke of DevOps to Queen of Chaos - Api days 2018From Duke of DevOps to Queen of Chaos - Api days 2018
From Duke of DevOps to Queen of Chaos - Api days 2018
 
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons LearnedITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
ITARC15 Workshop - Architecting a Large Software Project - Lessons Learned
 
How can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdfHow can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdf
 
We continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShellWe continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShell
 
Front-End Modernization for Mortals
Front-End Modernization for MortalsFront-End Modernization for Mortals
Front-End Modernization for Mortals
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernization
 
Front end-modernization
Front end-modernizationFront end-modernization
Front end-modernization
 
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
Typescript design patterns applied to sharepoint framework - Sharepoint Satur...
 
Care and feeding notes
Care and feeding notesCare and feeding notes
Care and feeding notes
 
Improving Drupal Performances
Improving Drupal PerformancesImproving Drupal Performances
Improving Drupal Performances
 
Ci tips and_tricks_linards_liepins
Ci tips and_tricks_linards_liepinsCi tips and_tricks_linards_liepins
Ci tips and_tricks_linards_liepins
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
10 Ways To Improve Your Code( Neal Ford)
10  Ways To  Improve  Your  Code( Neal  Ford)10  Ways To  Improve  Your  Code( Neal  Ford)
10 Ways To Improve Your Code( Neal Ford)
 
Devops interview questions 2 www.bigclasses.com
Devops interview questions  2  www.bigclasses.comDevops interview questions  2  www.bigclasses.com
Devops interview questions 2 www.bigclasses.com
 

Último

COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...naitiksharma1124
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Soroosh Khodami
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Chirag Panchal
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfkalichargn70th171
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfsteffenkarlsson2
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Andrea Goulet
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMarkus Moeller
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdftimtebeek1
 
Sourcing Success - How to Find a Clothing Manufacturer
Sourcing Success - How to Find a Clothing ManufacturerSourcing Success - How to Find a Clothing Manufacturer
Sourcing Success - How to Find a Clothing ManufacturerWave PLM
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Andreas Granig
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationElement34
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignNeo4j
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanNeo4j
 
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdfMicrosoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdfQ-Advise
 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfICS
 
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024Primacy Infotech
 
Malaysia E-Invoice digital signature docpptx
Malaysia E-Invoice digital signature docpptxMalaysia E-Invoice digital signature docpptx
Malaysia E-Invoice digital signature docpptxMok TH
 
Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfSrushith Repakula
 
What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersWhat need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersEmilyJiang23
 

Último (20)

Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
 
Sourcing Success - How to Find a Clothing Manufacturer
Sourcing Success - How to Find a Clothing ManufacturerSourcing Success - How to Find a Clothing Manufacturer
Sourcing Success - How to Find a Clothing Manufacturer
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test Automation
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdfMicrosoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
Microsoft 365 Copilot; An AI tool changing the world of work _PDF.pdf
 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
Odoo vs Shopify: Why Odoo is Best for Ecommerce Website Builder in 2024
 
Malaysia E-Invoice digital signature docpptx
Malaysia E-Invoice digital signature docpptxMalaysia E-Invoice digital signature docpptx
Malaysia E-Invoice digital signature docpptx
 
Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdf
 
What need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java DevelopersWhat need to be mastered as AI-Powered Java Developers
What need to be mastered as AI-Powered Java Developers
 

Workshop - The Little Pattern That Could.pdf

  • 1. The Little Pattern That Could Leveraging the Power of Repositories Tobias Goeschel Sr Solutions Architect, FSI Amazon Web Services
  • 2. Before we start: A disclaimer To teach anything meaningful with code exercises in two hours is challenging. I have provided exercises and example code that I think will make this possible. The code is available on GitHub, so you can play with it for yourself: https://github.com/weltraumpirat/repository_workshop.git Of course, this is nowhere near real-life. Please do not take it as a template to design your DDD application by. It is just one possible implementation, and in many aspects incomplete and/or imperfect. Of course, I am not a Java expert. In fact, I haven’t coded anything serious in Java in years. I chose Java, because it has some characteristics that illustrate the effect of repositories. You can help me improve by sending pull requests! Of course, I am very opinionated, anyway. Sorry not sorry. The pictures in this slide deck were created with the help of MidJourney and Photoshop AI. Similarities to real people and/or artwork are purely coincidental.
  • 3. Once upon a time,…
  • 4. Your company, ChopShop Inc., has recently seen a fast expansion in business, and the demand for new features is ever increasing. The CTO has noticed a sharp increase in delivery times, and as a team, you are quick to assert that the code has become unmaintainable in its current form: It is entangled and messy, business logic is distributed across many modules, it takes hours to fi nd bugs, and fi xes in one place often break things somewhere else. The solution is clear: Microservices.
  • 5. You know that microservices are hard to get right, and you want to take no chances. You decide to introduce Domain Driven Design, successfully run an EventStorming, identifying bounded contexts and aggregates, and start separating code into proper modules.
  • 6. Exercise #1 You have made progress. But inside of each module, there’s still quite a mess. Rest controllers are huge, containing both domain logic and database queries via JPA. Someone on the team makes good arguments to continue the refactoring towards Hexagonal Architecture. What are some concrete actions you should take? Examine the ShoppingCartController class and discuss options with your teammates.
  • 7. Hint #1 The code has full test coverage, it looks better than most code bases, and it looks like we already have repositories… Why do we still need to refactor? Try to imagine a codebase like this, but at scale - hundreds, thousands of classes like this. What could be problematic about the current solution?
  • 8. Hint #2 Hexagonal Architecture requires a clear separation of the domain logic from the REST API, the database, third party frameworks, and all other technical details. That means, other parts can depend on the core, but never vice versa. What are possible adapters that you could build? How can you make sure dependencies always point inward, not outward?
  • 9. Exercise #2 Your team has been quick to isolate the RestController logic from the domain core, and decide to refactor to CQRS. Now it’s time to introduce a “proper” DDD Repository. What are the necessary steps for the refactoring? Examine the use cases (Commands and Queries) and their implementations, then identify steps to take with your teammates.
  • 10. The Repository Pattern in DDD A repository is essentially an interface that hides the details of data access from the domain core. Different storage mechanisms can be attached by creating individual implementations, e.g. for fi le-based storage or per database engine. The interface itself is part of the domain core, the implementation belongs to its environment. Domain objects can pass to the repository and back into the core. They map to serializable data objects. But careful: Business methods must never be invoked outside of the domain core! There are two kinds of repositories: Collection- and Persistence-oriented.
  • 11. Collection-Oriented Repositories Collection-oriented repositories act like a collection: They have add(), remove(), addAll() and removeAll(), as well as fi nder methods that allow to search by attribute values. Since a collection does not explicitly notice changes on its member objects, all changes have to be recorded and explicitly “ fl ushed” to the database.
  • 12. Persistence-Oriented Repositories Persistence-oriented repositories are save()-based. They make changes more explicit by requiring an extra method call: Any change to a member object is persisted instantaneously by calling save() on the repository. Changes that are not explicitly persisted will be lost. The rule of thumb is: Go with collection-oriented, unless it creates dif fi culties in your context.
  • 13. Hint #1 Repositories should map to domain objects, not data transfer objects or database tables. What is the difference? Be mindful of aggregate boundaries.
  • 14. Hint #2 Your teammates are worried about data integrity. Where should you place transaction logic?
  • 15. Exercise #3 The team has successfully implemented aggregates and a collection- based repository. However, your tests are still very slow - they have to initialize the full Spring context to run, resulting in hours of waiting every week. As a result, more and more colleagues skip tests entirely, resulting in more bugs and rework, which not only led to a number of embarrassing incidents, but also further slows down the delivery. How could those tests be improved? Examine the test code, as well as the newly introduced repository logic, then discuss and implement measures with your teammates.
  • 16. Hint #1 All the business logic is now cleanly separated from technical details. It should be testable without external dependencies. Using polymorphism, what could be a quick way to fully isolate the core?
  • 17. Hint #2 Dependency injection is just a fancy way of passing constructor parameters. You can eliminate all the expensive setup by making good use of those.
  • 18. Exercise #4 You’ve deployed your new microservices on Kubernetes. One month later, your boss calls: The AWS bill is staggering! She urges you to get those spendings down ASAP! Your team investigates, and after looking at some CloudWatch logs, you realize the usage patterns of your app are spiky, high traf fi c times appear random, and there is a lot of idle time - the system should not be running 24/7! You decide to ditch the containers and go full serverless, con fi dent that your system is modular, and should be easy to split up. Discuss the necessary steps. What about your current solution could be problematic?
  • 19. Hint #1 Serverless apps are best mapped to individual use cases.
  • 20. Hint #2 The collection based repository keeps a lot of in-memory state. This is not helpful and may result in longer runtimes, higher memory consumption, and potential race conditions. What could you do to fi x it?
  • 21. Let’s stay in touch! https://mastodon.social/@weltraumpirat https://linkedin.com/in/w3ltraumpirat https://twitter.com/w3ltraumpirat