What is GraphQL?
GraphQL is an API specification developed by Facebook in 2012 to address specifically iOS and Android application performance and reliability problems created by the complexity of Facebook’s mobile apps. When GraphQL was developed, mobile bandwidth was still a significant point of frustration for mobile app developers. GraphQL provided a way to address these low-bandwidth performance needs; it allowed for front end developers to fetch very discrete pieces of data instead of returning more complete results.
How can GraphQL be beneficial for eCommerce platforms and eCommerce experiences?
In the eCommerce world, businesses strive to deliver the most relevant experiences for each of their users and shoppers. Many companies have selected “headless” or API first approaches because it allows for greater flexibility in creating front end experiences, as compared to more monolithic eCommerce platforms that tightly couple the backend and frontends. Because headless commerce places emphasis on the data, GraphQL allows front ends to retrieve just what they need. This allows businesses to build more unique experiences. There are several benefits provided by the GraphQL:
Simplified Front-end Development
It is easy for developers to iterate their frontend applications quickly because the GraphQL layer is responsible for providing up-to-date data. The developers don’t have to spend time chasing down the API, which has the most up-to-date data. This helps to accelerate time-to-market for new experiences.
GraphQL allows to fetch only data that is needed by the application by making parallel requests to different systems within an application ecosystem. This allows to minimize over- and under- fetching, which improves network performance making a positive impact on customer experience.
Less code to maintain
With GraphQL, frontend applications do not need to maintain the logic required to call different systems and then reconcile the data. GraphQL also eliminates the need for backends for frontends. Altogether, this reduces code duplication and allows to eliminate channel siloes that can lead to inconsistent customer experience.
Challenges Associated with GraphQL
As with any technology, there are certain drawbacks related to GrapQL adoption and usage:
Additional Maintenance Effort
GrpahQL is an additional layer that needs to be maintained separately with its architecture, development, and operations.
Potential Conflicts Between Different GraphQL Layers
In a larger organization, different teams can create multiple GrpahQL layers, each with its schema. This can result in increased architectural complexity making a negative impact on time-to-market.
When is GraphQL the right choice?
Much like its intentions at the time of inception, GraphQL is ideal for situations where developers are trying to minimize the amount of data being retrieved by their frontend application. For example, if you are trying to make an experience available to users in very rural areas where their internet bandwidth is constrained, GraphQL will aid in reaching those customers. Additionally, GraphQL allows for each application to retrieve only the discrete data that it needs to perform its function, making each application lightweight.
When is GraphQL not the right choice?
In the world of performance and efficiencies, GraphQL has a lot of promise. Still, it is far from being a silver bullet, and much like REST APIs, developers need to adhere to best practices—some even more so than with REST APIs—to make sure the approach lives up to the hype. For example, just because the data is provided to the front end is more streamlined doesn’t mean the retrieval of that data is more streamlined. If multiple resources and multiple fields need to be accessed, they’ll need to be accessed via REST API or GraphQL. Additionally, due to the nature of GraphQL, it can become challenging to understand SaaS platform consumption, compared to RESTful applications measure resource requests. Consumers of SaaS application using GraphQL can unexpectedly hit their API rate limits, seeing their performance degrade or their costs increase. Lastly, there’s a missing piece to the puzzle: how can you execute any business condition or logic that is unique to your business that isn’t found in the out of the box commerce functionality of your eCommerce platform? With GraphQL, all of this logic will need to reside in the frontend application. With multiple frontend applications, businesses will see an explosion of custom business logic either residing in the frontend application or a backend for frontend (BFF), both of which introduce maintenance complexity akin to that of a monolith.
How Elastic Path Commerce Cloud addresses the same challenges
When developing the Elastic Path Commerce Cloud, we have designed the APIs with the developers in mind. Our goals were to provide RESTful APIs which are accessible for the developers to learn and use while eliminating complexity and providing maximum flexibility.
Simplified Front-end Development
Elastic Path Commerce Cloud provides cleanly-designed APIs with only 166 actions that expose well-defined packaged business capabilities to the developers. This accelerates time-to-market for new frontend applications and enables rapid iterations.
The clean and minimalistic design allows to optimize data fetching to improve network performance and deliver superior customer experience.
Less Code to Maintain
Well-designed packaged business capabilities exposed through APIs eliminate the need to reconcile the data across multiple APIs as there is only one single source of truth with one API. This allows to reduce unnecessary code crawling into the frontend.
Explore how Elastic Path Commerce Cloud relies on the well-designed API to deliver Composable Commerce.