As part of building out an E-Commerence website for Company X, integrations into other systems within the company are required. These integrations include Ordering and Payment services. The APIs for these services are exposed via Rest and SOAP web services.
There are different approaches suggested by developers/engineers as to how we should write these integrations (as listed below). What is the 'industry standard' when integrating into other services from magento 2?
The following suggestions were provided by different developers/engineers working on this E-Commerence website:
- Create a separate PHP client library for Ordering and Payment services, and import these libraries within Magento. As the customers place orders and make payments in Magento, use these client libraries to communicate with relevant services. The business logic will reside within Magento.
- Create a standalone service independent of Magento, which implements the Ordering and Payment services API and exposes its own combined Rest API. As the customers place orders and make payments in Magento, take the in coming request objects, convert them to json, and forward json payload to this standalone service. This standalone service will extract the data from json payload and make calls to Ordering and Payment services. It will also have business logic and make API calls back into Magento for anything that needs to be updated.
Reasons for providing #2 solution are listed below and reasons against or reasons that nullify #2 are added as bullet points:
- Portability - Install NodeJS or Java and run standalone servers anywhere
- Magento 2 uses PHP 7 and is independent of operating system. The PHP client libraries will also be portable.
- Enterprise Solution - any group within the company can makes calls to the standalone service and use it for their purpose
- Considering the standalone services make API calls back to Magento API, other groups within the company cannot use the standalone service since it will effect this E-Commerence website.
- It does not make sense to scale the standalone services without scaling Magento since Magento will be forwarding calling to these services (source of the load). In order to handle increased load, both Magento and standalone services will need to be scaled together.
- Separation of Concern
- Using PHP client library, we can keep communication with Ordering and Payment services in the 'services' layer.
- The business logic should remain within Magento.
- Backward Compatibility - Upgrading to newer version of Magento will not affect communication with Ordering and Payment service.
- Creating PHP client libraries for Ordering and Payment services will be independent from Magento and relies on PHP 7, not Magento.
- If newer version of Magento changes the object structure for ordering or payments, the standalone services will not be able to parse new structure without an update.
- Testing - Standalone services can be tested without Magento
- True, but is it necessary to have the standalone services at all?