Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Netflix Embraces GraphQL Microservices for Rapid Application Development

Netflix Embraces GraphQL Microservices for Rapid Application Development

This item in japanese

Netflix engineering recently published a blog post detailing how Netflix embraced GraphQL microservices for rapid application development. In this post, Dane Avilla, a senior software engineer at Netflix, describes their key learnings in the process and how GraphQL lends itself well for proof-of-concept development.

Avilla notes two approaches for creating GraphQL schemas. One method uses GraphQL as a single entry point for navigating an entire organization's structured data ("One Graph to Rule Them All"). Another option is to use GraphQL only as an enriched API specification for building CRUD applications. Netflix used the latter approach for its rapid application development effort:

The successful implementation of an internal app over 4–6 weeks with limited initial requirements and an ad hoc distributed team (with no previous history of collaboration) raised a large amount of interest throughout the Netflix Studio. Other teams within Netflix are finding the GraphQL microservices approach (...) to be a viable solution for internal CRUD tools that would historically have used REST.

To more easily implement these microservices, Netflix engineers standardized on a custom Docker image built on top of Graphile. Graphile is a set of tools to rapidly build robust, performant, and extensible applications centered around PostgreSQL and GraphQL. Using Graphile allowed Netflix engineers to expose a PostgreSQL data set as an API quickly. Avilla describes:

Using Docker, we defined a lightweight, stand-alone container that allowed us to package the Graphile library and its supporting code into a self-contained bundle that any team can use at Netflix with no additional coding required. Simply pull down the defined Docker base image and run it with the appropriate database connection string. This approach proved to be very successful and yielded several insights into the use of Graphile.

One insight is to use database views as an "API layer." Using views allows preserving flexibility to allow modifying tables without changing an existing GraphQL schema. Also, views could do basic formatting for fields. Another insight is to use PostgreSQL composite types. By default, Graphile exposes various non-scalar types as a GraphQL JSON type. Using PostgreSQL's composite types and Graphile's support for annotations in comments allows generating strongly typed GraphQL schemas, which, in turn, accelerate application development even further.

A third insight revolves around the development process. According to Avilla, they saw that initially allowing the client "full access" to the auto-generated GraphQL queries and mutations allowed for greater development flexibility when the UI's behavior was still not finalized. Later on, when the team solidified the required API, they could lock down the schema and expose only the required functionality. Also, this phase could allow them to optimize the remaining DB queries using indexes, denormalization, clustering, etc.

Netflix engineers do not currently support adding custom queries and mutations to a Graphile-generated schema. However, they could achieve this using Graphile's makeExtendSchemaPlugin, which allows merging custom types, queries, and mutations into the schema generated by Graphile.

GraphQL is an open-source data query and manipulation language for APIs and a runtime for fulfilling queries with existing data. GraphQL was developed internally by Facebook in 2012 before being publicly released in 2015. It is gaining traction in recent years as an alternative to more traditional REST APIs. Its main premise is to allow increased flexibility for frontend developers, who can query the exact dataset they need for a particular screen in a single operation.

Rate this Article