Magento 2 Topology and Framework Architecture
From a topology point of view, Magento 2 eCommerce platform is built on layered software architecture with four tiers:
- client (browser cache)
- page cache
In between each tier, multiple load balancer can be added to take full advantage of Magento 2’s high availability design.
From a web application point of view, Magento 2 can be divided into three layers:
- Presentation Layer consists of View Elements and Controllers, worth notice that Magento also shares its core eCommerce functionality via web API endpoints.
- Service Layer is important to the so called “Separation between Presentation from Business Logic”. It holds service contracts which can be swapped by third party modules without impacting other parts of the system. Service contracts are defined as a set of Service and Data Interfaces which provide the main entry point of functions and data access.
- Domain Layer holds business logic that powers a Magento store. It implements service contracts and delivers eCommerce functionality. And just as what we expected from an MVC architecture, the Domain layer (model layer) interact directly with Database Persistence which maintains a high level of security and customisation ability.
- Database Persistence takes advantage of the open source MySQL database system to store business data. In an advanced enterprise setup, database consists of master database for write access of products, orders and customers, and slave database for read access such as catalog, wishlist and checkout. This allows Magento 2 to be scaled to support 3.5 million page views/hour for catalog, and 250,000 orders/hour for orders.
Magento 2 Performance and Scalability Improvements
As we all know, Magento is built on the famous EAV database model. It’s a considered by majority of the Magento community as an ingenious idea for product management but not so much for performance. To combat the known speed issue, Magento 1 introduced flat tables to index and store product info prior to querying. Let’s look at how Magento 2 have improved in its performance.
Client Side Improvements
Maximise Browser Cache. Similar to Magento 1, all JS and CSS files are cached on the initial visit to reduce page download time.
Notice that if you use Apache web server, you can use PageSpeed module to further tune up your browser side optimization such as rendering images with .webp format.
Varnish Page Caching
We believe varnish is a direct answer to Magento’s speed issue. Depends on the size of the merchant, Varnish can be implemented on the same server of Magento, or scaled into different servers then use a load balancer to distribute traffic between multiple Varnish instances.
To deal with large amount of concurrent order and product management requests. Magento 2 offers optional asynchronous update to orchestra product updates, order creation and order processing. This allows a dramatic Magento admin performance boost where multiple orders and products can be updated simultaneously by 25+ admin users.
Job Queue Mechanism
Rabbit MQ is only available to Magento 2 Enterprise Edition which allows for asynchronous processing jobs. Queue workers get the jobs placed in the queue server once they become available. This allows both web server and queue server to be optimised separately according to their loads. With Magento 2 CE edition, Rabbit MQ can be integrated via third party modules such as Magento 2 EnqueueModule.
PHP 7 is claimed to improve the performance of almost all PHP applications with twice the speed of the previous generation.
Multiple Database Masters
Magento 2 supports up to 3 master database for checkout, orders and products. Each master database can have multiple slaves to separate read and write operations. In spite of the complexity of database setup, it doesn’t increase the sophistication of development because Magento uses CQRS (Command Query Responsibility Segregation) database pattern to rout the queries to the appropriate database.
In addition to having multiple slave database to scale reading capability, MySQL Cluster allows Magento 2 to have multiple Master database to scale MySQL for write capability.
Magento 2 offers Performance Toolkit to speed up development. It allows Magento developers to test Magento installation and the impact of customisation. The performance Toolkit generates a large amount of sample data and run Apache JMeter scenarios, so you get an idea of the load capacity of your server.
In addition, Magento 2 also provides a free New Relic extension to monitor store performance.