Building a Highly Scalable Cloud API Gateway

Rate this content
Bookmark

One of the benefits of GraphQL is that it enables a single entry point into any number of back end service or databases. More and more companies are adopting cloud technologies – leading to more jobs, more money, and more opportunities in cloud computing. When GraphQL is integrated with a cloud back end, enabling secure and direct access to dozens of databases and managed services, the limitations are endless. The problem is often that building out these implementations from scratch, and getting them right, is hard. In this talk, I’ll show how you can build cloud-based GraphQL back ends connecting to multiple databases (SQL and NoSQL), serverless functions, machine learning services, and microservices using TypeScript, AppSync, and AWS CDK – and do so in fewer lines of code than you’d expect. We’ll also look at how subscriptions, security, caching, and authentication are all handled, enabling you to build APIs that can simultaneously connect to tens of millions of clients at once to offer true real-time applications at scale. By the end of the talk, you should feel comfortable knowing that you can become a cloud engineer using an existing GraphQL skillset.

This talk has been presented at GraphQL Galaxy 2020, check out the latest edition of this Tech Conference.

FAQ

AWS AppSync is a managed GraphQL service provided by AWS that simplifies the process of building scalable APIs. It handles security, scalability, and data integration, allowing developers to define types, queries, mutations, and subscriptions in their schema, and to configure different authentication and authorization types, making it suitable for handling both public and private access scenarios.

The main challenges include ensuring security through authentication, authorization, and fine-grained access control, managing scalability to handle sudden spikes in traffic, maintaining developer velocity with manageable complexity, and controlling costs in terms of both monetary and opportunity costs.

The AWS Cloud Development Kit (CDK) allows developers to define cloud infrastructure in code, using familiar programming languages like TypeScript. It integrates with AWS services like Lambda and DynamoDB to deploy scalable GraphQL APIs efficiently, enabling rapid development and iteration.

AWS AppSync's managed service model provides a dedicated team that focuses on solving specific problems related to GraphQL APIs, offering a solution that is backed by years of development and specialized expertise. This model helps in reducing the time and effort required to build and manage APIs while ensuring scalability and security.

Configuring an API with AWS AppSync involves defining the GraphQL schema with types, queries, mutations, and subscriptions. Developers can configure multiple authentication and authorization types to suit different access scenarios. They can also link the API to various data sources such as AWS DynamoDB, serverless Aurora, or external databases like MongoDB.

AWS AppSync APIs can be deployed using AWS Amplify, AWS CDK, or any tool that supports AWS CloudFormation. These tools facilitate the setup of APIs and the integration with other AWS services, providing various features like GraphQL code generation, schema transformation, and more.

AWS AppSync allows configuration of various authentication and authorization mechanisms, including public and private access types, using providers like OIDC. Security measures against malicious queries, DDoS attacks, and data encryption are also supported to protect the API and its data.

Nader Dabit
Nader Dabit
31 min
02 Jul, 2021

Comments

Sign in or register to post your comment.

Video Summary and Transcription

This talk covers building a highly scalable cloud API gateway using GraphQL and AWS AppSync. It delves into the intersection of web, mobile, and cloud computing, emphasizing the concept of a full-stack cloud and serverless architecture. The speaker discusses key challenges like malicious queries, query depth, and the importance of making subscriptions scale. AWS AppSync is highlighted for its ability to handle sudden spikes in traffic and its support for multiple authentication and authorization types. The process of configuring an API with AppSync involves defining the schema, data sources, and resolvers, with deployment options including AWS Amplify and AWS CDK. Additionally, the talk addresses the need for developer velocity and cost considerations, and mentions tools like the SAM CLI for testing GraphQL Lambdas.

1. Introduction

Short description:

I'm going to be talking about building a highly scalable cloud API gateway with GraphQL. My team is focused on the intersection of web, mobile, and cloud computing. I'm interested in the idea of a full-stack cloud and full-stack serverless. This talk is going to be broken up into three main parts: briefly going over concepts, building a live coding demo, and discussing the challenges of building a custom GraphQL server and AWS AppSync.

♪ Hello, everyone. Welcome to my talk. I'm going to be talking about building a highly scalable cloud API gateway with GraphQL. My name is Nader Dabat. I'm a senior developer advocate on the AWS web and mobile team, where I focus on lowering the barrier to entry to cloud computing. My team works on a lot of different technologies. We work on web. We work on mobile. We work on back-end, infrastructure as code, all kinds of stuff.

But really my team is really focused on the intersection of web, mobile, and cloud computing. So kind of like the intersection of front-end and cloud, full-stack cloud, you could call it. And in particular, one of the things that I'm really interested in is this idea of a full-stack cloud and full-stack serverless. So I think the talk that I'm going to be giving today kind of goes very closely along with that idea, because I'm able to kind of use my existing front-end skill set as a front-end developer to build out these scalable cloud applications using GraphQL.

