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.

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 discusses building a highly scalable cloud API gateway with GraphQL using AWS AppSync. It covers the challenges of scalability, developer velocity, and cost in building APIs. The Talk provides a step-by-step guide on building a cloud API gateway using CDK and AppSync, including defining the schema, configuring data sources and permissions, creating resolvers, and deploying the API. It also highlights the flexibility and trade-offs of using AWS AppSync, testing GraphQL Lambdas, and the portability of the solution. The learning curve of AppSync has improved over time, and future updates are planned to further simplify the process.

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
We all love GraphQL, but it can be daunting to get a server up and running and keep your code organized, maintainable, and testable over the long term. No more! Come watch as I go from an empty directory to a fully fledged GraphQL API in minutes flat. Plus, see how easy it is to use and create directives to clean up your code even more. You're gonna love GraphQL even more once you make things Redwood Easy!
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
How many times did you implement the same flow in your application: check, if data is already fetched from the server, if yes - render the data, if not - fetch this data and then render it? I think I've done it more than ten times myself and I've seen the question about this flow more than fifty times. Unfortunately, our go-to state management library, Vuex, doesn't provide any solution for this.For GraphQL-based application, there was an alternative to use Apollo client that provided tools for working with the cache. But what if you use REST? Luckily, now we have a Vue alternative to a react-query library that provides a nice solution for working with server cache. In this talk, I will explain the distinction between local application state and local server cache and do some live coding to show how to work with the latter.
Batteries Included Reimagined - The Revival of GraphQL Yoga
GraphQL Galaxy 2021GraphQL Galaxy 2021
33 min
Batteries Included Reimagined - The Revival of GraphQL Yoga
The Guild has recently released Envelop - a new, modern GraphQL Server Framework and plugin system. In this talk I’ll share a brief overview of Envelop and why you should probably upgrade your existing GraphQL server to it.
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
In this talk, we'll look at some of the modern options for building a full-stack React and GraphQL app with strong conventions and how this can be of enormous benefit to you and your team. We'll focus specifically on RedwoodJS, a full stack React framework that is often called 'Ruby on Rails for React'.
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
Though GraphQL is declarative, resolvers operate field-by-field, layer-by-layer, often resulting in unnecessary work for your business logic even when using techniques such as DataLoader. In this talk, Benjie will introduce his vision for a new general-purpose GraphQL execution strategy whose holistic approach could lead to significant efficiency and scalability gains for all GraphQL APIs.

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
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
Building GraphQL APIs on top of Ethereum with The Graph
GraphQL Galaxy 2021GraphQL Galaxy 2021
48 min
Building GraphQL APIs on top of Ethereum with The Graph
WorkshopFree
Nader Dabit
Nader Dabit
The Graph is an indexing protocol for querying networks like Ethereum, IPFS, and other blockchains. Anyone can build and publish open APIs, called subgraphs, making data easily accessible.

In this workshop you’ll learn how to build a subgraph that indexes NFT blockchain data from the Foundation smart contract. We’ll deploy the API, and learn how to perform queries to retrieve data using various types of data access patterns, implementing filters and sorting.

By the end of the workshop, you should understand how to build and deploy performant APIs to The Graph to index data from any smart contract deployed to Ethereum.