SlideShare ist ein Scribd-Unternehmen logo
1 von 54
Downloaden Sie, um offline zu lesen
From class
To architecture
Marcin Hawraniak
About me
● Working @ Red-Sky
● CTO @ ChallengeMe.GG
● 10+ years of commercial programming
● Building stuff to solve problems :)
Disclaimer
● There are no solutions that solve all problems
● Presentation is on abstract level
Developer wants to code a class.
Class is a solution for a problem so Developer
seeks one...
Problem distillation
Source: http://serviceorientation.com/serviceorientation/service_composability
Source: http://serviceorientation.com/serviceorientation/service_composability
Source: http://serviceorientation.com/serviceorientation/the_need_for_service_orientation
Problem distillation
● This is not business layer only, applies to technical aspects as well!
● Business may benefit early due to smaller solutions being ready faster than all at
once
● Communicate with business to find critical ones - focus on them first
What helps to control size of a
problem/solution?
Domain Driven Design
Domain Driven Design
Source: Domain Driven Design Quickly
Source: Domain Driven Design Quickly
DDD - Bounded Context
● Logical barriers of the model that give solution to a problem
● Same entity across Bounded Contexts may have different names and properties
● Bounded Context may be considered as a logical boundary in monolith application or
Microservice
● Helps in non DDD environment too!
Source: “.NET Microservices: Architecture for Containerized .NET Applications”
Use case: Tournaments with schedule
Use case: Tournaments with schedule
● Tournaments should support multiple systems (single/double elimination, swiss, 
)
● Matches are scheduled
● Created matches allow to play a game
Tournaments
Scheduled Matches
Use case: Tournaments with schedule
Assumptions:
● Platform already supports matches
Tournaments
Scheduled Matches
Matches
Use case: Tournaments with schedule
Business concerns:
● We may require scheduled matches without tournaments in the future
Tournaments Scheduled Matches Matches
Use case: Tournaments with schedule
Tournaments Scheduled Matches Matches
Tournaments with
scheduled
(business process)
Business process vs lower level components
Business process Lower level components
● Ties components together
● Controls the flow
● Use case naming convention in
code
● Business use case Bounded
Context
● Quite generic/reusable as a
component
● Component specific naming
convention in the code
● Local Bounded Context
Use case: Tournaments with schedule
Benefits
● Easier to split work across developers
● Ready to support new feature
● Reusability of components
● Less code in each component
● Very specific business requirements’ details not spoiling reusable components
All good but...
Time
Scope Quality
Following all principles not always possible
● Chasing perfection - endless refactoring
● “Better working than perfect”
● Almost everyone may give different solution for the same problem
● Write code in such way (decoupling) to limit scope of changes leaking outside of
given code scope while refactoring
● Be aware of what rules are being broken (SOLID)
When there is no time
● Assess price of technical debt and the risk involved
○ Is component critical?
○ Does current state introduces risks?
○ Is the code readable enough?
○ In case of refactoring, will I need to change code only within this single component?
○ How important is it for business?
○ How business will benefit by changing this in comparison to cost of change?
○ Does component follow project’s convention enough?
○ How business would benefit from current code despite its quality?
○ Will I be able to refactor it later?
● Negotiate scope
● Communicate!
Mechanical vs deep refactoring
● Mechanical refactoring usually is cheap and introduces low risk
○ Examples:
■ Renaming Classes / Interfaces
■ Code formatting
● Deep refactoring
○ Requires changing actual domain (may introduce new edge cases)
○ Within single Bounded Context introduces low to medium risk (unit tests)
○ Across many Bounded Contexts introduces medium to high risk (integration test)
Common closure principle
The classes in a package should be closed together against the same kinds of changes.
A change that affects a package affects all the classes in that package.
Source: “Principles of Package Design” by Matthias Noback
Classes grouped using Bounded Context.
Ideas how to structure the code?
Abstract of directory structure
Source: https://fideloper.com/hexagonal-architecture
Source: https://fideloper.com/hexagonal-architecture
Source: https://fideloper.com/hexagonal-architecture
Top directory tree
● Framework
○ Communication related (HTTP, Websocket, CLI, ACL, rate limiting, 
)
● Application
○ Connects business logic with framework
○ Implement Domain interfaces (like database, API or other 3rd party libraries)
○ Transactions handling
○ Catches Domain Events (logging, queueing, sending email)
● Domain
○ Completely technology agnostic by using Interfaces
○ Contains Components and Shared Kernel
Component / Business process - example
● Entities
○ Entity1
○ Entity2
● Repositories
○ Entity1RepositoryInterface
○ Entity2RepositoryInterface
● Service
● Tests
Component / Business process - notes
● If Entity1 references lots of Entity2 (oneToMany)
○ Make separate repository for each Entity
○ Foreign keys are ok within Component
● Repositories
○ Generic methods (at least)
○ Performance optimized methods if needed (counting)
● Service
○ Calling methods changes state of Entity
● Tests
○ Unit tests
Component / Business process - notes
● Tracking - each component may track it’s own domain specific history changes
○ Consider tracking more than needed - business will ask soon about KPIs
○ To solve storage/performance issue implementation may use NoSQL
○ Tracking may be explicit (in domain) or implicit (via tracking dispatched events)
● Passing data to service methods
○ Simple types makes testing easier
Shared kernel - notes
● Components commonly used by other Components (Event Dispatcher, Base Entity
Classes, Traits, Scheduler)
● Changes may affect other Components
Components relation to other components
● Assigning Entity reference to Entity from other component
○ In most cases ID is enough (avoid foreign keys)
○ Referencing different kinds of Entities by storing Context Type and Context ID, example:
■ Type Match and Match ID
■ Type Tournament and Tournament ID
Relation on code level vs service level
● Code level
○ Single app instance
○ Higher level components may extend lower level components with plugins
○ Coupled code vs Dispatching Events
● Service level (SOA / Microservices)
○ No code sharing
○ Access only via API / Messaging
Technical components
● Do not mix low level technical components with Domain
● Naming basing on Context:
○ Image processing
○ Communication (Websockets / HTTP / Queue)
○ Domain Framework (ie Interfaces for Commands, Dispatcher)
○ Addition to 3rd party framework (Symfony / Laravel)
CQRS
Command Query Responsibility Segregation
Source: https://microservices.io/patterns/data/cqrs.html
What if I don’t have full CQRS?
● Commands will use Services from domain
● Queries
○ In simplest form may use existing Repositories from Components
○ Consider separate Repository Interface for Commands/Services and Queries
○ Keep adding counters / redundant data step by step avoid complex joins and speed up queries
○ Over time Query Repository may use more advanced solutions
Architectures
Source: https://docs.microsoft.com/en-us/previous-versions/msp-n-p/ee658090(v%3dpandp.10)
Source: http://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html
Source: https://fideloper.com/hexagonal-architecture
Source:
https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexag
onal-onion-clean-cqrs-how-i-put-it-all-together/
My Class
● Is it technical, domain or connecting domain with framework?
● Is it for state change or reading?
● Is it generic or application/use case specific?
● Does it have state?
● Which properties are optimization purposes?
● What Bounded Contexts it should be aware of?
Summary
● Chosen approach depends on team’s experience, available time, project’s lifespan
● Seek for Bounded Context in non DDD components/layers too!
● Coupling within Component is good. Unnecessary coupling between Components is
bad.
● There are no strict rules, each team goes their own path
● Introduce new ideas in your project step by step
● Explore, make mistakes, improve
Resources
● https://www.infoq.com/minibooks/domain-driven-design-quickly
● https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/
● https://fideloper.com/hexagonal-architecture
● http://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html
● https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-i
t-all-together/
Questions?
● hawraniak@red-sky.pl
● Looking for challenges? rekrutacja@red-sky.pl
Thank you <3