So I have a couple of books, but the most recent one and the one that might pertain the most to this talk is full-stack serverless from O'Reilly. So if you're interested in building these cloud applications with React and GraphQL or just with GraphQL and any front-end framework, definitely check it out. Everything there is built with GraphQL and AWS.

So this talk is going to be broken up into three main parts. So it's a 20-minute talk, not a lot of time. So I'm going to kind of briefly go over some concepts and then I'm going to build a live coding demo that kind of builds the things that I'm talking about, because for me, I like watching code. I learn a lot when I see code. And the idea that I'm going to be building is using infrastructure as code in TypeScript. So it's actually a really fun topic, in my opinion. So I'm going to be kind of going over what are the challenges of building a custom GraphQL server? I'm going to talk about AWS AppSync and then I'm going to do that live coding demo.

So what are some of the challenges for building a GraphQL API from scratch? It's kind of broken up in my opinion into four main parts. The first and, in my opinion, most important is security. When you build out your GraphQL API, you not only kind of have to make it work, you have to take into consideration a lot of different things and a lot of different scenarios around authentication, authorization, and find grant access control. Most of the time, your API is going to need multiple types of authorization scenarios. So if you think of something like Twitter, you think of something like Instagram, Facebook, all of the more popular, modern applications that you probably interact with today, typically have a combination of public and private access.

So how do you actually implement this public and private access? And if you're doing this from scratch, it's typically a lot of work. You have to think about things like encryption, you have to think about how the user information is stored, and all of this stuff.

2. Building Scalable APIs with AWS AppSync

Short description:

And then there's GraphQL-specific scenarios, like malicious queries, query depth, and things like that. The next main area is scalability. So you built this API. It works. But what happens when you get that 10,000-user bump at one time, or something goes viral, and you get a 10X or 100X or maybe even a 1,000X number of visitors? You want your API to scale. And then you have to think about GraphQL-specific stuff, like subscriptions. So one of the things that we've worked on very hard and something we've really focused on the last few years is making subscriptions scale. And then the next thing that I would say is something that you typically need to take into consideration is this idea of developer velocity. And then finally, there's cost. And when I talk about cost, I'm not only talking about monetary cost, I'm also talking about opportunity cost and developer hours, and the things that you consider, for instance, if you're a startup or just a company in general, and you have competing companies that are doing the same thing that you're doing, if you need to build something and test it out and you don't know it's going to work or not, let's say you spend three months, six months building this thing. That's an opportunity cost that you have to really consider, because if this thing doesn't work out, you've spent a lot of money, you've spent a lot of time, and that time could have possibly been spent building something else, had you known that this thing was not going to work out. This is kind of where I think that AWS AppSync, the service that we've been working on for the last few years, really shines across all these different areas. Anyway, so, AppSync allows you to kind of build out these APIs anything that you need mapped through GraphQL you can do with AppSync. So, you start off with the new AppSync API, you define your schema. From there you configure the different authentication and authorization types. After you've configured your auth types, you configure your data sources.

And then there's GraphQL-specific scenarios, like malicious queries, query depth, and things like that. And then the typical security rules and issues that you deal with within the API surface, like DDoS attacks and things like that.

The next main area is scalability. So you built this API. It works. But what happens when you get that 10,000-user bump at one time, or something goes viral, and you get a 10X or 100X or maybe even a 1,000X number of visitors? You want your API to scale. So how do you actually provision your infrastructure and do so in a cost-effective manner to where your app scales? And then you have to think about GraphQL-specific stuff, like subscriptions. So one of the things that we've worked on very hard and something we've really focused on the last few years is making subscriptions scale. So we have customers that have scaled our APIs to tens of millions of connected devices for a single API endpoint. This was a very hard challenge, and it's typically something that is just hard to do in general.

And then the next thing that I would say is something that you typically need to take into consideration is this idea of developer velocity. So when you're building your API, what happens when you need to add a new feature? When you need to version something? When you need to modify an existing data source or maybe even add a new data source? What happens when your API starts to become complex? Is this going to slow your team down and therefore kind of slow the development of your entire app? And then finally, there's cost. And when I talk about cost, I'm not only talking about monetary cost, I'm also talking about opportunity cost and developer hours, and the things that you consider, for instance, if you're a startup or just a company in general, and you have competing companies that are doing the same thing that you're doing, if you need to build something and test it out and you don't know it's going to work or not, let's say you spend three months, six months building this thing. That's an opportunity cost that you have to really consider, because if this thing doesn't work out, you've spent a lot of money, you've spent a lot of time, and that time could have possibly been spent building something else, had you known that this thing was not going to work out. So, how do you take into consideration all of these things and how do you do so kind of in an effective manner across all of these different areas?

