Microservices with GraphQL plus Adoption checklist.

Nitin Mahajan
Dec 31, 2019 · 5 min read

Evolution of the API

GraphQL is the next stage in the progression of distributed application communication for data and application logic. Over the last several decades, with the invention of the internet, advancement in the network, compute, memory & cloud computing, application communication has evolved from Binary Protocol to HTTP Text-based protocol(SOAP, Rest). GraphQL commences the next stage of this evolution to match the pace of innovation triggered by mobile, eCommerce, social media, and IoT devices.

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.” — GraphQL.org

GraphQL Landscape is growing.

GraphQL adoption has expedited in the last five years, and it is manifested by the

  • Thriving community & meetups
  • Enhanced library support in a plethora of programming languages, to support various platforms
  • The rise in GraphQL services (Apollo, AWS AppSync) and GraphQL first databases like DGraph and Hasura to lessen the adoption barrier
  • Expanding GraphQL Foundation and Specification for Microservice-based GraphQL (Apollo Federation)
  • The risen attendance at the GraphQL Summit hosted by Apollo
  • Steady growth for text “GraphQL” in google search.
Google Trends Search Comparison “GraphQL” & “Rest API” in the last five years.

Refer Awesome-graph list of GraphQL libraries by chentuslin.

Will GraphQL replace Rest?

There is no unidimensional solution, and Rest API will be one of the dimensions for data service along with GraphQL. GraphQL is a great choice when customers need a single, customizable service to support a lot of not so well defined needs with flexibility to pick and choose data from the domain model. Rest APIs style services are a better choice when the customer needs an optimized service for a well defined complicated use-case. Refer Is GraphQL a great choice for East-West Service Communication by Marc-André Giroux for details?


Industry Adoption

Over 1100 people attended Apollo hosted 2019 GraphQL Summit from a wide range of companies that are at different stages of their GraphQL Journey. Conde Nast, The New York Times, Intuit & Zillow have been early adopters of GraphQL, serving considerable Production GraphQL traffic, not accounting for Facebook, who wrote the GraphQL Specification and the first implementation. Airbnb is taking an incremental migration approach and shifting its entire stack to Apollo & GraphQL using React Hooks replacing Redux & Rest. What I learned at GraphQL Summit by Khalil Stemmler provides small writeups and links to some of the session videos.

What are the GraphQL Adoption Patterns?

GraphQL schema is a model of the domain data and how different business entities are related to each other. GraphQL gets its power from its ability to expose a unified data interface between client and server. Companies adopt one or more of the following Architectural patterns.

  • Monolith Architecture. A monolith GraphQL server is a smooth development path. A single central server connects to multiple downstream databases or rest services, to expose a unified data graph. This pattern is ideal when a small development team is responsible for building an entire domain Graph.
  • Custom schema stitching solution. Smaller independent teams build microservice GraphQL endpoints and expose a Unified Graph using homegrown custom schema stitching.
  • Apollo schema stitching(deprecated)
  • Standalone GraphQL. Individual teams adopt GraphQL over Rest API without the intent of building a Unified Data Graph.

Microservices and GraphQL

How to do Microservices with GraphQL?

During this decade, the Software Architecture has seen a progressive transformation from Monolith to Microservices architecture. Growing appetite for faster experimentation and deployment has fueled the growth of Microservices Architecture. This growth leads to significant development in the Rest APIs, API Management Tools, Messaging Systems, Containers & Serverless Frameworks. Developing a Monolith GraphQL will surface the challenges of communication and reduction in the velocity of feature development. Federation Specification is Apollo’s solution to enable Microservice development in the GraphQL ecosystem.

Apollo Federation is an architecture for composing multiple GraphQL services into a single graph and it is based on a declarative composition programming model that allows proper separation of concerns. — Apollo

“A revolutionary architecture for building a distributed graph” by James Baxley III

Apollo Federation facilitates connecting multiple services using the following techniques.

  • Type Reference declaratively reference types defined in different schema analogous to Object Composition.
  • Type Extension extends a type defined in a different schema analogous to Inheritance.

A set of Federated Services and a Gateway is required to implement Apollo Federation.

  • Federated services are Microservice GraphQL APIs to enable data connection by using type reference or type extension techniques.
  • Gateway is to compose a Unified Data Graph and execute federated queries.

Apollo Server implements the Federation and provides two open-source libraries apollo/federation & apollo/gateway.

Full Stack or Server Side?

Depending on the state of the Technology stack & development resources following approaches are being adopted for migration to GraphQL.

Server-side Only

  • Incrementally substitute existing Rest API to GraphQL with the least changes to the client-side technologies. There are two basic server-side implementation patterns.
  • GraphQL using existing Rest Service Layer.
  • GraphQL directly using the Origin database and prevent the overhead of maintaining multiple data transformation layers.

Full Stack with GraphQL backend

GraphQL adopters using the full-stack approach to augment the development velocity & user experience by enhanced performance. Newer and modern technology solutions are introduced in the entire stack to achieve the following benefits.

Productivity Gains

  • Typescript adoption brings Type Safety, which leads to a reduction in bugs.
  • Reduction in boilerplate code required to build your client-side state management.

Performance Gains

Microservices GraphQL Adoption Checklist

Any new technology adoption arises inherent complexity and uncertainties. Complexities of the service to service communication and heterogeneous architecture. Risks of widespread late failure detection and lost effort. Develop a checklist to alleviate these risks and plan for the complexities. Extend this starter checklist.

Architecture & Design

Operational aspects for Microservices GraphQL

  • How to do Continuous Integration & Deployment with Microservices GraphQL?
  • Schema Validation
  • Logging & Monitor Graph Usage
  • Application Performance Monitoring Tool
  • Versioning and Backward Incompatible Changes

Performance

  • You can’t go far without Caching.
  • N+1 Problem
  • Persisted Queries for saving bandwidth and restricted queries.
  • Dataloader for batching Queries
  • Graph Depth Limit
  • Optimized Database Queries using AST(Abstract Syntax Tree)
  • Pagination
  • Filtering & Sorting Practices

List of Managed GraphQL Services

With the rise in the adoption of GraphQL, there is an uptick in Managed Services and GraphQL first databases.

Managed GraphQL

  • Apollo Graph Manager is a cloud service that helps you manage, validate, and secure your organization’s data graph.
  • AWS Appsync is an enterprise-level, fully managed GraphQL service with real-time data synchronization and offline programming features.
  • 8Base Build and run cloud-based enterprise applications faster using JavaScript, GraphQL, and 8base.
  • GraphCMS is a GraphQL based Headless Content Management System.

Databases

  • Fauna -The database built for serverless, featuring native GraphQL
  • Neo4j & GRAND stack(GraphQL, React, Apollo & Neo4j)
  • Hasura GraphQL Engine lets you set up a GraphQL server and event triggers over a Postgres database in minutes
  • Dgraph — Graph database with GraphQL as the query language
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade