GraphQL at PayPal: An Adoption Story

Shruti Kapoor
Aug 31 · 12 min read
Photo by Parrish Freeman on Unsplash

State of GraphQL today

We started our GraphQL adoption journey by building our checkout experience. We saw tremendous benefits in adopting GraphQL when our checkout app built with GraphQL became our guiding light.We built more apps, provided infrastructure support, launched a public GraphQL API, and provided trainings and learning materials across the company. We also set up a standards body, provided a GraphQL tools fanny pack, and built sample apps to help teams get started.

Today, GraphQL is being used by several production apps across PayPal. It is now a default pattern to use GraphQL for building new UI apps. Many existing apps are in the process of migrating to GraphQL. GraphQL is being used by common platforms such as Identity, Payments, and Compliance to provide a consistent experience across all PayPal products. Our API developers have started using GraphQL to build APIs. Braintree released its public GraphQL API.

With the help of GraphQL, we have been able to bridge the gap between a backend for frontend (BFF) apps and backend API capabilities since GraphQL can work as an orchestration layer for downstream APIs, perform functions of the backend API, and act as the API interface for UI apps. We are moving towards a unified GraphQL Gateway to support one graph through the company.

Why did PayPal need GraphQL?

When we chose GraphQL, we were looking for a technology to help us solve the following problems:

  • Overfetched data: Our REST (representational state transfer) APIs sent a part of the response a client needs and some extraneous data. Since the server in a REST API dictates the shape of data, our UI teams spent a lot of time filtering and parsing data on client side, often using libraries such as Redux to format and store data. With GraphQL, clients are able to ask for a set of fields, and get exactly those fields back, thereby removing the need to do data formatting and reshaping on the client side. This greatly increased the time it took to ship UI features and make our apps lightweight.
Photo by drmakete lab on Unsplash

How did we begin adopting GraphQL?

PayPal has an extensive suite of REST APIs that power the core functionality of apps and sits very close to the database. GraphQL is used as an orchestration layer in our apps. It sits between the frontend UI app and backend API layer acting as a backend for frontend (BFF). This means that a UI app talks to a GraphQL endpoint, and the endpoint figures out which downstream service to call. New features can be built directly within the GraphQL layer. Some teams have chosen to use GraphQL as a pure orchestration layer, while other teams use the GraphQL layer as a business logic layer.

The Checkout team was the first to pioneer the adoption of GraphQL. Mark Stuart shared our journey of adopting GraphQL in the Checkout app in this blog post in detail. When the Checkout team showcased their app, the benefits of orchestration and improvement in developer productivity really clicked with our engineering teams. This sparked interest across PayPal, and teams started developing demo apps to utilize GraphQL for their apps.

It was the new shiny thing. Everybody got excited about the hype, but what stuck out most for the teams was how easy it was to orchestrate downstream APIs and create a unified experience for clients. With GraphQL, all of the downstream complexity could be hidden and clients wouldn’t have to worry about figuring out which piece connects where. It made for a more coherent experience for clients.

Teams started building products, presented them in our tech showcase, and got other people excited too. Soon, everybody was curious. Once we got leadership on board, we were really able to take off.

How did we scale adoption of GraphQL?

As we started scaling our GraphQL adoption, we realized that every app was trying to solve its own GraphQL problems. Often, teams were solving the same problem and reinventing the wheel. We realized there was a need to unify these efforts under one umbrella and hence, we established a standards body. We provided support for tooling, front-tier and mid tier sample apps, error handling techniques, and learning resources.

We built tooling to help support GraphQL adoption:

  • We established GraphQL standards for defining GraphQL APIs internally. These standards define naming conventions, GraphQL types, header standards, directive standards and error handling techniques.

Having a standards body and tooling was great and helped teams set up their graphs faster. However, we noticed that some problems persisted. We noticed that the individual graphs were deviating from the correct way of doing things, such as authentication. We lost a little control of auth rails in individual graphs. We also realized that having multiple graphs makes schema sharing harder. We wanted to provide a centralized point of entry, govern schemas together, model the data in a global way, and provide a way to reuse types. This is what led us to build a one graph gateway using Apollo Federation.

