Episode 37 designs GraphQL serverless-first: cold start optimization with light dependencies and warm-ups, AWS Lambda with API Gateway and VPC, edge computing with Cloudflare Workers and Vercel Edge Functions, and database connection management with RDS Proxy and serverless databases.

Serverless changes how we think about deployment: no servers to manage, automatic scaling, and pay-as-you-go. Episode 37 designs GraphQL serverless-first — with all its benefits and challenges.
We'll cover serverless best practices, run GraphQL on AWS Lambda, explore edge computing, and manage database connections in a serverless environment.
A cold start happens when an idle function is booted again — the first request is slower. Ways to reduce it:
{
"dependencies": {
"@apollo/server": "^4",
"graphql": "^16"
}
}Every dependency adds bundle size and init time. Audit your packages: do you need the whole library, or just a small part of it? Also apply stateless design (episode 34): shared state in Redis, not in instance memory.
GraphQL on Lambda uses a handler pattern that maps HTTP events to GraphQL:
import { startServerAndCreateLambdaHandler } from "@as-integrations/aws-lambda";
import { ApolloServer } from "@apollo/server";
const server = new ApolloServer({ typeDefs, resolvers });
export const graphqlHandler = startServerAndCreateLambdaHandler(server);This handler is exposed via API Gateway (REST or HTTP API) which forwards requests to Lambda. Configuration in serverless.yml:
service: graphql-api
provider:
name: aws
runtime: nodejs20.x
memorySize: 512
functions:
graphql:
handler: dist/index.graphqlHandler
events:
- httpApi:
path: /graphql
method: POSTIf Lambda must access a database in a VPC (for example RDS), configure the VPC in serverless.yml, then deploy with serverless deploy. Because Lambda instances are created and destroyed, connection pooling is a must. Lambda Layers can separate large dependencies so the handler bundle stays small.
Edge computing runs code at the location closest to the user — the smallest latency. GraphQL at the edge:
export default {
async fetch(request, env) {
const { pathname } = new URL(request.url);
if (pathname === "/graphql") {
return handleGraphQL(request);
}
return new Response("Not found", { status: 404 });
},
};Note that edge runtimes have limitations: not all Node libraries run there (for example certain Node.js APIs are unavailable). For GraphQL at the edge, consider simple queries, CDN-cached results, and calls to the origin for mutation data.
Combine the edge with regional routing: cache public queries at the edge, then route write requests (mutations) to the right region. This splits load and keeps latency low for frequent reads.
The classic serverless problem: every Lambda invocation can open a connection, and the database quickly runs out of connections. The standard AWS solution is RDS Proxy — a pooler that centralizes Lambda connections to the database:
import pg from "pg";
const pool = new pg.Pool({
host: process.env.RDS_PROXY_HOST,
database: "app",
user: "app",
password: process.env.DB_PASSWORD,
max: 20,
});RDS Proxy also keeps connections warm between invocations, reducing cold starts for database access.
Serverless databases remove the need to manage instances:
Serverless databases fit the up-and-down pattern of Lambda. Remember that the RPO and RTO from episode 35 still apply — make sure backups and PITR are active.
Key takeaways:
startServerAndCreateLambdaHandler exposes GraphQL on AWS Lambda.In the next episode, episode 38, you'll learn about real-time collaboration features — live queries with @live, presence features with online status and cursor positions, conflict resolution with OT and CRDT, and example implementations of collaborative editing and live dashboards. Your real-time collaborative app will come alive!