Episode 33 builds a GraphQL gateway and API management: gateway layer responsibilities, Kong Gateway with rate limiting and authentication, AWS AppSync as managed GraphQL, Hasura for instant GraphQL from a database, and API key management with a developer portal.

The larger an organization, the more services, clients, and teams need to be managed. Episode 33 discusses GraphQL Gateway and API Management — the layer that stands in front of your services and manages traffic, authentication, and usage limits.
We'll learn the gateway's responsibilities, use Kong Gateway, explore AWS AppSync and Hasura as managed solutions, and discuss API management comprehensively.
The gateway sits between clients and services. Its main responsibilities:
The common pattern: clients only interact with the gateway; the services behind it are never directly exposed. This simplifies security and allows backend changes without affecting clients.
Kong is an open-source API gateway that supports GraphQL. Run it via Docker:
docker run -d --name kong \
-p 8000:8000 -p 8001:8001 \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=localhost" \
kong:3.8Then register the GraphQL service and route via the Kong Admin API, for example with curl -X POST http://localhost:8001/services -d name=graphql-api -d url=http://api:4000.
Add the rate limiting and key-auth plugins:
curl -X POST http://localhost:8001/services/graphql-api/plugins \
-d name=rate-limiting \
-d config.minute=100 \
-d config.policy=localcurl -X POST http://localhost:8001/services/graphql-api/plugins \
-d name=key-authWith the key-auth plugin, every consumer must include an API key — consumer and key management is done via the Kong Admin API. Kong handles limiting and authentication before the request reaches the GraphQL server.
AWS AppSync is a fully managed GraphQL service from AWS:
AppSync fits when you're already on AWS and want to remove the operational burden of servers. Its trade-offs: vendor lock-in and VTL- or JavaScript-based resolvers that are less flexible than writing free-form resolvers.
Hasura generates a GraphQL API automatically from a PostgreSQL database. Setup:
docker run -d -p 8080:8080 \
-e HASURA_GRAPHQL_DATABASE_URL=postgres://user:pass@host/db \
-e HASURA_GRAPHQL_ADMIN_SECRET=rahasia \
hasura/graphql-engine:latestWith a single command, Hasura reads the database schema and instantly provides queries, mutations, filters, aggregations, and subscriptions. Its main advantages:
Hasura is great for getting started quickly at high speed, especially when your data lives in PostgreSQL. Its weakness: business logic still needs to be handled via remote schemas or actions.
Regardless of the gateway used, API management requires:
type UsageReport {
consumerId: ID!
requestCount: Int!
totalCost: Float!
period: String!
}Many companies combine a gateway (Kong, Apollo Gateway) with a managed platform like StepZen or a full API platform that provides an integrated developer portal.
Key takeaways:
In the next episode, episode 34, you'll learn about scaling GraphQL — vertical scaling with resource optimization, horizontal scaling with load balancing and stateless design, database scaling with read replicas and connection pooling, layered caching, scaling WebSocket subscriptions, and circuit breakers with bulkheads. Your API will be ready to serve millions of requests!