We're transitioning Studio from Beta to Early Availability

Is GraphQL right for your project?

How GraphQL can be helpful for teams of different sizes.
Divine Orji

Written by Divine Orji

May 14, 2024
Is GraphQL right for your project?

Since its release, GraphQL has seen rapid adoption across various industries, with companies like GitHub, Shopify, Pinterest, and Hygraph leveraging its capabilities. Gartner® predicts that by 2025, GraphQL's usage in production will surge from less than 10% in 2021 to over 50%.

Despite its growing popularity, GraphQL is great for some projects while unsuitable for others. This article will examine how GraphQL can be helpful for teams of different sizes, from small startups to large corporations, and whether or not it’s right for you.

#GraphQL: A quick overview

Before we discuss whether GraphQL is right for your business, let’s examine its strength and the two ways you could adopt it.

GraphQL lets you specify the data fields you want and structure them in a single request. This gives you flexibility in defining the result data and eliminates the need to manage multiple endpoints, as all your data requests and responses are gotten through one endpoint.

undefined

GraphQL works best in specific use cases where a needed data type is well-defined and a low payload size is preferred, such as in mobile phones. It is inherently language-agnostic, with many implementations of its specification in programming languages such as Go, JavaScript, Ruby, and Python. Additionally, GraphQL supports mutations, which allow for data modification, and subscriptions, which provide real-time data updates.

There are two major architectural styles for building APIs with GraphQL:

  • Backend for Frontend (BFF)

  • Web services

Backend for Frontend

As the name implies, this architecture style entails building a separate GraphQL backend for each major user touchpoint. It works best for internal APIs, with many development teams initially wrapping their existing legacy code in a GraphQL BFF.

Backends for frontends

Web Services

API architectures that follow this design pattern are usually not tied to any specific user interface. Instead, they model and represent some business domain functionality.

Web Services

#Is GraphQL practical for small projects with limited resources?

Small projects typically have simple project requirements and a limited scope. For example, if you create a marketing website for your business, the user experience will generally remain the same irrespective of your users’ devices.

When developing an API to manage your website's blog, you could have a single GraphQL server that fetches content from your content repository, then structure each client’s GraphQL queries to select the specific data you need. This leads to a better developer experience and gives your project enough room to evolve.

Benefits of using GraphQL in a small project

  • GraphQL allows you to iterate through different ideas and develop scalable solutions for your project. You can follow best practices and experiment without worrying about breaking your product or affecting users.
  • GraphQL gives you finely controlled access to your database or content repository, allowing you to fetch just enough data for each client-side view.

Challenges of using GraphQL in a small project

While GraphQL is nice to have in a small project, it can pose some challenges. Here’s an overview of the potential challenges and how to overcome them:

  • Setting up and maintaining a GraphQL API architecture requires more time and effort than working with a traditional REST API, especially if you are unfamiliar with the technology. This delays your project’s time to market. Thankfully, you won’t have such time pressure if you develop with Hygraph. Hygraph is a GraphQL-native headless CMS that abstracts away many time-consuming tasks through a fully functional GraphQL API and an intuitive dashboard.
  • Implementing caching in GraphQL is often tricky. In traditional REST APIs, the GET method has a well-defined caching behavior that browsers, content delivery networks (CDNs), proxies, and web servers can leverage. GraphQL uses POST by default, which prevents the full use of HTTP caching mechanisms. Effective caching strategies—such as implementing the popular Apollo GraphQL client—could solve this problem.
  • Resolving complex queries for small data sets could introduce latency, potentially leading to a suboptimal user experience.

#How does GraphQL accommodate the needs of medium-sized teams/projects?

GraphQL stands out when aggregating multiple data sources into a single endpoint. This feature is especially beneficial in medium-sized projects with separate backend and frontend teams, as everyone can refer to a standard schema with complete type definitions and up-to-date API documentation.

GraphQL aggregating data from multiple places into a single API endpoint

Benefits of using GraphQL in a medium-sized project

Here are some benefits of working with GraphQL on a medium-sized project:

  • GraphQL enables developers to define a clear schema as a contract between teams, streamlining development and reducing misunderstandings.

  • Once the GraphQL schema is defined and mock data is introduced, frontend and backend teams can work in parallel. This accelerates development as frontend developers can use mock data for UI development while backend developers focus on building server-side logic.

  • GraphQL can automatically generate comprehensive API documentation based on your schema and data types, reducing the overhead of maintaining separate documentation resources.

Challenges of using GraphQL in a medium-sized project

