SlideShare a Scribd company logo
Alessandro Ronchi
Bitbull
@aleron75
Awesome architectures
in Magento 2.3
Awesome architectures
in Magento 2.3
Alessandro Ronchi
Bitbull
@aleron75
This presentation has been realized with kind permission of Riccardo Tempesta (The
Rick); the original one was presented by him at Meet Magento Germany 2019 and the
slides you are seeing here are just a refactoring of his original work. Most of the
content is the same, especially the jokes :)
@MageTitansES @aleron75
And, in turn, most of the work presented here is built standing on the shoulders of
heroes like the Magento architect you see here.
- Igor Miniailo
- Eugene Shakhsuvarov
- Anton Kril
If you are wondering where all this hero culture comes from…
@MageTitansES @aleron75
http://bit.ly/flying-jason
...what would you expect from a community used to this? :)
- COO at Bitbull
- Mage Titans Italy organizer
- Magento Master 2017, 2019
- Top 50 Contributor 2017, 2018
- Magento Community Maintainer
Alessandro Ronchi
@MageTitansES @aleron75
Never stop exploring!
Just a couple of words about me.
Agenda
1. The Magento legacy
2. Software architectures evolution
3. Evolution of Magento 2
4. Some applied concepts
Confused about
Magento development?
We’ve heard that someone feels a bit stressed by developing on Magento 2 and this
probably comes from a bit of confusion.
Nevertheless I’ve talked with Mark, a 23yo guy, who told me that developing on
Magento 2 is not stressful at all.
“Being a Magento 2 developer
is not stressful at all”
~ Mark, 23 years old
@MageTitansES @aleron75
You can see the quote from Mark…
And yes, you spotted out the joke because, actually, Mark is only 20yo :)
CONFUSION
from Latin: “cum” + “fusus”
So where this stress come from?
To understand, let’s see where this confusion comes from.
M2 !== M1
It comes from the fact that M2 is not a revolution but an evolution of M1: M1 is our
legacy, merged into M2.
Despite this, we shouldn’t develop on M2 the same way we did on M1, here is where
the confusion likely comes from.
Software architecture
evolution: 1990’s to 2010’s
To better understand our legacy and the direction M2 is getting, let me briefly run
through the evolution of software architectures of last decades.
And indulge me to do it like any legit Italian should do it.
Software architecture: 1990s
@MageTitansES @aleron75
By making analogies with pasta :)
In the ‘90s we had spaghetti coding, also known as “copy & paste” code.
Software architecture: 1990s
@MageTitansES @aleron75
- no standards
- fast development
- no maintenance
At that time we had very few standards for web applications, the market required fast
development and the concept of software maintenance was pretty new.
As a result, code suffered from high coupling, we couldn’t change one piece of code
without affecting another and, infact, we didn’t do it.
Rather, we preferred to copy logic here and there because applying changes could
have brought undesired side effects (known as regressions).
Without tests, we couldn’t perform refactoring and w/o refactoring we couldn’t clean
the kitchen, we couldn’t increase the quality and maintainability of our code.
Software architecture: 2000s
@MageTitansES @aleron75
Then we had the lasagna coding.
Software architecture: 2000s
@MageTitansES @aleron75
- bigger complexity
- testability
- scalability (as a whole)
In the 2000s the market required more complex, testable and scalable web
applications.
We realized that we could obtain this by isolating some responsibilities into layers.
So n-layered applications came out.
Typical 3-layered: presentation, business logic, data handling.
This architecture is not bad per se, this is how, for example, M1 was built.
But there are some limitations:
- not possible to scalable separately read/write
- app deployed as a whole (monolithic application)
- layers tend to reflect the data model, UIs are typically CRUD oriented
Software architecture: 2010s
@MageTitansES @aleron75
Finally we realized that we could split a monolith into smaller pieces, each with single
specific responsibility, with something good inside exposed through public interfaces
(APIs).
It was time to serve ravioli!
Software architecture: 2010s
@MageTitansES @aleron75
- composition
- independent deployability
- independent scalability
This kind of applications allows us to compose functionality, deploy and scale them
independently.
This is what we called Service Oriented Architectures and, more trendily,
microservices.
What about
Magento 2 evolution?
But is this the change M2 is embracing?
@MageTitansES @aleron75
Yes and no.
M2 is evolving; nowadays Magento Core Engineers prefer to speak of “service
isolation”.
Service Isolation Upsides
1. SCALABILITY
2. DEPLOYABILITY
3. REPLACEABILITY
4. UPGRADABILITY
The key common adjective in this list is: independent
BUT TODAY?
Just let’s step back to current state of M2.
@MageTitansES @aleron75
We already have replaceability, through DI, right?
@MageTitansES @aleron75
...that can brings us to situations like the one illustrated.
This comes as a legacy from Magento 1 and it became evident thanks to DI.
Why having all these dependencies (which btw is not good) was not evident before?
final class Mage
Because of the infamous “God” class of M1
It allowed a class to easily depend on other classes at the cost of “hiding” this
dependency (while adding more and more responsibilities).
DI made all these dependencies evident in M2 and revealed the architectural
problems of M1: classes had too much responsibilities.
@MageTitansES @aleron75
But we can have replaceability through modularity!
MODULES !== MODULARITY
Not quite: having modules doesn’t mean having a real modular architecture.
Real modularity is the very first step towards Service Isolation.
MODULARITY
CONTEXT ISOLATION
So let’s see what are the main features of modularity, because this is driving M2
evolution at date.
@MageTitansES @aleron75
Bounded Contexts
InventoryCatalog Checkout Customer ...
Bounded Contexts is a concept that comes from Domain Driven Design; in brief:
DDD is an approach to software development that helps us taking decisions about
how to design our application speaking the ubiquitous language of the Domain
Experts (our customer) and trying to avoid ambiguity and focusing on design
simplification.
A Bounded Context is a unit in which all the elements that we design have an
ubiquitous meaning and possibly a single responsibility, allowing us to reach
design simplification.
Another Inventory
@MageTitansES @aleron75
Bounded Contexts: replaceability
Inventory
Catalog Checkout Customer ...
Isolating elements (concepts) in bounded context easily allows to obtain
replaceability, one of the key goals of Service Isolation.
@MageTitansES @aleron75
Bounded Contexts: example
Catalog
- sku
- name
- description
...
Let’s see an example: the representation of a product in different contexts.
@MageTitansES @aleron75
Bounded Contexts: example
Catalog
- sku
- name
- description
...
Inventory
- sku
- physical qty
- in stock
...
Here we see that a product in different contexts can have different attributes.
@MageTitansES @aleron75
Bounded Contexts: example
Catalog
- sku
- name
- description
...
Inventory
- sku
- physical qty
- in stock
...
Checkout
- sku
- salable qty
- unit price
...
Different responsibilities, different behaviors, no need to generalize in a unique
concept that would be:
- charged with too many responsibilities
- prone to ambiguity: what does a “qty” property represent? Physical
availability? Salable quantity?
@MageTitansES @aleron75
Bounded Contexts: example
Catalog
Product
Inventory
Source Item
Checkout
Quote Item
In different contexts, the same concept maps to different entities.
Different entities can be simpler, more specialized, less ambiguous.
@MageTitansES @aleron75
Bounded Contexts in M2
http://bit.ly/mage2si
So, for example, we can identify the Catalog Context in M2...
@MageTitansES @aleron75
Bounded Contexts in M2
http://bit.ly/mage2si
...the Customer...
@MageTitansES @aleron75
Bounded Contexts in M2
http://bit.ly/mage2si
...the Checkout...
@MageTitansES @aleron75
Bounded Contexts in M2
http://bit.ly/mage2si
...and many more.
This is the big picture of bounded contexts in M2.
MODULARITY
CONTEXT INTERACTIONS
Once we have context isolation, we need contexts to interact with each other.
@MageTitansES @aleron75
Contexts Interaction
Inventory Sales
How Inventory and Sales communicate?
@MageTitansES @aleron75
Contexts Interaction in M1: coupled
Inventory Sales
MUTUAL DEPENDENCY
This is how context interaction works in M1 (and still works in the majority of M2
codebase): we have mutual dependency between different contexts.
That’s not what we want.
@MageTitansES @aleron75
Contexts Interaction in M2: decoupled
Inventory
Sales
Inventory Sales
Uses plugins to
add/change logic
This, instead, is how ideally we can achieve decoupled context interaction in M2:
through the usage of a specific context which makes the connection b/w two isolated
contexts that don’t share anything with each other.
This third element implements specialized business logic and can use plugins to
interact with the other contexts.
WHY PLUGINS?
Let’s see why plugins are the best choice by looking at alternatives.
@MageTitansES @aleron75
Observers: why not
Extension point
Observer
Event
Event
Extension point
- soft dependencies
- rely only on existing extension points
Observers don’t allow us to define hard evident dependencies meaning that, if the
event that is observed is not dispatched, the observer is not triggered.
If something is not working we don’t have evidence of that.
Furthermore, we can only rely on extension points that have been previously defined:
no event triggered, no extension point.
@MageTitansES @aleron75
Preferences: why not always
- some classes still do too much
- can be used on single responsibility classes
- all or none
MANY RESPONSIBILITIES
TOO MANY POTENTIAL SIDE EFFECTS
SINGLE RESPONSIBILITY
(WHEN AVAILABLE)
Preferences allow us to replace a core class with our own implementation. That can
work sometimes but the truth is that a lot of classes in M2 still have a lot of
responsibilities; replacing a class means taking the ownership of all its business logic.
Maybe we need to change only a few behaviors.
Through preferences, there can be only one class replacing another at the same time,
no space for others.
@MageTitansES @aleron75
Plugins: the best option
- hard & explicit dependencies
- no extension point needed (more or less)
- work at method level
Plugins are the best option, because they don’t have the drawbacks seen:
- dependency is hard and explicit because we declare the class which we are
pluginizing by passing it as the $subject parameter
- we don’t need the core team to have foreseen the possible extension point
because we can pluginize every public method (read more here)
- they work at method level and multiple plugins can coexist on the same class
and even on the same method
MODULARITY
API FIRST
Last, but not least, real modularity can be achieved by designing a system that rely
on abstractions, that is, interfaces or, in other words, APIs.
@MageTitansES @aleron75
API first
API / Interface
API / Interface Concrete implementation
@MageTitansES @aleron75
API first
MyModuleApi MyModule
@MageTitansES @aleron75
API first
@MageTitansES @aleron75
API first: replaceability
MyModuleApi MyModule
AnotherModule
- modules only depend on abstractions
Again, depending on abstractions allows us to obtain replaceability
@MageTitansES @aleron75
API first
Here is an example of an “Interface-only” module
@MageTitansES @aleron75
API first
And here an example of the dependencies form interface modules declared in
composer.json
@MageTitansES @aleron75
API first: modules splitting
http://bit.ly/mage2si
This is a picture made among others by Anton Kril, Director of Architecture at
Magento, that summarizes the possible scenarios before and after applying this
approach.
You can find this and other diagrams in the Service Isolation repository linked before:
http://bit.ly/mage2si
@MageTitansES @aleron75
Modules splitting: so many modules!
MSI is 40+ modules, so far...
A consequence of this approach is the growing number of modules required to
implement a functionality.
@MageTitansES @aleron75
Service isolation
...first reaction...
The first reaction may be panic....
@MageTitansES @aleron75
Service isolation
...second reaction...
...or even worse: rejection...
@MageTitansES @aleron75
Service isolation
...but finally, the aha!
...but once we realize the benefits of such approach we eventually can appreciate it.
WHY IS THIS AMAZING?
We are just trading simplicity for something else...
@MageTitansES @aleron75
Service isolation
FULL MODULAR SYSTEM
This approach allows us to have:
- full modularity
FULL MODULAR SYSTEM CLEAR CONTEXT BOUNDARIES
@MageTitansES @aleron75
Service isolation
This approach allows us to have:
- full modularity
- clear context boundaries
FULL MODULAR SYSTEM CLEAR CONTEXT BOUNDARIES EASY TO FIND RESPONSIBILITIES
@MageTitansES @aleron75
Service isolation
This approach allows us to have:
- full modularity
- clear context boundaries
- classes that are easier to find because they have fewer responsibilities,
located in proper namespaces
FULL MODULAR SYSTEM CLEAR CONTEXT BOUNDARIES EASY TO FIND RESPONSIBILITIES
REPLACEABILITY
@MageTitansES @aleron75
Service isolation
This approach allows us to have:
- full modularity
- clear context boundaries
- classes that are easier to find because they have few responsibilities located
in proper namespaces
- we get replaceability, making it easier to override entire parts of core module
FULL MODULAR SYSTEM CLEAR CONTEXT BOUNDARIES EASY TO FIND RESPONSIBILITIES
REPLACEABILITY INDEPENDENT SCALABILITY
@MageTitansES @aleron75
Service isolation
This approach allows us to have:
- full modularity
- clear context boundaries
- classes that are easier to find because they have few responsibilities located
in proper namespaces
- we get replaceability, making it easier to override entire parts of core module
- and finally, we can scale pieces of application independently thanks to DB
isolation
DB ISOLATION
Let’s see how DB isolation works
@MageTitansES @aleron75
DB isolation: foreign keys?
FK
Source Item
product_id product_id
Product
In Magento 1 (and still in the majority of Magento 2 as well), we can’t split the DB not
to break referential integrity.
FK
Source Item
product_id product_id
Product
FK: THE DATABASE MUST BE THE SAME
@MageTitansES @aleron75
DB isolation: foreign keys?
Because of this “internal” link, different parts of the application must share the same
DB.
Source Item
sku sku
Product
@MageTitansES @aleron75
DB isolation: foreign keys?
use business keys: no DB dependency
So what can we do to avoid problems with foreign keys?
Get rid of them! Using business keys, instead.
Source Item
sku sku
Product
use business keys: no DB dependency
@MageTitansES @aleron75
DB isolation: foreign keys?
Pay attention, this comes at a cost: we lose something, of course, because we are
entering in the field of distributed systems where immediate data consistency is
not always guaranteed.
THE CAP THEOREM
The Cap Theorem, also known as Brewer’s Theorem.
@MageTitansES @aleron75
The CAP theorem
Reference:
https://www.dataversity.net/acid-vs-base-the-shifting-ph-of-database-transaction-proc
essing/
There are three essential system requirements necessary for the successful
design, implementation and deployment of distributed applications.
They are Consistency, Availability and Partition Tolerance – or CAP:
- Consistency: all nodes see the same data at the same time
- Availability: node failures don’t prevent the system to continue working
- Partition Tolerance: network failures don’t prevent the system to
continue working
CA: typical of ACID systems (Atomicity, Consistency, Isolation, Durability: M1) - not
good for scaling
CP: typical of BASE systems (Basically Available, Soft state, Eventual consistency:
M2)
in distributed systems
we can guarantee
only two!
@MageTitansES @aleron75
The CAP theorem
The CAP Theorem states that in distributed systems we can guarantee only two of the
three requirements.
Magento 1 is an ACID system where we have Consistency and Availability
guaranteed.
in large scalable
distributed systems
we give up on
immediate consistency
@MageTitansES @aleron75
The CAP theorem
The Service Isolated architecture towards which Magento 2 is evolving requires it to
abandon Immediate Consistency shifting from an ACID to a BASE system.
in large scalable
distributed systems
we rely on
eventual consistency
@MageTitansES @aleron75
The CAP theorem
Eventual Consistency means that the system will eventually become consistent
once it stops receiving input.
The data will propagate to everywhere it should sooner or later, but the system will
continue to receive input and is not checking the consistency of every transaction
before it moves onto the next one.
Examples of eventual consistency we experience everyday as users:
- Dropbox
- Git
- Google Docs
We read data from hereWe write data here
Separate contexts can have different representation of an information.
Data projection doesn’t happen necessarily in real-time and can take some time.
DATA PROJECTION
@MageTitansES @aleron75
Eventual consistency
A diagram illustrating how data becomes consistent b/w different systems.
@MageTitansES @aleron75
Eventual consistency
http://bit.ly/eventualc
Don’t forget to follow Greg Young and read all his articles and books if you are
interested in DDD, CQRS, Event Sourcing, etc.
Is this the real life?
Is this just fantasy?
Let me anticipate a question that can come from the audience.
All the ideas expressed here are the result of how Magento Inventory (formerly MSI)
is developed and chances are that the future architecture of Magento 2 (or should we
call it Magento 3?) is going towards this.
As an old Chinese saying tells us: "A journey of a thousand miles begins with a single
step"
@MageTitansES @aleron75
Reference: MSI Magento Inventory
http://bit.ly/mageinventory
That’s why I heavily recommend to start looking at the Magento Inventory Project.
Good reads
http://bit.ly/dsbook1 http://bit.ly/dsbook2 http://bit.ly/dsbook3
FREE!
Here are some recommended books about distributed systems:
- Designing Data-Intensive Applications http://bit.ly/dsbook1
- Building Microservices http://bit.ly/dsbook2
- Distributed Systems (introductory, easy, free, must read!) http://bit.ly/dsbook3
What I learned
1. M2: CONTINUOUS IMPROVEMENT
2. SERVICE ISOLATION
3. DISTRIBUTED SYSTEM (M3?)
4. LEARN BY CONTRIBUTING
To recap the lessons learned:
- Magento is under continuous improvement
- At date, Service Isolation is the number one goal of architectural evolution
- In the future, Magento could become a distributed platform
- All the information provided in this presentation (and many, many more) were
learned by contributing to the Magento core
“there’s no better way to learn!”
Paraphrasing a famous flying company, contributing is the better way to learn (in my
opinion).
@MageTitansES @aleron75
Get involved in the evolution!
It’s up to you: hate or help!
https://magentocommeng.slack.com/messages#appdesign
Jump in, if you want.
I thank you all!
Alessandro Ronchi
Bitbull
@aleron75
“You brought me fame and fortune and everything that goes with it.
I thank you all” ~ Freddy Mercury
Any questions?
Alessandro Ronchi
Bitbull
@aleron75

More Related Content

PPTX
Something Architecture
PPTX
Multi-Source Inventory. Imagine. Las Vegas. 2018
PPTX
Chernivtsi Magento Meetup&Contribution day. Miniailo.I.
PPTX
Multi Source Inventory (MSI) in Magento 2
PPTX
Magento Multi-Source Inventory (MSI)
PPTX
Valeriy Nayda - Best Practices in Magento 2. Based on Multi Source Inventory ...
PPTX
Igor Miniailo - Magento 2 API Design Best Practices
PPTX
Backwards Compatibility Developers Guide. #MM17NL
Something Architecture
Multi-Source Inventory. Imagine. Las Vegas. 2018
Chernivtsi Magento Meetup&Contribution day. Miniailo.I.
Multi Source Inventory (MSI) in Magento 2
Magento Multi-Source Inventory (MSI)
Valeriy Nayda - Best Practices in Magento 2. Based on Multi Source Inventory ...
Igor Miniailo - Magento 2 API Design Best Practices
Backwards Compatibility Developers Guide. #MM17NL

What's hot (20)

PPTX
Experience in Magento Community Projects
PDF
James Zetlen - PWA Studio Integration…With You
PDF
Chernivtsi Magento Meetup&Contribution day. Naida V.
PPTX
APIdays Helsinki 2019 - Impact of Microservices Architecture on API Managemen...
PDF
Volodymyr Kublytskyi - Develop Product, Design Platform
PPTX
Flamingo presentation at code.talks commerce by Daniel Pötzinger
PDF
Jacopo Nardiello - From CI to Prod: Running Magento at scale with Kubernetes
PPTX
How Customers are Building and Using their Own Connectors
PPT
Meet Magento Belarus - Elena Leonova
PDF
Flamingo - Inspiring Commerce Frontend made in Go - Meet Magento 2019
PPTX
Micro frontend architecture_presentation_ssoni
PDF
Outlook on Magento 2
PDF
Decoupled Days 2019: Delivering Headless Commerce
PDF
Moose.ai: migliorare la customer experience delle banche con un chatbot B2C &...
PPTX
The Effect of Microservices on API Design
PDF
Serverless chatbot: from idea to production at blazing speed
PDF
API first Design and Microservices
PPTX
Software architecture in practice
PDF
APIdays Helsinki 2019 - The Future of the Dynamic Application Server, NGINX U...
PDF
[API World 2021 ] - Understanding Cloud Native Deployment
Experience in Magento Community Projects
James Zetlen - PWA Studio Integration…With You
Chernivtsi Magento Meetup&Contribution day. Naida V.
APIdays Helsinki 2019 - Impact of Microservices Architecture on API Managemen...
Volodymyr Kublytskyi - Develop Product, Design Platform
Flamingo presentation at code.talks commerce by Daniel Pötzinger
Jacopo Nardiello - From CI to Prod: Running Magento at scale with Kubernetes
How Customers are Building and Using their Own Connectors
Meet Magento Belarus - Elena Leonova
Flamingo - Inspiring Commerce Frontend made in Go - Meet Magento 2019
Micro frontend architecture_presentation_ssoni
Outlook on Magento 2
Decoupled Days 2019: Delivering Headless Commerce
Moose.ai: migliorare la customer experience delle banche con un chatbot B2C &...
The Effect of Microservices on API Design
Serverless chatbot: from idea to production at blazing speed
API first Design and Microservices
Software architecture in practice
APIdays Helsinki 2019 - The Future of the Dynamic Application Server, NGINX U...
[API World 2021 ] - Understanding Cloud Native Deployment
Ad