This is kind of where I think that AWS AppSync, the service that we've been working on for the last few years, really shines across all these different areas. And AppSync is a managed GraphQL service from AWS. And I really like managed services because when you are dealing with a managed service, this team is working on just this one problem for years. And all those people are specialized in solving this one problem. So, when you're buying into a managed service, you're typically buying into years of work, a lot of money spent, and a lot of edge cases solved for just dealing with this one problem. So, if you can find something that kind of fits the challenge that you're trying to solve, and a managed service way from a team that you can trust, it's often a good approach for doing something without having to build it yourself from scratch and kind of reinventing the wheel.

Anyway, so, AppSync allows you to kind of build out these APIs anything that you need mapped through GraphQL you can do with AppSync. So, you start off with the new AppSync API, you define your schema. Here in your schema you define your types of course, your queries, your mutations and your subscriptions. From there you configure the different authentication and authorization types. So, you can have a base type, and the base type could be public, it could be private, it could be using an OIDC provider, it could be whatever. But you can have additional authorization types as well. So, most APIs, like I mentioned, have multiple authorization scenarios. So, most apps that go to production have multiple auth types. So, you typically have some type of public access along with some type of private access. After you've configured your auth types, you configure your data sources.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

From GraphQL Zero to GraphQL Hero with RedwoodJS
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
From GraphQL Zero to GraphQL Hero with RedwoodJS
Top Content
Tom Pressenwurter introduces Redwood.js, a full stack app framework for building GraphQL APIs easily and maintainably. He demonstrates a Redwood.js application with a React-based front end and a Node.js API. Redwood.js offers a simplified folder structure and schema for organizing the application. It provides easy data manipulation and CRUD operations through GraphQL functions. Redwood.js allows for easy implementation of new queries and directives, including authentication and limiting access to data. It is a stable and production-ready framework that integrates well with other front-end technologies.
Local State and Server Cache: Finding a Balance
Vue.js London Live 2021Vue.js London Live 2021
24 min
Local State and Server Cache: Finding a Balance
Top Content
This Talk discusses handling local state in software development, particularly when dealing with asynchronous behavior and API requests. It explores the challenges of managing global state and the need for actions when handling server data. The Talk also highlights the issue of fetching data not in Vuex and the challenges of keeping data up-to-date in Vuex. It mentions alternative tools like Apollo Client and React Query for handling local state. The Talk concludes with a discussion on GitLab going public and the celebration that followed.
Batteries Included Reimagined - The Revival of GraphQL Yoga
GraphQL Galaxy 2021GraphQL Galaxy 2021
33 min
Batteries Included Reimagined - The Revival of GraphQL Yoga
Envelope is a powerful GraphQL plugin system that simplifies server development and allows for powerful plugin integration. It provides conformity for large corporations with multiple GraphQL servers and can be used with various frameworks. Envelope acts as the Babel of GraphQL, allowing the use of non-spec features. The Guild offers GraphQL Hive, a service similar to Apollo Studio, and encourages collaboration with other frameworks and languages.
Rock Solid React and GraphQL Apps for People in a Hurry
GraphQL Galaxy 2022GraphQL Galaxy 2022
29 min
Rock Solid React and GraphQL Apps for People in a Hurry
The Talk discusses the challenges and advancements in using GraphQL and React together. It introduces RedwoodJS, a framework that simplifies frontend-backend integration and provides features like code generation, scaffolding, and authentication. The Talk demonstrates how to set up a Redwood project, generate layouts and models, and perform CRUD operations. Redwood automates many GraphQL parts and provides an easy way for developers to get started with GraphQL. It also highlights the benefits of Redwood and suggests checking out RedwoodJS.com for more information.
Adopting GraphQL in an Enterprise
GraphQL Galaxy 2021GraphQL Galaxy 2021
32 min
Adopting GraphQL in an Enterprise
Today's Talk is about adopting GraphQL in an enterprise. It discusses the challenges of using REST APIs and the benefits of GraphQL. The Talk explores different approaches to adopting GraphQL, including coexistence with REST APIs. It emphasizes the power of GraphQL and provides tips for successful adoption. Overall, the Talk highlights the advantages of GraphQL in terms of efficiency, collaboration, and control over APIs.
Step aside resolvers: a new approach to GraphQL execution
GraphQL Galaxy 2022GraphQL Galaxy 2022
16 min
Step aside resolvers: a new approach to GraphQL execution
GraphQL has made a huge impact in the way we build client applications, websites, and mobile apps. Despite the dominance of resolvers, the GraphQL specification does not mandate their use. Introducing Graphast, a new project that compiles GraphQL operations into execution and output plans, providing advanced optimizations. In GraphFast, instead of resolvers, we have plan resolvers that deal with future data. Graphfast plan resolvers are short and efficient, supporting all features of modern GraphQL.

