SlideShare a Scribd company logo
#MM17PL
Sander Mangel
Headless Magento
#MM17PL
β€’ Magento developer
β€’ Lead @ FitForMe
β€’ Co-organiser MMNL,
Unconf, MageStackDay,
Meetups
β€’ Avid community member
twitter.com/sandermangel
linkedin.com/in/sandermangel
github.com/sandermangel
#MM17PL
#MM17PL
What is headless architecture
"Headless architecture means an application offering APIs that abstract away business logic
for a multitude of clients to consistently and repeatedly execute the same tasks."
#MM17PL
Read more
http://bit.ly/2qo6XBc
http://bit.ly/1Wku9c0
http://bit.ly/2rtVIas
http://bit.ly/2qrkQKP
http://bit.ly/2hyM6Dy
#MM17PL
Putting it into practice
#MM17PL
#MM17PL
#MM17PL
?
#MM17PL
Common integrations
● ERP
● Fulfillment
● Logs
● Email server
● ….
#MM17PL
Clients
● Magento backend
● Magento frontend
● Legacy system
● Dashboards
● Magento 2?
#MM17PL
So we take a different
approach
β€’ Magento will be a client &
provide data
β€’ Implement a basic data
warehouse
β€’ Which is fed by, and queried
by various services separated
by domains
β€’ Isolate data & business logic
per domain
That allows for a smooth integration
#MM17PL
#MM17PL
Leverage middleware for a
stable environment
storage
source consumer server
#MM17PL
Leverage middleware for a
stable environment
storage
source consumer server
● Normalize & combine data
● Offer stable APIs for clients
● Insulate from future changes
#MM17PL
#MM17PL
Incoming data
#MM17PL
Build on standardised libraries
● There is a solution for everything
already out there
● Use popular libraries, preferably
adhering to a PSR protocol
● Don't overcomplicate dependency
injection
● Think carefully about what you need
and spend time finding the best
option
[...]
"require": {
"php": ">=7.0",
"slim/slim": "^3.1",
"monolog/monolog": "^1.17",
"cache/filesystem-adapter": "^0.4.0",
"guzzlehttp/guzzle": "^6.2",
"cache/array-adapter": "^0.5.0",
"illuminate/database": "^5.4",
"yadakhov/insert-on-duplicate-key": "^1.1",
"symfony/console": "^3.3",
"league/oauth1-client": "^1.7"
}
[...]
#MM17PL
Build on standardised libraries
● slimphp - Routing, DI
● monolog - gives insight in what the service does
for monitoring and debugging
● cache/… - stores certain API calls, temporary data
● guzzle - offers a way to consume APIs over http
● illuminate/database - Laravel ORM (personal
preference)
● Insert-on-duplicate.... - not a default option in
illuminate/database but a must for me
● symfony/console - for cronjobs and commandline
tasks
● league/oauth1-client - offers built in Magento 1
REST integration
[...]
"require": {
"php": ">=7.0",
"slim/slim": "^3.1",
"monolog/monolog": "^1.17",
"cache/filesystem-adapter": "^0.4.0",
"guzzlehttp/guzzle": "^6.2",
"cache/array-adapter": "^0.5.0",
"illuminate/database": "^5.4",
"yadakhov/insert-on-duplicate-key": "^1.1",
"symfony/console": "^3.3",
"league/oauth1-client": "^1.7"
}
[...]
#MM17PL
Build on standardised libraries
● SlimPHP project as basis
● One module in src some basic
setup files needed by SlimPHP
● Keep it simple and self-contained
#MM17PL
Some learnings
● Single purpose
● It should feel overly simple
● Within the service, separate tasks
● Document, document, document
● Write integration tests for the API
endpoints
● Log everything
#MM17PL
Exposing data
#MM17PL
Exposing data
● Read only
● Easy to integrate
● Offer sorting, filtering, and a host of
other query options
● Be very fast (d'oh)
● Standardized & easily scalable
#MM17PL
Standardizing?
● Output format and syntax
● Filtering and sorting
● Caching
#MM17PL
Enabling various integrations
protected function _prepareCollection()
{
[...]
try {
$client = new Client();
$res = $client->request('GET', $helper->getBaseUrl(0) . 'quarantine?'.
http_build_query([ 'limit' => $limit, 'page' => $page, 'sort' => $columnId, 'sortdir'
=> $dir, 'filters' => (array)$filter, '', '&'));
} catch (Exception $error) {
Mage::logException($error);
$this->setCollection($collection); // set a dummy empty collection
return $this;
}
$data = json_decode($res->getBody(), true);
$lastPage = $data['to'];
array_walk($data['data'], function($order) use (&$collection) {
$collection->addItem(
new Varien_Object(
[ 'shipping_date' => $order['shipping_date'],
'order_reference' => $order['order_reference'],
'customer_reference' => $order['customer_reference'],
'updated_at' => $order['updated_at'],
'shipping_fullname' => "{$order['shipping_firstname']}
{$order['shipping_middlename']} {$order['shipping_lastname']}",
]
)
);
});
$collection->setCurPage($page);
$collection->setLastPageNumber($lastPage);
$collection->setSize($lastPage * $limit);
$this->setCollection($collection);
● Magento 1 grids
● Ajax calls for smaller values
● Data imports
● Communication between services
● ...
#MM17PL
Caching
● How dynamic is dynamic content
● Cache is all about control
● Think of a strategy upfront
#MM17PL
Caching
● How dynamic is dynamic content
● Cache is all about control
● Think of a strategy upfront
https://github.com/magespecialist/m2-M
SP_APIEnhancer
Magento 2 API enhancer
#MM17PL
Wish list & ideas
#MM17PL
Database
● MariaDB
β—‹ Relational
β—‹ Easy to work with
β—‹ Offers good performance up to 1TB
data
● Elastic
β—‹ REST output
β—‹ Plug and play
β—‹ Advanced search
#MM17PL
#MM17PL
Monolithic
● Dedicated / VPS server
β—‹ Offered by all hosting
companies
β—‹ Easy to maintain
β—‹ Does not scale easily
β—‹ If one goes down...
Distributed
● Instances on a cloud
β—‹ Scales easily
β—‹ Environments are isolated
β—‹ Requires more knowledge
β—‹ Can be harder to
administrate
#MM17PL
API gateway
● Allow for easy service discovery
● Handle authentication, call rate limiting
● Routing
- http://microservices.io/patterns/apigateway.html
- https://www.nginx.com/blog/building-microservic
es-using-an-api-gateway/
#MM17PL
API gateway
● Allow for easy service discovery
● Handle authentication, call rate limiting
● Routing
- http://microservices.io/patterns/apigateway.html
- https://www.nginx.com/blog/building-microservic
es-using-an-api-gateway/
#MM17PL
Output format
There are great solution for better
documenting, discovery and output
formatting.
However, standardising output across
a large set of APIs has it's pitfalls as
no implementation is ever perfect
#MM17PL
Summary
● By offloading tasks from Magento we keep
it fast and lightweight
● Storing data in a central place and making
it available via REST apis makes for easy
integration
● Headless can start by adding some of
those APIs to the existing back- or frontend
● Using lightweight php frameworks with
limited features makes for easy to develop
and fast applications
Code: https://github.com/sandermangel/headless-middleware
twitter.com/sandermangel
github.com/sandermangel
Integrating a ReactJS frontend in Magento 2
- Riccardo Tempesta
https://www.youtube.com/watch?v=ElZ5UtTXpzQ

More Related Content

PDF
Headless approach for offloading heavy tasks in Magento
PDF
Php & web server performace
PPTX
Website cloning using backtrack 5
PDF
Design a scalable site: Problem and solutions
PPTX
Debugging Microservices - key challenges and techniques - Microservices Odesa...
PDF
Extending The My Sql Data Landscape
PDF
RESTful with Drupal - in-s and out-s
PDF
SGCE 2015 REST APIs
Headless approach for offloading heavy tasks in Magento
Php & web server performace
Website cloning using backtrack 5
Design a scalable site: Problem and solutions
Debugging Microservices - key challenges and techniques - Microservices Odesa...
Extending The My Sql Data Landscape
RESTful with Drupal - in-s and out-s
SGCE 2015 REST APIs

What's hot (20)

PPTX
Hyperledger in AWS
PDF
Generic repository pattern with ASP.NET MVC and Entity Framework
PDF
Sinatra
PPT
Full stack JavaScript - the folly of choice
Β 
PDF
Zing Me Real Time Web Chat Architect
PPTX
Web Application Development using PHP and MySQL
PDF
Scaling Production Data across Microservices
PDF
Kafka meetup seattle 2019 mirus reliable, high performance replication for ap...
PDF
PHPCR - Standard Content Repository for PHP
PDF
Total cloud immersion
PPTX
NoSQL Database in .NET Apps
PPT
Introduction to JavaScript Full Stack
PPTX
Couch DB/PouchDB approach for hybrid mobile applications
PPTX
Evolution of java script libraries
PDF
Synchronization with CouchDB and PouchDB
PDF
Post-relational databases: What's wrong with web development? v3
PDF
JS Lab`16. АндрСй ΠšΠΎΠ»ΠΎΠ΄Π½ΠΈΡ†ΠΊΠΈΠΉ: "Π Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° REST сСрвисов Π½Π° SailsJS"
PPT
Drupalcamp Estonia - High Performance Sites
PPTX
Challenges of angular in production (Tasos Bekos) - GreeceJS #17
PPTX
Javascript Myths and its Evolution
Hyperledger in AWS
Generic repository pattern with ASP.NET MVC and Entity Framework
Sinatra
Full stack JavaScript - the folly of choice
Β 
Zing Me Real Time Web Chat Architect
Web Application Development using PHP and MySQL
Scaling Production Data across Microservices
Kafka meetup seattle 2019 mirus reliable, high performance replication for ap...
PHPCR - Standard Content Repository for PHP
Total cloud immersion
NoSQL Database in .NET Apps
Introduction to JavaScript Full Stack
Couch DB/PouchDB approach for hybrid mobile applications
Evolution of java script libraries
Synchronization with CouchDB and PouchDB
Post-relational databases: What's wrong with web development? v3
JS Lab`16. АндрСй ΠšΠΎΠ»ΠΎΠ΄Π½ΠΈΡ†ΠΊΠΈΠΉ: "Π Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° REST сСрвисов Π½Π° SailsJS"
Drupalcamp Estonia - High Performance Sites
Challenges of angular in production (Tasos Bekos) - GreeceJS #17
Javascript Myths and its Evolution
Ad

Similar to Headless Magento - Meet Magento Poland 2017 (20)

PPTX
Zendcon scaling magento
ODP
Deploying Perl apps on dotCloud
PDF
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
Β 
PPT
12 Ways to Improve Magento 2 Security and Performance
PDF
Scaling symfony apps
PDF
Scaling PHP apps
PDF
How Sysbee Manages Infrastructures and Provides Advanced Monitoring by Using ...
PDF
Serverless? How (not) to develop, deploy and operate serverless applications.
PPTX
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
PDF
Building a high-performance, scalable ML & NLP platform with Python, Sheer El...
PPTX
Silverstripe at scale - design & architecture for silverstripe applications
PDF
There is something about serverless
PPTX
Eko10 Workshop Opensource Database Auditing
PDF
Netflix Open Source Meetup Season 4 Episode 2
PDF
Magento Performance Optimization 101
PPTX
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
PDF
How to deploy & optimize eZ Publish
PDF
introduction to micro services
PPTX
Not my problem - Delegating responsibility to infrastructure
PDF
Modern tools for magento development
Zendcon scaling magento
Deploying Perl apps on dotCloud
PHP At 5000 Requests Per Second: Hootsuite’s Scaling Story
Β 
12 Ways to Improve Magento 2 Security and Performance
Scaling symfony apps
Scaling PHP apps
How Sysbee Manages Infrastructures and Provides Advanced Monitoring by Using ...
Serverless? How (not) to develop, deploy and operate serverless applications.
Building Microservices with .NET (speaker Anton Vasilenko, Binary Studio)
Building a high-performance, scalable ML & NLP platform with Python, Sheer El...
Silverstripe at scale - design & architecture for silverstripe applications
There is something about serverless
Eko10 Workshop Opensource Database Auditing
Netflix Open Source Meetup Season 4 Episode 2
Magento Performance Optimization 101
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
How to deploy & optimize eZ Publish
introduction to micro services
Not my problem - Delegating responsibility to infrastructure
Modern tools for magento development
Ad

More from Sander Mangel (9)

PDF
Shopware PWA - a technical overview of
PDF
Quality Assurance at every step of a Magento project
PDF
PWA 101, what you need to know about ShopwarePWA
PDF
Exploring pwa for shopware
PDF
Pwa, separating the features from the solutions
PDF
Van Magento 1 naar 2
PDF
Layered Landing
PDF
Scaling an eCommerce environment
PDF
Migrating to Magento 2 - As a Merchant
Shopware PWA - a technical overview of
Quality Assurance at every step of a Magento project
PWA 101, what you need to know about ShopwarePWA
Exploring pwa for shopware
Pwa, separating the features from the solutions
Van Magento 1 naar 2
Layered Landing
Scaling an eCommerce environment
Migrating to Magento 2 - As a Merchant

Recently uploaded (20)

PDF
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
PDF
Paper PDF World Game (s) Great Redesign.pdf
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PPTX
international classification of diseases ICD-10 review PPT.pptx
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPTX
innovation process that make everything different.pptx
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PDF
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
Β 
PDF
The Internet -By the Numbers, Sri Lanka Edition
Β 
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PDF
Introduction to the IoT system, how the IoT system works
PDF
Testing WebRTC applications at scale.pdf
PPTX
Introduction to Information and Communication Technology
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
How to Ensure Data Integrity During Shopify Migration_ Best Practices for Sec...
Paper PDF World Game (s) Great Redesign.pdf
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
international classification of diseases ICD-10 review PPT.pptx
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
Cloud-Scale Log Monitoring _ Datadog.pdf
Slides PDF The World Game (s) Eco Economic Epochs.pdf
innovation process that make everything different.pptx
SASE Traffic Flow - ZTNA Connector-1.pdf
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
RPKI Status Update, presented by Makito Lay at IDNOG 10
Β 
The Internet -By the Numbers, Sri Lanka Edition
Β 
Tenda Login Guide: Access Your Router in 5 Easy Steps
Slides PPTX World Game (s) Eco Economic Epochs.pptx
Introduction to the IoT system, how the IoT system works
Testing WebRTC applications at scale.pdf
Introduction to Information and Communication Technology
WebRTC in SignalWire - troubleshooting media negotiation
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...

Headless Magento - Meet Magento Poland 2017

  • 2. #MM17PL β€’ Magento developer β€’ Lead @ FitForMe β€’ Co-organiser MMNL, Unconf, MageStackDay, Meetups β€’ Avid community member twitter.com/sandermangel linkedin.com/in/sandermangel github.com/sandermangel
  • 4. #MM17PL What is headless architecture "Headless architecture means an application offering APIs that abstract away business logic for a multitude of clients to consistently and repeatedly execute the same tasks."
  • 10. #MM17PL Common integrations ● ERP ● Fulfillment ● Logs ● Email server ● ….
  • 11. #MM17PL Clients ● Magento backend ● Magento frontend ● Legacy system ● Dashboards ● Magento 2?
  • 12. #MM17PL So we take a different approach β€’ Magento will be a client & provide data β€’ Implement a basic data warehouse β€’ Which is fed by, and queried by various services separated by domains β€’ Isolate data & business logic per domain That allows for a smooth integration
  • 14. #MM17PL Leverage middleware for a stable environment storage source consumer server
  • 15. #MM17PL Leverage middleware for a stable environment storage source consumer server ● Normalize & combine data ● Offer stable APIs for clients ● Insulate from future changes
  • 18. #MM17PL Build on standardised libraries ● There is a solution for everything already out there ● Use popular libraries, preferably adhering to a PSR protocol ● Don't overcomplicate dependency injection ● Think carefully about what you need and spend time finding the best option [...] "require": { "php": ">=7.0", "slim/slim": "^3.1", "monolog/monolog": "^1.17", "cache/filesystem-adapter": "^0.4.0", "guzzlehttp/guzzle": "^6.2", "cache/array-adapter": "^0.5.0", "illuminate/database": "^5.4", "yadakhov/insert-on-duplicate-key": "^1.1", "symfony/console": "^3.3", "league/oauth1-client": "^1.7" } [...]
  • 19. #MM17PL Build on standardised libraries ● slimphp - Routing, DI ● monolog - gives insight in what the service does for monitoring and debugging ● cache/… - stores certain API calls, temporary data ● guzzle - offers a way to consume APIs over http ● illuminate/database - Laravel ORM (personal preference) ● Insert-on-duplicate.... - not a default option in illuminate/database but a must for me ● symfony/console - for cronjobs and commandline tasks ● league/oauth1-client - offers built in Magento 1 REST integration [...] "require": { "php": ">=7.0", "slim/slim": "^3.1", "monolog/monolog": "^1.17", "cache/filesystem-adapter": "^0.4.0", "guzzlehttp/guzzle": "^6.2", "cache/array-adapter": "^0.5.0", "illuminate/database": "^5.4", "yadakhov/insert-on-duplicate-key": "^1.1", "symfony/console": "^3.3", "league/oauth1-client": "^1.7" } [...]
  • 20. #MM17PL Build on standardised libraries ● SlimPHP project as basis ● One module in src some basic setup files needed by SlimPHP ● Keep it simple and self-contained
  • 21. #MM17PL Some learnings ● Single purpose ● It should feel overly simple ● Within the service, separate tasks ● Document, document, document ● Write integration tests for the API endpoints ● Log everything
  • 23. #MM17PL Exposing data ● Read only ● Easy to integrate ● Offer sorting, filtering, and a host of other query options ● Be very fast (d'oh) ● Standardized & easily scalable
  • 24. #MM17PL Standardizing? ● Output format and syntax ● Filtering and sorting ● Caching
  • 25. #MM17PL Enabling various integrations protected function _prepareCollection() { [...] try { $client = new Client(); $res = $client->request('GET', $helper->getBaseUrl(0) . 'quarantine?'. http_build_query([ 'limit' => $limit, 'page' => $page, 'sort' => $columnId, 'sortdir' => $dir, 'filters' => (array)$filter, '', '&')); } catch (Exception $error) { Mage::logException($error); $this->setCollection($collection); // set a dummy empty collection return $this; } $data = json_decode($res->getBody(), true); $lastPage = $data['to']; array_walk($data['data'], function($order) use (&$collection) { $collection->addItem( new Varien_Object( [ 'shipping_date' => $order['shipping_date'], 'order_reference' => $order['order_reference'], 'customer_reference' => $order['customer_reference'], 'updated_at' => $order['updated_at'], 'shipping_fullname' => "{$order['shipping_firstname']} {$order['shipping_middlename']} {$order['shipping_lastname']}", ] ) ); }); $collection->setCurPage($page); $collection->setLastPageNumber($lastPage); $collection->setSize($lastPage * $limit); $this->setCollection($collection); ● Magento 1 grids ● Ajax calls for smaller values ● Data imports ● Communication between services ● ...
  • 26. #MM17PL Caching ● How dynamic is dynamic content ● Cache is all about control ● Think of a strategy upfront
  • 27. #MM17PL Caching ● How dynamic is dynamic content ● Cache is all about control ● Think of a strategy upfront https://github.com/magespecialist/m2-M SP_APIEnhancer Magento 2 API enhancer
  • 29. #MM17PL Database ● MariaDB β—‹ Relational β—‹ Easy to work with β—‹ Offers good performance up to 1TB data ● Elastic β—‹ REST output β—‹ Plug and play β—‹ Advanced search
  • 31. #MM17PL Monolithic ● Dedicated / VPS server β—‹ Offered by all hosting companies β—‹ Easy to maintain β—‹ Does not scale easily β—‹ If one goes down... Distributed ● Instances on a cloud β—‹ Scales easily β—‹ Environments are isolated β—‹ Requires more knowledge β—‹ Can be harder to administrate
  • 32. #MM17PL API gateway ● Allow for easy service discovery ● Handle authentication, call rate limiting ● Routing - http://microservices.io/patterns/apigateway.html - https://www.nginx.com/blog/building-microservic es-using-an-api-gateway/
  • 33. #MM17PL API gateway ● Allow for easy service discovery ● Handle authentication, call rate limiting ● Routing - http://microservices.io/patterns/apigateway.html - https://www.nginx.com/blog/building-microservic es-using-an-api-gateway/
  • 34. #MM17PL Output format There are great solution for better documenting, discovery and output formatting. However, standardising output across a large set of APIs has it's pitfalls as no implementation is ever perfect
  • 35. #MM17PL Summary ● By offloading tasks from Magento we keep it fast and lightweight ● Storing data in a central place and making it available via REST apis makes for easy integration ● Headless can start by adding some of those APIs to the existing back- or frontend ● Using lightweight php frameworks with limited features makes for easy to develop and fast applications
  • 36. Code: https://github.com/sandermangel/headless-middleware twitter.com/sandermangel github.com/sandermangel Integrating a ReactJS frontend in Magento 2 - Riccardo Tempesta https://www.youtube.com/watch?v=ElZ5UtTXpzQ