Similar to Awesome architectures in Magento 2.3 (20)

PDF
How I ended up contributing to Magento core
PPTX
Awesome Architectures in Magento 2.3
PDF
The lessons I learned contributing to #MagentoMSI
PPT
Architecting for Change: An Agile Approach
PPTX
Microservice architecture : Part 1
PDF
CWIN17 Utrecht / cg u services - frank van der wal
PPTX
Introduction to Serverless. Oracle Fn Project.
PPTX
MuleSoft London Community March 2018 - The power of the Crowd
PDF
What Is Microservices Architecture and How Does It Benefit App Development.pdf
PPTX
Let's talk about... Microservices
PDF
Microservices in Golang
PPTX
Software application architecture
PDF
Can low-code overturn this wisdom?
PPTX
Introduction to microservices
PDF
Technical-design-for-Angular-apps.pdf
PDF
Approaching risk management with your head in the cloud
PDF
Devnexus - Nowadays Architecture Trends, from Monolith to Microservices and S...
PDF
locotalk-whitepaper-2016
PDF
Monoliths, Myths, and Microservices
PPTX
Microservices with mule
How I ended up contributing to Magento core
Awesome Architectures in Magento 2.3
The lessons I learned contributing to #MagentoMSI
Architecting for Change: An Agile Approach
Microservice architecture : Part 1
CWIN17 Utrecht / cg u services - frank van der wal
Introduction to Serverless. Oracle Fn Project.
MuleSoft London Community March 2018 - The power of the Crowd
What Is Microservices Architecture and How Does It Benefit App Development.pdf
Let's talk about... Microservices
Microservices in Golang
Software application architecture
Can low-code overturn this wisdom?
Introduction to microservices
Technical-design-for-Angular-apps.pdf
Approaching risk management with your head in the cloud
Devnexus - Nowadays Architecture Trends, from Monolith to Microservices and S...
locotalk-whitepaper-2016
Monoliths, Myths, and Microservices
Microservices with mule
Ad