Workshops on related topic

Build with SvelteKit and GraphQL
GraphQL Galaxy 2021GraphQL Galaxy 2021
140 min
Build with SvelteKit and GraphQL
Top Content
Featured WorkshopFree
Scott Spence
Scott Spence
Have you ever thought about building something that doesn't require a lot of boilerplate with a tiny bundle size? In this workshop, Scott Spence will go from hello world to covering routing and using endpoints in SvelteKit. You'll set up a backend GraphQL API then use GraphQL queries with SvelteKit to display the GraphQL API data. You'll build a fast secure project that uses SvelteKit's features, then deploy it as a fully static site. This course is for the Svelte curious who haven't had extensive experience with SvelteKit and want a deeper understanding of how to use it in practical applications.

Table of contents:
- Kick-off and Svelte introduction
- Initialise frontend project
- Tour of the SvelteKit skeleton project
- Configure backend project
- Query Data with GraphQL
- Fetching data to the frontend with GraphQL
- Styling
- Svelte directives
- Routing in SvelteKit
- Endpoints in SvelteKit
- Deploying to Netlify
- Navigation
- Mutations in GraphCMS
- Sending GraphQL Mutations via SvelteKit
- Q&A
Build Modern Applications Using GraphQL and Javascript
Node Congress 2024Node Congress 2024
152 min
Build Modern Applications Using GraphQL and Javascript
Featured Workshop
Emanuel Scirlet
Miguel Henriques
2 authors
Come and learn how you can supercharge your modern and secure applications using GraphQL and Javascript. In this workshop we will build a GraphQL API and we will demonstrate the benefits of the query language for APIs and what use cases that are fit for it. Basic Javascript knowledge required.
End-To-End Type Safety with React, GraphQL & Prisma
React Advanced Conference 2022React Advanced Conference 2022
95 min
End-To-End Type Safety with React, GraphQL & Prisma
Featured WorkshopFree
Sabin Adams
Sabin Adams
In this workshop, you will get a first-hand look at what end-to-end type safety is and why it is important. To accomplish this, you’ll be building a GraphQL API using modern, relevant tools which will be consumed by a React client.
Prerequisites: - Node.js installed on your machine (12.2.X / 14.X)- It is recommended (but not required) to use VS Code for the practical tasks- An IDE installed (VSCode recommended)- (Good to have)*A basic understanding of Node.js, React, and TypeScript
GraphQL for React Developers
GraphQL Galaxy 2022GraphQL Galaxy 2022
112 min
GraphQL for React Developers
Featured Workshop
Roy Derks
Roy Derks
There are many advantages to using GraphQL as a datasource for frontend development, compared to REST APIs. We developers in example need to write a lot of imperative code to retrieve data to display in our applications and handle state. With GraphQL you cannot only decrease the amount of code needed around data fetching and state-management you'll also get increased flexibility, better performance and most of all an improved developer experience. In this workshop you'll learn how GraphQL can improve your work as a frontend developer and how to handle GraphQL in your frontend React application.
Build a Headless WordPress App with Next.js and WPGraphQL
React Summit 2022React Summit 2022
173 min
Build a Headless WordPress App with Next.js and WPGraphQL
Top Content
WorkshopFree
Kellen Mace
Kellen Mace
In this workshop, you’ll learn how to build a Next.js app that uses Apollo Client to fetch data from a headless WordPress backend and use it to render the pages of your app. You’ll learn when you should consider a headless WordPress architecture, how to turn a WordPress backend into a GraphQL server, how to compose queries using the GraphiQL IDE, how to colocate GraphQL fragments with your components, and more.
Relational Database Modeling for GraphQL
GraphQL Galaxy 2020GraphQL Galaxy 2020
106 min
Relational Database Modeling for GraphQL
Top Content
WorkshopFree
Adron Hall
Adron Hall
In this workshop we'll dig deeper into data modeling. We'll start with a discussion about various database types and how they map to GraphQL. Once that groundwork is laid out, the focus will shift to specific types of databases and how to build data models that work best for GraphQL within various scenarios.
Table of contentsPart 1 - Hour 1      a. Relational Database Data Modeling      b. Comparing Relational and NoSQL Databases      c. GraphQL with the Database in mindPart 2 - Hour 2      a. Designing Relational Data Models      b. Relationship, Building MultijoinsTables      c. GraphQL & Relational Data Modeling Query Complexities
Prerequisites      a. Data modeling tool. The trainer will be using dbdiagram      b. Postgres, albeit no need to install this locally, as I'll be using a Postgres Dicker image, from Docker Hub for all examples      c. Hasura