Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Headless approach for offloading heavy tasks in Magento

846 views

Published on

a use case for leveraging a headless approach to handle heavy tasks outside of Magento

Published in: Internet
  • Very nice tips on this. In case you need help on any kind of academic writing visit our website ⇒ www.HelpWriting.net ⇐ and place your order
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hey guys! Who wants to chat with me? More photos with me here 👉 http://www.bit.ly/katekoxx
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Headless approach for offloading heavy tasks in Magento

  1. 1. Headless approach With Magento
  2. 2. Sander Mangel - Magento Developer - Lead @ FitForMe - Co-organiser MMNL, Unconf, MageStackDay, Meetups - Avid community member twitter.com/sandermangel linkedin.com/in/sandermangel github.com/sandermangel
  3. 3. Welcome to 2017 welcome to the future...
  4. 4. Read more http://bit.ly/2qo6XBc http://bit.ly/1Wku9c0 http://bit.ly/2rtVIas http://bit.ly/2qrkQKP http://bit.ly/2hyM6Dy Source: https://laughingsquid.com/victorian-headless-portrait-photography/
  5. 5. What is headless architecture Source: https://pantheon.io/blog/headless-websites-whats-big-deal-decoupled-architecture
  6. 6. 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."
  7. 7. Putting this into practice
  8. 8. Clients ● Fulfillment dashboard ● Magento backend ● Magento frontend ● ...
  9. 9. ● 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 So we take a different approach
  10. 10. Leverage middleware for a stable environment storage source consumer server
  11. 11. Leverage middleware for a stable environment ● Normalize & combine data ● Offer stable APIs for clients ● Insulate from future changes storage source consumer server
  12. 12. Source: https://www.linkedin.com/pulse/business-analysisits-rocket-science-paul-lumsden
  13. 13. http://matrix.wikia.com/wiki/Matrix
  14. 14. Processing incoming data
  15. 15. { "name": "ffm/headless-middleware", "description": "Basic middleware for a remote API call", "license": "MIT", "authors": [], "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" }, "require-dev": { "phpunit/phpunit": "^6.0", "roave/security-advisories": "dev-master", "friendsofphp/php-cs-fixer": "^2.1", "phpmd/phpmd": "^2.6", "phpro/grumphp": "^0.11.5", "phpspec/phpspec": "^3.3", "phpstan/phpstan": "^0.6.4", "nikic/php-parser": "^3.0" }, "autoload": { "psr-4": { "Ffm": "src/" } }, "autoload-dev": { "psr-4": { "Tests": "tests/" } }, "scripts": { "start": "php -S 0.0.0.0:8080 -t public public/index.php", "test": "grumphp run" } } Source: https://github.com/sandermangel/headless-middleware
  16. 16. ● 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 Build on standardised libraries [...] "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" } [...]
  17. 17. ● 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 Everything has a purpose [...] "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" } [...]
  18. 18. ● SlimPHP project as basis ● One module in src some basic setup files needed by SlimPHP ● Keep it simple and self-contained Structure
  19. 19. Storage
  20. 20. ● SQL based / relational ● Offer good performance up to 1TB data ● Easy to integrate ● Be the best solution for the upcoming year Choice of database
  21. 21. Exposing data
  22. 22. ● Read only ● Offer sorting, filtering, and a host of other query options ● Be very fast (d'oh) ● Be standardised & easily scalable Making data available for clients Source: https://www.archaeological.org/fieldwork/afob/10374#
  23. 23. Search Leveraging the built in REST api of Elastic we had a ready to go layer. We decided to leave that 'as is' and deal with changes in data structure or due to a version upgrade as they come Each search result has, next to the record data, a reference to a UID from the SQL database to retrieve the full data set.
  24. 24. Datasets ● As stated the API server is read only ● For each dataset (a table in a database) there is one endpoint ● Simple filter methods on one or more fields ● Each returned dataset has reference UIDs to other records that are tied to this item. So for customers this can be orders or addresses ● Multiple API calls over large or joined datasets
  25. 25. Summary
  26. 26. ● 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 Summary Source: https://www.archaeological.org/fieldwork/afob/10374#
  27. 27. https://joind.in/talk/8365d Code: https://github.com/sandermangel/headl ess-middleware twitter.com/sandermangel github.com/sandermangel

×