More from Alessandro Ronchi (13)

PDF
Mage-OS - signals from the community - Magentiamo Day 2024
PDF
Mage-OS Fork it, Own it, Grow it, Better!
PDF
Meet Magento IT 2021 - Principles & Advantages of Hexagonal Architecture on M...
PDF
Some lessons learned contributing to #MagentoMSI
PDF
How I ended up touching Magento core
PDF
B2B & Magento: a long journey tale
PDF
Need to estimate? Let's play poker!
PDF
Why I did one step backward to go forward
PDF
A true story about Magento best practices
PDF
Magento best practices
PDF
Mageday::2014 - Workshop
PDF
Mageday::2014
PDF
Mageploy presentato al Mage::day() 2013
Mage-OS - signals from the community - Magentiamo Day 2024
Mage-OS Fork it, Own it, Grow it, Better!
Meet Magento IT 2021 - Principles & Advantages of Hexagonal Architecture on M...
Some lessons learned contributing to #MagentoMSI
How I ended up touching Magento core
B2B & Magento: a long journey tale
Need to estimate? Let's play poker!
Why I did one step backward to go forward
A true story about Magento best practices
Magento best practices
Mageday::2014 - Workshop
Mageday::2014
Mageploy presentato al Mage::day() 2013

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Spectroscopy.pptx food analysis technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Machine learning based COVID-19 study performance prediction
sap open course for s4hana steps from ECC to s4
Review of recent advances in non-invasive hemoglobin estimation
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
The AUB Centre for AI in Media Proposal.docx
Per capita expenditure prediction using model stacking based on satellite ima...
Chapter 3 Spatial Domain Image Processing.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Reach Out and Touch Someone: Haptics and Empathic Computing
NewMind AI Weekly Chronicles - August'25 Week I
Unlocking AI with Model Context Protocol (MCP)
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Dropbox Q2 2025 Financial Results & Investor Presentation
Spectroscopy.pptx food analysis technology
Advanced methodologies resolving dimensionality complications for autism neur...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
MYSQL Presentation for SQL database connectivity
Machine learning based COVID-19 study performance prediction