Weitere Àhnliche Inhalte

Ähnlich wie From class to architecture

Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Fwdays
 
Clean architecture
Clean architectureClean architecture
Clean architecture.NET Crowd
 
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020OdessaJS Conf
 
The working architecture of NodeJS applications, ВоĐșŃ‚ĐŸŃ€ бурсĐșĐžĐč
The working architecture of NodeJS applications, ВоĐșŃ‚ĐŸŃ€ бурсĐșĐžĐčThe working architecture of NodeJS applications, ВоĐșŃ‚ĐŸŃ€ бурсĐșĐžĐč
The working architecture of NodeJS applications, ВоĐșŃ‚ĐŸŃ€ бурсĐșĐžĐčSigma Software
 
The working architecture of node js applications open tech week javascript ...
The working architecture of node js applications   open tech week javascript ...The working architecture of node js applications   open tech week javascript ...
The working architecture of node js applications open tech week javascript ...Viktor Turskyi
 
JavaScript for Enterprise Applications
JavaScript for Enterprise ApplicationsJavaScript for Enterprise Applications
JavaScript for Enterprise ApplicationsPiyush Katariya
 
Baby steps to Domain-Driven Design
Baby steps to Domain-Driven DesignBaby steps to Domain-Driven Design
Baby steps to Domain-Driven DesignĆœilvinas Kuusas
 