What advantages are we seeing with GraphQL adoption?

The fact that we were able to orchestrate adjacencies and convert the identity of a PayPal subsidiary into a PayPal account is a matter of pride. We initially launched our Braintree API and we were able to get it done really quickly. Time to ship was faster and GraphQL was able to report what piece of schema went where. The main advantages we have been seeing with GraphQL are:

  • Developer productivity: Tools like GraphiQL and Playground are really great to play around with the API and explore documentation at the same time without having to check out any additional tools such as Postman.

What challenges are we facing?

Photo by Possessed Photography on Unsplash

We are still working to create a standardized approach to challenges in GraphQL technology such as error handling, authentication, file handling, and batch processing.

Teams are independently building their own graphs, which leads to duplicated efforts, different ways of handling and surfacing errors, and deviation from the standard way of handling authentication.

We are still working on incorporating internal tools. Since a lot of these tools rely on the status code of the API response — 200s, 400s, 500s, it has become harder for us to map GraphQL responses (all 200s) to these tools.

GraphQL at PayPal grew tremendously fast. Many teams built their own way of handling errors, solving GraphQL problems, and instrumenting to the internal logging system. After it grew, we provided support by adding internal plugins and middleware to normalize error handling, instrumentation, and reducing internal network chattiness, but we wished we built support sooner.

Our adoption of one graph approach has been slow. Teams have to change a lot of behavior of how they are currently making apps in order to get on the one graph, adding process and time to deliver. The challenge has been to tell people that now we have rules to add to the graph but keep them motivated to use one graph. Joey Nenni gave a talk at JS @ PayPal and talked about our approach to one graph and a potential solution to overcome this challenge.

How did we convince our engineering and leadership teams?

Our frontend developers saw the benefits of using GraphQL immediately. It was also easy to convince backend developers who were working on UI teams. They understood the power of orchestrating with GraphQL. For core platform APIs teams, we haven’t fully convinced them yet. When we introduced GraphQL concepts, sometimes we were told that REST can do that too. Yes it can, we can replicate what GraphQL does with REST as well, but then at the end, we are just recreating GraphQL. We haven’t gotten a full buy-in from developers across the stack, but our REST and GraphQL APIs can live together. We learned to not boil the ocean.

Photo by Christoffer Engström on Unsplash

To convince our leadership, we knew that it wasn’t enough to focus on the performance of GraphQL APIs. The performance of an orchestrated GraphQL API depends on the APIs it consumes. A GraphQL API is only as fast as its slowest downstream API. Instead, we focused on developer productivity and time to ship a product. We demonstrated that using GraphQL can help build products faster, improve team collaboration, and make it easier to explore documentation. When we introduced GraphiQL and Playground tools to our teams, they immediately saw the benefit in having a GraphQL endpoint and playground tool to fire off requests while exploring the documentation.

We demonstrated how GraphQL helps improve the productivity of internal and external developers, how GraphQL helps reduce the time to ship features, and how we were able to hide complexity from our clients. With GraphQL, we didn’t have to work on multiple SDKs for each platform. We built the API once, and we were done. Without GraphQL, we had no idea which fields were being used by the merchants and which endpoints were called. We did not have instrumentation on KPIs such as first integration to production. With GraphQL, we were able to demonstrate our learnings, instrumentations and field level insights.

How can you start adoption at your own company?

  1. When first speculating whether GraphQL is the right technology, it is helpful to build a demo app that can demonstrate how GraphQL can fit in your enterprise architecture.

Big thank you

Photo by Wilhelm Gunkel on Unsplash

This article has been made possible by the contributions of our valuable team members. Thank you to Mark Stuart, Joey Nenni, Walmik Deshpande and Miriam Goldberg for agreeing to be interviewed and sharing their experiences. A big thank you to Mark Stuart for leading the adoption of GraphQL in PayPal, motivating me to share my GraphQL experience, and being an inspiration to our developer community.

Come join us!

Are you interested in helping out with our GraphQL journey? We are hiring across the board!

The PayPal Technology Blog

The PayPal Technology Blog

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Start a blog