Awesome architectures in Magento 2.3

  • 2. Awesome architectures in Magento 2.3 Alessandro Ronchi Bitbull @aleron75 This presentation has been realized with kind permission of Riccardo Tempesta (The Rick); the original one was presented by him at Meet Magento Germany 2019 and the slides you are seeing here are just a refactoring of his original work. Most of the content is the same, especially the jokes :)
  • 3. @MageTitansES @aleron75 And, in turn, most of the work presented here is built standing on the shoulders of heroes like the Magento architect you see here. - Igor Miniailo - Eugene Shakhsuvarov - Anton Kril If you are wondering where all this hero culture comes from…
  • 5. - COO at Bitbull - Mage Titans Italy organizer - Magento Master 2017, 2019 - Top 50 Contributor 2017, 2018 - Magento Community Maintainer Alessandro Ronchi @MageTitansES @aleron75 Never stop exploring! Just a couple of words about me.
  • 6. Agenda 1. The Magento legacy 2. Software architectures evolution 3. Evolution of Magento 2 4. Some applied concepts
  • 7. Confused about Magento development? We’ve heard that someone feels a bit stressed by developing on Magento 2 and this probably comes from a bit of confusion. Nevertheless I’ve talked with Mark, a 23yo guy, who told me that developing on Magento 2 is not stressful at all.
  • 8. “Being a Magento 2 developer is not stressful at all” ~ Mark, 23 years old @MageTitansES @aleron75 You can see the quote from Mark… And yes, you spotted out the joke because, actually, Mark is only 20yo :)
  • 9. CONFUSION from Latin: “cum” + “fusus” So where this stress come from? To understand, let’s see where this confusion comes from.
  • 10. M2 !== M1 It comes from the fact that M2 is not a revolution but an evolution of M1: M1 is our legacy, merged into M2. Despite this, we shouldn’t develop on M2 the same way we did on M1, here is where the confusion likely comes from.
  • 11. Software architecture evolution: 1990’s to 2010’s To better understand our legacy and the direction M2 is getting, let me briefly run through the evolution of software architectures of last decades. And indulge me to do it like any legit Italian should do it.
  • 12. Software architecture: 1990s @MageTitansES @aleron75 By making analogies with pasta :) In the ‘90s we had spaghetti coding, also known as “copy & paste” code.
  • 13. Software architecture: 1990s @MageTitansES @aleron75 - no standards - fast development - no maintenance At that time we had very few standards for web applications, the market required fast development and the concept of software maintenance was pretty new. As a result, code suffered from high coupling, we couldn’t change one piece of code without affecting another and, infact, we didn’t do it. Rather, we preferred to copy logic here and there because applying changes could have brought undesired side effects (known as regressions). Without tests, we couldn’t perform refactoring and w/o refactoring we couldn’t clean the kitchen, we couldn’t increase the quality and maintainability of our code.
  • 14. Software architecture: 2000s @MageTitansES @aleron75 Then we had the lasagna coding.
  • 15. Software architecture: 2000s @MageTitansES @aleron75 - bigger complexity - testability - scalability (as a whole) In the 2000s the market required more complex, testable and scalable web applications. We realized that we could obtain this by isolating some responsibilities into layers. So n-layered applications came out. Typical 3-layered: presentation, business logic, data handling. This architecture is not bad per se, this is how, for example, M1 was built. But there are some limitations: - not possible to scalable separately read/write - app deployed as a whole (monolithic application) - layers tend to reflect the data model, UIs are typically CRUD oriented
  • 16. Software architecture: 2010s @MageTitansES @aleron75 Finally we realized that we could split a monolith into smaller pieces, each with single specific responsibility, with something good inside exposed through public interfaces (APIs). It was time to serve ravioli!
  • 17. Software architecture: 2010s @MageTitansES @aleron75 - composition - independent deployability - independent scalability This kind of applications allows us to compose functionality, deploy and scale them independently. This is what we called Service Oriented Architectures and, more trendily, microservices.
  • 18. What about Magento 2 evolution? But is this the change M2 is embracing?
  • 19. @MageTitansES @aleron75 Yes and no. M2 is evolving; nowadays Magento Core Engineers prefer to speak of “service isolation”.
  • 20. Service Isolation Upsides 1. SCALABILITY 2. DEPLOYABILITY 3. REPLACEABILITY 4. UPGRADABILITY The key common adjective in this list is: independent
  • 21. BUT TODAY? Just let’s step back to current state of M2.
  • 22. @MageTitansES @aleron75 We already have replaceability, through DI, right?
  • 23. @MageTitansES @aleron75 ...that can brings us to situations like the one illustrated. This comes as a legacy from Magento 1 and it became evident thanks to DI. Why having all these dependencies (which btw is not good) was not evident before?
  • 24. final class Mage Because of the infamous “God” class of M1 It allowed a class to easily depend on other classes at the cost of “hiding” this dependency (while adding more and more responsibilities). DI made all these dependencies evident in M2 and revealed the architectural problems of M1: classes had too much responsibilities.
  • 25. @MageTitansES @aleron75 But we can have replaceability through modularity!
  • 26. MODULES !== MODULARITY Not quite: having modules doesn’t mean having a real modular architecture. Real modularity is the very first step towards Service Isolation.
  • 27. MODULARITY CONTEXT ISOLATION So let’s see what are the main features of modularity, because this is driving M2 evolution at date.
  • 28. @MageTitansES @aleron75 Bounded Contexts InventoryCatalog Checkout Customer ... Bounded Contexts is a concept that comes from Domain Driven Design; in brief: DDD is an approach to software development that helps us taking decisions about how to design our application speaking the ubiquitous language of the Domain Experts (our customer) and trying to avoid ambiguity and focusing on design simplification. A Bounded Context is a unit in which all the elements that we design have an ubiquitous meaning and possibly a single responsibility, allowing us to reach design simplification.
  • 29. Another Inventory @MageTitansES @aleron75 Bounded Contexts: replaceability Inventory Catalog Checkout Customer ... Isolating elements (concepts) in bounded context easily allows to obtain replaceability, one of the key goals of Service Isolation.
  • 30. @MageTitansES @aleron75 Bounded Contexts: example Catalog - sku - name - description ... Let’s see an example: the representation of a product in different contexts.
  • 31. @MageTitansES @aleron75 Bounded Contexts: example Catalog - sku - name - description ... Inventory - sku - physical qty - in stock ... Here we see that a product in different contexts can have different attributes.
  • 32. @MageTitansES @aleron75 Bounded Contexts: example Catalog - sku - name - description ... Inventory - sku - physical qty - in stock ... Checkout - sku - salable qty - unit price ... Different responsibilities, different behaviors, no need to generalize in a unique concept that would be: - charged with too many responsibilities - prone to ambiguity: what does a “qty” property represent? Physical availability? Salable quantity?
  • 33. @MageTitansES @aleron75 Bounded Contexts: example Catalog Product Inventory Source Item Checkout Quote Item In different contexts, the same concept maps to different entities. Different entities can be simpler, more specialized, less ambiguous.
  • 34. @MageTitansES @aleron75 Bounded Contexts in M2 http://bit.ly/mage2si So, for example, we can identify the Catalog Context in M2...
  • 35. @MageTitansES @aleron75 Bounded Contexts in M2 http://bit.ly/mage2si ...the Customer...
  • 36. @MageTitansES @aleron75 Bounded Contexts in M2 http://bit.ly/mage2si ...the Checkout...
  • 37. @MageTitansES @aleron75 Bounded Contexts in M2 http://bit.ly/mage2si ...and many more. This is the big picture of bounded contexts in M2.
  • 38. MODULARITY CONTEXT INTERACTIONS Once we have context isolation, we need contexts to interact with each other.
  • 39. @MageTitansES @aleron75 Contexts Interaction Inventory Sales How Inventory and Sales communicate?
  • 40. @MageTitansES @aleron75 Contexts Interaction in M1: coupled Inventory Sales MUTUAL DEPENDENCY This is how context interaction works in M1 (and still works in the majority of M2 codebase): we have mutual dependency between different contexts. That’s not what we want.
  • 41. @MageTitansES @aleron75 Contexts Interaction in M2: decoupled Inventory Sales Inventory Sales Uses plugins to add/change logic This, instead, is how ideally we can achieve decoupled context interaction in M2: through the usage of a specific context which makes the connection b/w two isolated contexts that don’t share anything with each other. This third element implements specialized business logic and can use plugins to interact with the other contexts.
  • 42. WHY PLUGINS? Let’s see why plugins are the best choice by looking at alternatives.
  • 43. @MageTitansES @aleron75 Observers: why not Extension point Observer Event Event Extension point - soft dependencies - rely only on existing extension points Observers don’t allow us to define hard evident dependencies meaning that, if the event that is observed is not dispatched, the observer is not triggered. If something is not working we don’t have evidence of that. Furthermore, we can only rely on extension points that have been previously defined: no event triggered, no extension point.
  • 44. @MageTitansES @aleron75 Preferences: why not always - some classes still do too much - can be used on single responsibility classes - all or none MANY RESPONSIBILITIES TOO MANY POTENTIAL SIDE EFFECTS SINGLE RESPONSIBILITY (WHEN AVAILABLE) Preferences allow us to replace a core class with our own implementation. That can work sometimes but the truth is that a lot of classes in M2 still have a lot of responsibilities; replacing a class means taking the ownership of all its business logic. Maybe we need to change only a few behaviors. Through preferences, there can be only one class replacing another at the same time, no space for others.
  • 45. @MageTitansES @aleron75 Plugins: the best option - hard & explicit dependencies - no extension point needed (more or less) - work at method level Plugins are the best option, because they don’t have the drawbacks seen: - dependency is hard and explicit because we declare the class which we are pluginizing by passing it as the $subject parameter - we don’t need the core team to have foreseen the possible extension point because we can pluginize every public method (read more here) - they work at method level and multiple plugins can coexist on the same class and even on the same method
  • 46. MODULARITY API FIRST Last, but not least, real modularity can be achieved by designing a system that rely on abstractions, that is, interfaces or, in other words, APIs.
  • 48. API / Interface Concrete implementation @MageTitansES @aleron75 API first
  • 50. @MageTitansES @aleron75 API first: replaceability MyModuleApi MyModule AnotherModule - modules only depend on abstractions Again, depending on abstractions allows us to obtain replaceability
  • 51. @MageTitansES @aleron75 API first Here is an example of an “Interface-only” module
  • 52. @MageTitansES @aleron75 API first And here an example of the dependencies form interface modules declared in composer.json
  • 53. @MageTitansES @aleron75 API first: modules splitting http://bit.ly/mage2si This is a picture made among others by Anton Kril, Director of Architecture at Magento, that summarizes the possible scenarios before and after applying this approach. You can find this and other diagrams in the Service Isolation repository linked before: http://bit.ly/mage2si
  • 54. @MageTitansES @aleron75 Modules splitting: so many modules! MSI is 40+ modules, so far... A consequence of this approach is the growing number of modules required to implement a functionality.
  • 55. @MageTitansES @aleron75 Service isolation ...first reaction... The first reaction may be panic....
  • 56. @MageTitansES @aleron75 Service isolation ...second reaction... ...or even worse: rejection...
  • 57. @MageTitansES @aleron75 Service isolation ...but finally, the aha! ...but once we realize the benefits of such approach we eventually can appreciate it.
  • 58. WHY IS THIS AMAZING? We are just trading simplicity for something else...
  • 59. @MageTitansES @aleron75 Service isolation FULL MODULAR SYSTEM This approach allows us to have: - full modularity
  • 60. FULL MODULAR SYSTEM CLEAR CONTEXT BOUNDARIES @MageTitansES @aleron75 Service isolation This approach allows us to have: - full modularity - clear context boundaries
  • 61. FULL MODULAR SYSTEM CLEAR CONTEXT BOUNDARIES EASY TO FIND RESPONSIBILITIES @MageTitansES @aleron75 Service isolation This approach allows us to have: - full modularity - clear context boundaries - classes that are easier to find because they have fewer responsibilities, located in proper namespaces
  • 62. FULL MODULAR SYSTEM CLEAR CONTEXT BOUNDARIES EASY TO FIND RESPONSIBILITIES REPLACEABILITY @MageTitansES @aleron75 Service isolation This approach allows us to have: - full modularity - clear context boundaries - classes that are easier to find because they have few responsibilities located in proper namespaces - we get replaceability, making it easier to override entire parts of core module
  • 63. FULL MODULAR SYSTEM CLEAR CONTEXT BOUNDARIES EASY TO FIND RESPONSIBILITIES REPLACEABILITY INDEPENDENT SCALABILITY @MageTitansES @aleron75 Service isolation This approach allows us to have: - full modularity - clear context boundaries - classes that are easier to find because they have few responsibilities located in proper namespaces - we get replaceability, making it easier to override entire parts of core module - and finally, we can scale pieces of application independently thanks to DB isolation
  • 64. DB ISOLATION Let’s see how DB isolation works
  • 65. @MageTitansES @aleron75 DB isolation: foreign keys? FK Source Item product_id product_id Product In Magento 1 (and still in the majority of Magento 2 as well), we can’t split the DB not to break referential integrity.
  • 66. FK Source Item product_id product_id Product FK: THE DATABASE MUST BE THE SAME @MageTitansES @aleron75 DB isolation: foreign keys? Because of this “internal” link, different parts of the application must share the same DB.
  • 67. Source Item sku sku Product @MageTitansES @aleron75 DB isolation: foreign keys? use business keys: no DB dependency So what can we do to avoid problems with foreign keys? Get rid of them! Using business keys, instead.
  • 68. Source Item sku sku Product use business keys: no DB dependency @MageTitansES @aleron75 DB isolation: foreign keys? Pay attention, this comes at a cost: we lose something, of course, because we are entering in the field of distributed systems where immediate data consistency is not always guaranteed.
  • 69. THE CAP THEOREM The Cap Theorem, also known as Brewer’s Theorem.
  • 70. @MageTitansES @aleron75 The CAP theorem Reference: https://www.dataversity.net/acid-vs-base-the-shifting-ph-of-database-transaction-proc essing/ There are three essential system requirements necessary for the successful design, implementation and deployment of distributed applications. They are Consistency, Availability and Partition Tolerance – or CAP: - Consistency: all nodes see the same data at the same time - Availability: node failures don’t prevent the system to continue working - Partition Tolerance: network failures don’t prevent the system to continue working CA: typical of ACID systems (Atomicity, Consistency, Isolation, Durability: M1) - not good for scaling CP: typical of BASE systems (Basically Available, Soft state, Eventual consistency: M2)
  • 71. in distributed systems we can guarantee only two! @MageTitansES @aleron75 The CAP theorem The CAP Theorem states that in distributed systems we can guarantee only two of the three requirements. Magento 1 is an ACID system where we have Consistency and Availability guaranteed.
  • 72. in large scalable distributed systems we give up on immediate consistency @MageTitansES @aleron75 The CAP theorem The Service Isolated architecture towards which Magento 2 is evolving requires it to abandon Immediate Consistency shifting from an ACID to a BASE system.
  • 73. in large scalable distributed systems we rely on eventual consistency @MageTitansES @aleron75 The CAP theorem Eventual Consistency means that the system will eventually become consistent once it stops receiving input. The data will propagate to everywhere it should sooner or later, but the system will continue to receive input and is not checking the consistency of every transaction before it moves onto the next one. Examples of eventual consistency we experience everyday as users: - Dropbox - Git - Google Docs
  • 74. We read data from hereWe write data here Separate contexts can have different representation of an information. Data projection doesn’t happen necessarily in real-time and can take some time. DATA PROJECTION @MageTitansES @aleron75 Eventual consistency A diagram illustrating how data becomes consistent b/w different systems.
  • 75. @MageTitansES @aleron75 Eventual consistency http://bit.ly/eventualc Don’t forget to follow Greg Young and read all his articles and books if you are interested in DDD, CQRS, Event Sourcing, etc.
  • 76. Is this the real life? Is this just fantasy? Let me anticipate a question that can come from the audience. All the ideas expressed here are the result of how Magento Inventory (formerly MSI) is developed and chances are that the future architecture of Magento 2 (or should we call it Magento 3?) is going towards this. As an old Chinese saying tells us: "A journey of a thousand miles begins with a single step"
  • 77. @MageTitansES @aleron75 Reference: MSI Magento Inventory http://bit.ly/mageinventory That’s why I heavily recommend to start looking at the Magento Inventory Project.
  • 78. Good reads http://bit.ly/dsbook1 http://bit.ly/dsbook2 http://bit.ly/dsbook3 FREE! Here are some recommended books about distributed systems: - Designing Data-Intensive Applications http://bit.ly/dsbook1 - Building Microservices http://bit.ly/dsbook2 - Distributed Systems (introductory, easy, free, must read!) http://bit.ly/dsbook3
  • 79. What I learned 1. M2: CONTINUOUS IMPROVEMENT 2. SERVICE ISOLATION 3. DISTRIBUTED SYSTEM (M3?) 4. LEARN BY CONTRIBUTING To recap the lessons learned: - Magento is under continuous improvement - At date, Service Isolation is the number one goal of architectural evolution - In the future, Magento could become a distributed platform - All the information provided in this presentation (and many, many more) were learned by contributing to the Magento core
  • 80. “there’s no better way to learn!” Paraphrasing a famous flying company, contributing is the better way to learn (in my opinion).
  • 81. @MageTitansES @aleron75 Get involved in the evolution! It’s up to you: hate or help! https://magentocommeng.slack.com/messages#appdesign Jump in, if you want.
  • 82. I thank you all! Alessandro Ronchi Bitbull @aleron75 “You brought me fame and fortune and everything that goes with it. I thank you all” ~ Freddy Mercury