Keeping business logic out of your UIs
Keeping business logic out of your UIsKeeping business logic out of your UIs
Keeping business logic out of your UIsPetter Holmström
 
DDD with Behat
DDD with BehatDDD with Behat
DDD with BehatAnton Serdyuk
 
Not my problem - Delegating responsibility to infrastructure
Not my problem - Delegating responsibility to infrastructureNot my problem - Delegating responsibility to infrastructure
Not my problem - Delegating responsibility to infrastructureYshay Yaacobi
 
Microservices as an evolutionary architecture: lessons learned
Microservices as an evolutionary architecture: lessons learnedMicroservices as an evolutionary architecture: lessons learned
Microservices as an evolutionary architecture: lessons learnedLuram Archanjo
 
On component interface
On component interfaceOn component interface
On component interfaceLaurence Chen
 
Designing Salesforce Platform Events
Designing Salesforce Platform EventsDesigning Salesforce Platform Events
Designing Salesforce Platform EventsCodeScience
 
Fighting legacy with hexagonal architecture and frameworkless php
Fighting legacy with hexagonal architecture and frameworkless phpFighting legacy with hexagonal architecture and frameworkless php
Fighting legacy with hexagonal architecture and frameworkless phpFabio Pellegrini
 
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...Codemotion
 
Build Your Own Angular Component Library
Build Your Own Angular Component LibraryBuild Your Own Angular Component Library
Build Your Own Angular Component LibraryCarlo Bonamico
 
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)Binary Studio
 
Spring 21 Salesforce Release Webinar
Spring 21 Salesforce Release WebinarSpring 21 Salesforce Release Webinar
Spring 21 Salesforce Release Webinarbrightgenss
 
How to Choose an Integration Platform Vendor for Your Business
How to Choose an Integration Platform Vendor for Your BusinessHow to Choose an Integration Platform Vendor for Your Business
How to Choose an Integration Platform Vendor for Your BusinessWSO2
 
Software Architecture - All you need to know
Software Architecture - All you need to knowSoftware Architecture - All you need to know
Software Architecture - All you need to knowVincent Composieux
 

Ähnlich wie From class to architecture (20)

Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
 
The working architecture of NodeJS applications, ВоĐșŃ‚ĐŸŃ€ бурсĐșĐžĐč
The working architecture of NodeJS applications, ВоĐșŃ‚ĐŸŃ€ бурсĐșĐžĐčThe working architecture of NodeJS applications, ВоĐșŃ‚ĐŸŃ€ бурсĐșĐžĐč
The working architecture of NodeJS applications, ВоĐșŃ‚ĐŸŃ€ бурсĐșĐžĐč
 
The working architecture of node js applications open tech week javascript ...
The working architecture of node js applications   open tech week javascript ...The working architecture of node js applications   open tech week javascript ...
The working architecture of node js applications open tech week javascript ...
 
JavaScript for Enterprise Applications
JavaScript for Enterprise ApplicationsJavaScript for Enterprise Applications
JavaScript for Enterprise Applications
 
Baby steps to Domain-Driven Design
Baby steps to Domain-Driven DesignBaby steps to Domain-Driven Design
Baby steps to Domain-Driven Design
 
Keeping business logic out of your UIs
Keeping business logic out of your UIsKeeping business logic out of your UIs
Keeping business logic out of your UIs
 
DDD with Behat
DDD with BehatDDD with Behat
DDD with Behat
 
Not my problem - Delegating responsibility to infrastructure
Not my problem - Delegating responsibility to infrastructureNot my problem - Delegating responsibility to infrastructure
Not my problem - Delegating responsibility to infrastructure
 
Microservices as an evolutionary architecture: lessons learned
Microservices as an evolutionary architecture: lessons learnedMicroservices as an evolutionary architecture: lessons learned
Microservices as an evolutionary architecture: lessons learned
 
On component interface
On component interfaceOn component interface
On component interface
 