All the benefits stated so far are great, but here are some challenges developers might face with GraphQL in medium-sized projects:

  • GraphQL has a steep learning curve for teams unfamiliar with the technology, and transitioning to GraphQL requires investment in training and upskilling. If some of your team members deeply understand GraphQL, encourage open dialogue and allow them to share lessons learned from experimenting with GraphQL to enhance team cohesion and collective expertise.
  • If your project has a strict timeline, implementing GraphQL manually may take a lot of time and effort, which can be challenging to accommodate. In this case, you can leverage GraphQL tools such as Hygraph, Hasura, or Postgraphile, which streamline the process of generating GraphQL APIs. Hygraph allows developers to quickly define data models and generate GraphQL schemas, leading to massive gains in productivity.
  • GraphQL’s ability to combine data from different sources means that if your project needs to get data and its related details from multiple sources, you will write nested queries, which GraphQL will resolve separately, leading to the “n + 1” problem. This could cause performance issues. To solve this, consider implementing GraphQL’s dataloader library to batch your requests.

#Is GraphQL scalable enough to handle the demands of enterprise-level projects?

Large-scale projects are usually riddled with a lot of complexity, serving a diverse group of users and orchestrating data across many APIs, microservices, and legacy systems. For example, Coursera — an online education platform — has hundreds of APIs implemented across dozens of services by various engineering teams.

Before it adopted GraphQL, Coursera’s client engineers faced many challenges while using these APIs, especially around discoverability and data assembly from various services. To address these challenges, Coursera built a dynamic assembly layer that unified their distributed APIs into one GraphQL endpoint and corresponding schema, allowing clients to access data from across Coursera’s various services in a single query.

Coursera’s GraphQL-powered architecture

Other enterprise-level companies that have migrated to GraphQL include:

  • Netflix — they built a federated GraphQL gateway that connects to smaller GraphQL APIs, such as their Video API service and Netflix Studio API.

  • Adobe Experience Platform — they leveraged GraphQL to manage their internal and external microservices.

Benefits of using GraphQL in an enterprise-level project

Here are some reasons why GraphQL is an excellent choice for enterprise-level projects:

  • GraphQL seamlessly collects data from different sources to provide a consistent experience across multiple touchpoints. You can combine numerous sub-graphs into one super-graph through schema stitching or federation.

  • GraphQL can give you a high-level overview of your APIs and microservices to identify redundant data types and schemas, allowing you to optimize your project and deliver data to your users more efficiently.

Challenges of using GraphQL in an enterprise-level project

Although GraphQL can be a powerful tool to streamline your processes, here are some challenges you might face while working with GraphQL in an enterprise-level project:

  • If your project has stringent performance requirements or involves interfacing with legacy systems that do not natively support GraphQL, you need to pay extra attention to your integration efforts and do it gradually. Large-scale projects can take an average of six months to integrate GraphQL with their existing systems and often need to develop custom implementations that perfectly fit their requirements.

    While working with Hygraph, you can leverage its Remote Sources feature. This feature allows you to connect any external API to your Hygraph project, effectively integrating external data as if it were part of your original schema. This approach will ensure compatibility with performance-critical components while minimizing disruptions to ongoing operations.

  • Adopting GraphQL could pose some security challenges that break existing legacy systems, such as shipping a new feature that causes an unexpected table scan. To mitigate these security concerns, consider employing field-based permissions and query depth limits alongside classic features like rate limiting and usage quotas. Additional security considerations include thoroughly testing, monitoring, and performing regular security audits to ensure a smooth transition and minimize the risk of unexpected issues.

#GraphQL and you

GraphQL‘s precise data fetching capabilities and support for various data sources make it appealing for projects requiring efficient data retrieval, real-time updates, and complex data interactions.

Nonetheless, you should consider your business needs and assess your team’s ability to overcome the initial learning curve and the potential need for custom solutions to address caching and query performance. Also, consider how your technology might change and whether investing in GraphQL expertise makes sense for your long-term goals.

Tools like Hygraph can significantly simplify these challenges and maximize the benefits of GraphQL for your project or business. For more insights on using GraphQL in your projects, check out Hygraph’s recent GraphQL survey.

The GraphQL Report 2024

Statistics and best practices from prominent GraphQL users.

Check out the report

Blog Author

Divine Orji

Divine Orji

Technical Writer

Divine is a web engineer and content creator specializing in frontend, JAMstack, and serverless technologies. In his free time, he enjoys a good game of basketball, chess, or Call of Duty.

Share with others

Sign up for our newsletter!

Be the first to know about releases and industry news and insights.