Designing Salesforce Platform Events
Designing Salesforce Platform EventsDesigning Salesforce Platform Events
Designing Salesforce Platform Events
 
Fighting legacy with hexagonal architecture and frameworkless php
Fighting legacy with hexagonal architecture and frameworkless phpFighting legacy with hexagonal architecture and frameworkless php
Fighting legacy with hexagonal architecture and frameworkless php
 
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
Carlo Bonamico, Sonia Pini - So you want to build your (Angular) Component Li...
 
Build Your Own Angular Component Library
Build Your Own Angular Component LibraryBuild Your Own Angular Component Library
Build Your Own Angular Component Library
 
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
 
Spring 21 Salesforce Release Webinar
Spring 21 Salesforce Release WebinarSpring 21 Salesforce Release Webinar
Spring 21 Salesforce Release Webinar
 
How to Choose an Integration Platform Vendor for Your Business
How to Choose an Integration Platform Vendor for Your BusinessHow to Choose an Integration Platform Vendor for Your Business
How to Choose an Integration Platform Vendor for Your Business
 
Software Architecture - All you need to know
Software Architecture - All you need to knowSoftware Architecture - All you need to know
Software Architecture - All you need to know
 

KĂŒrzlich hochgeladen

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Christopher Logan Kennedy
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vĂĄzquez
 

KĂŒrzlich hochgeladen (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

From class to architecture

  • 2. About me ● Working @ Red-Sky ● CTO @ ChallengeMe.GG ● 10+ years of commercial programming ● Building stuff to solve problems :)
  • 3. Disclaimer ● There are no solutions that solve all problems ● Presentation is on abstract level
  • 4. Developer wants to code a class. Class is a solution for a problem so Developer seeks one...
  • 9. Problem distillation ● This is not business layer only, applies to technical aspects as well! ● Business may benefit early due to smaller solutions being ready faster than all at once ● Communicate with business to find critical ones - focus on them first
  • 10. What helps to control size of a problem/solution?
  • 12. Domain Driven Design Source: Domain Driven Design Quickly
  • 13. Source: Domain Driven Design Quickly
  • 14. DDD - Bounded Context ● Logical barriers of the model that give solution to a problem ● Same entity across Bounded Contexts may have different names and properties ● Bounded Context may be considered as a logical boundary in monolith application or Microservice ● Helps in non DDD environment too!
  • 15. Source: “.NET Microservices: Architecture for Containerized .NET Applications”
  • 16. Use case: Tournaments with schedule
  • 17. Use case: Tournaments with schedule ● Tournaments should support multiple systems (single/double elimination, swiss, 
) ● Matches are scheduled ● Created matches allow to play a game Tournaments Scheduled Matches
  • 18. Use case: Tournaments with schedule Assumptions: ● Platform already supports matches Tournaments Scheduled Matches Matches
  • 19. Use case: Tournaments with schedule Business concerns: ● We may require scheduled matches without tournaments in the future Tournaments Scheduled Matches Matches
  • 20. Use case: Tournaments with schedule Tournaments Scheduled Matches Matches Tournaments with scheduled (business process)
  • 21. Business process vs lower level components Business process Lower level components ● Ties components together ● Controls the flow ● Use case naming convention in code ● Business use case Bounded Context ● Quite generic/reusable as a component ● Component specific naming convention in the code ● Local Bounded Context
  • 22. Use case: Tournaments with schedule Benefits ● Easier to split work across developers ● Ready to support new feature ● Reusability of components ● Less code in each component ● Very specific business requirements’ details not spoiling reusable components
  • 25. Following all principles not always possible ● Chasing perfection - endless refactoring ● “Better working than perfect” ● Almost everyone may give different solution for the same problem ● Write code in such way (decoupling) to limit scope of changes leaking outside of given code scope while refactoring ● Be aware of what rules are being broken (SOLID)
  • 26. When there is no time ● Assess price of technical debt and the risk involved ○ Is component critical? ○ Does current state introduces risks? ○ Is the code readable enough? ○ In case of refactoring, will I need to change code only within this single component? ○ How important is it for business? ○ How business will benefit by changing this in comparison to cost of change? ○ Does component follow project’s convention enough? ○ How business would benefit from current code despite its quality? ○ Will I be able to refactor it later? ● Negotiate scope ● Communicate!
  • 27. Mechanical vs deep refactoring ● Mechanical refactoring usually is cheap and introduces low risk ○ Examples: ■ Renaming Classes / Interfaces ■ Code formatting ● Deep refactoring ○ Requires changing actual domain (may introduce new edge cases) ○ Within single Bounded Context introduces low to medium risk (unit tests) ○ Across many Bounded Contexts introduces medium to high risk (integration test)
  • 28. Common closure principle The classes in a package should be closed together against the same kinds of changes. A change that affects a package affects all the classes in that package. Source: “Principles of Package Design” by Matthias Noback
  • 29. Classes grouped using Bounded Context. Ideas how to structure the code?
  • 34. Top directory tree ● Framework ○ Communication related (HTTP, Websocket, CLI, ACL, rate limiting, 
) ● Application ○ Connects business logic with framework ○ Implement Domain interfaces (like database, API or other 3rd party libraries) ○ Transactions handling ○ Catches Domain Events (logging, queueing, sending email) ● Domain ○ Completely technology agnostic by using Interfaces ○ Contains Components and Shared Kernel
  • 35. Component / Business process - example ● Entities ○ Entity1 ○ Entity2 ● Repositories ○ Entity1RepositoryInterface ○ Entity2RepositoryInterface ● Service ● Tests
  • 36. Component / Business process - notes ● If Entity1 references lots of Entity2 (oneToMany) ○ Make separate repository for each Entity ○ Foreign keys are ok within Component ● Repositories ○ Generic methods (at least) ○ Performance optimized methods if needed (counting) ● Service ○ Calling methods changes state of Entity ● Tests ○ Unit tests
  • 37. Component / Business process - notes ● Tracking - each component may track it’s own domain specific history changes ○ Consider tracking more than needed - business will ask soon about KPIs ○ To solve storage/performance issue implementation may use NoSQL ○ Tracking may be explicit (in domain) or implicit (via tracking dispatched events) ● Passing data to service methods ○ Simple types makes testing easier
  • 38. Shared kernel - notes ● Components commonly used by other Components (Event Dispatcher, Base Entity Classes, Traits, Scheduler) ● Changes may affect other Components
  • 39. Components relation to other components ● Assigning Entity reference to Entity from other component ○ In most cases ID is enough (avoid foreign keys) ○ Referencing different kinds of Entities by storing Context Type and Context ID, example: ■ Type Match and Match ID ■ Type Tournament and Tournament ID
  • 40. Relation on code level vs service level ● Code level ○ Single app instance ○ Higher level components may extend lower level components with plugins ○ Coupled code vs Dispatching Events ● Service level (SOA / Microservices) ○ No code sharing ○ Access only via API / Messaging
  • 41. Technical components ● Do not mix low level technical components with Domain ● Naming basing on Context: ○ Image processing ○ Communication (Websockets / HTTP / Queue) ○ Domain Framework (ie Interfaces for Commands, Dispatcher) ○ Addition to 3rd party framework (Symfony / Laravel)
  • 42. CQRS
  • 43. Command Query Responsibility Segregation Source: https://microservices.io/patterns/data/cqrs.html
  • 44. What if I don’t have full CQRS? ● Commands will use Services from domain ● Queries ○ In simplest form may use existing Repositories from Components ○ Consider separate Repository Interface for Commands/Services and Queries ○ Keep adding counters / redundant data step by step avoid complex joins and speed up queries ○ Over time Query Repository may use more advanced solutions
  • 50. My Class ● Is it technical, domain or connecting domain with framework? ● Is it for state change or reading? ● Is it generic or application/use case specific? ● Does it have state? ● Which properties are optimization purposes? ● What Bounded Contexts it should be aware of?
  • 51. Summary ● Chosen approach depends on team’s experience, available time, project’s lifespan ● Seek for Bounded Context in non DDD components/layers too! ● Coupling within Component is good. Unnecessary coupling between Components is bad. ● There are no strict rules, each team goes their own path ● Introduce new ideas in your project step by step ● Explore, make mistakes, improve
  • 52. Resources ● https://www.infoq.com/minibooks/domain-driven-design-quickly ● https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/ ● https://fideloper.com/hexagonal-architecture ● http://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html ● https://herbertograca.com/2017/11/16/explicit-architecture-01-ddd-hexagonal-onion-clean-cqrs-how-i-put-i t-all-together/
  • 53. Questions? ● hawraniak@red-sky.pl ● Looking for challenges? rekrutacja@red-sky.pl