GraphQL lets clients ask for exactly the data they need in one request, which is great for frontends and mobile apps. On the server, that flexibility shifts responsibility to you: a single query can fan out into hundreds of database calls, and a malicious query can ask for enormous nested data. This guide covers hosting a GraphQL API that stays fast and safe.
Choosing a Server
Pick the GraphQL server for your language: Apollo Server, GraphQL Yoga or Mercurius on Node.js; Strawberry or Graphene on Python; graphql-java or Spring for GraphQL on Java; Hot Chocolate on .NET; gqlgen on Go. Run it as a supervised service behind Nginx like any API (see our REST API hosting guide for the shared setup).
The N+1 Problem
A query for 50 orders with their customers can trigger 1 query for orders and 50 for customers. Batch and cache per request with DataLoader (or your framework's equivalent), which collects the customer IDs and fetches them in one query. Check query counts per operation in development; this one change often reduces database load dramatically.
Protecting the Server
- Depth limits: reject deeply nested queries (for example more than 8–10 levels).
- Complexity or cost limits: assign costs to fields and lists and reject expensive queries.
- Pagination required on list fields, with maximum page sizes.
- Timeouts per request and per resolver for slow data sources.
- Rate limiting per client or API key in Nginx and in the application.
- Introspection disabled or restricted in production for public APIs if your threat model requires it.
Persisted Queries
With persisted (or allow-listed) queries, clients send a hash instead of the full query text, and the server only runs queries it knows. This blocks arbitrary expensive queries from public clients, shrinks requests, and allows GET requests that can be cached by a CDN.
Caching
| Layer | Use |
|---|---|
| CDN / HTTP cache | Public persisted queries over GET with cache headers |
| Response cache | Whole query results for public data, keyed by query and variables |
| Resolver / data cache (Redis) | Expensive lookups shared across requests |
| DataLoader | Per-request batching and de-duplication |
Never cache user-specific results in shared caches without including the user in the key.
Subscriptions
GraphQL subscriptions usually run over WebSockets (graphql-ws protocol) or server-sent events. Configure Nginx for upgrades with long timeouts, authenticate during connection initialisation, and use Redis pub/sub so events reach subscribers on every process (see our WebSocket guide).
Monitoring per Operation
All GraphQL requests hit one URL, so web server logs show little. Record metrics per operation name: request count, error rate, latency percentiles and resolver timings. Require clients to name operations, and alert on slow or failing operations. Tracing (for example OpenTelemetry) shows which resolvers dominate a slow query.
Error Handling
GraphQL returns errors in the response body, often with HTTP 200. Log errors server-side with operation names, avoid exposing stack traces or internal details to clients, and distinguish user errors from server failures in your monitoring.
Security
- Authorisation in resolvers or a central layer for every field that returns protected data, not only at the top level.
- Validate input types and sizes.
- HTTPS only; CORS limited to your frontends.
- Batching limits if your server accepts multiple operations per request.
Sizing
| API | Suggested plan |
|---|---|
| API for a web or mobile app, with its database | 2 vCores / 8 GB |
| Busy API, subscriptions, Redis caching | 4 vCores / 16 GB |
| Federated graph or heavy analytics queries | 8 vCores / 32 GB or several services |
Common Mistakes
- No DataLoader, so list queries trigger hundreds of database calls.
- Unlimited depth and list sizes on public endpoints.
- Authorisation only on top-level fields.
- Monitoring only the single /graphql URL instead of operations.
In Short
Batch data loading, limit query cost, prefer persisted queries for public clients, cache carefully, run subscriptions with pub/sub, and monitor per operation.
Example: A Mobile App Backend
A food-ordering startup serves its Android and iOS apps from a GraphQL API built with GraphQL Yoga on a 4 vCore / 16 GB VPS, alongside PostgreSQL and Redis. The mobile apps ship persisted queries generated at build time, so the server rejects any query it does not recognise. DataLoader batches restaurant and menu lookups, cutting a typical home-screen query from dozens of database calls to four. Order status updates reach customers through a subscription over WebSockets, with Redis pub/sub fanning events out to both Node.js processes. Metrics per operation name revealed that one search operation caused most slow responses; adding an index and a short Redis cache fixed it.
Schema Evolution
GraphQL APIs usually evolve without versioned URLs. Add new fields freely, mark old ones with @deprecated and a reason, watch usage metrics until clients stop requesting them, and only then remove them. Check schema changes in CI against the queries your clients actually use, so a careless rename does not break an app version that users have not updated yet. Mobile apps stay installed for months, so plan deprecation windows accordingly.
Next Steps
Add DataLoader to every relationship resolver, enable depth and cost limits, name all client operations, and set up per-operation metrics before your traffic grows. Then decide whether persisted queries suit your clients.
Deployment Checklist
- Run the server under systemd, PM2 or Docker with automatic restarts and health checks.
- Set request body size limits in Nginx and the GraphQL server so huge queries or variables are rejected early.
- Configure database connection pools to match worker counts, so bursts of resolvers do not exhaust connections.
- Generate and publish the schema in CI, and check for breaking changes before deploying.
- Deploy new versions with a rolling or blue-green approach so long-lived subscription connections reconnect cleanly.
Schema Evolution
GraphQL APIs usually evolve without versioned URLs. Add new fields freely, mark old ones with @deprecated and a reason, watch operation metrics to see when clients stop using them, and remove fields only after usage reaches zero. Schema checks in CI that compare against recorded client operations catch accidental breaking changes, such as renaming a field or making a nullable argument required, before they reach production.
Example: A Mobile App Backend
A team serving a React Native app runs GraphQL Yoga with PostgreSQL and Redis on a 4 vCore / 16 GB VPS. DataLoader batches every relation, list fields are capped at 50 items, and the mobile app ships persisted queries, so the public endpoint rejects anything not on the allow list. Product catalogue queries are cached in Redis for a minute, order updates reach the app through subscriptions, and dashboards show latency per operation name so slow screens are easy to trace.
SkyRainCloud Plans for This Workload
GraphQL servers are usually light; the database does the heavy lifting. 2 vCores / 8 GB runs most APIs with their database; heavy query loads or subscriptions fit 4 vCores / 16 GB.
AMD EPYC 7C13 VPS
Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — AMD | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Websites, small APIs, bots, staging and VPN servers | Order |
| VPS 2 — AMD | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,299/month | WooCommerce, Node.js/Python backends, Docker Compose stacks, CI runners | Order |
| VPS 3 — AMD | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,499/month | Production databases, high-traffic sites, multi-container apps | Order |
| VPS 4 — AMD | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,899/month | Large production workloads, SaaS platforms, analytics, in-memory caches | Order |
Intel Xeon Platinum 8269CY VPS
KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — Intel | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Business websites, small apps, scheduled jobs and bots | Order |
| VPS 2 — Intel | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,169/month | Business software, mid-size databases, several sites on one server | Check stock |
| VPS 3 — Intel | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,249/month | ERP/CRM stacks, heavier databases, multiple production apps | Check stock |
| VPS 4 — Intel | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,299/month | High-memory workloads and consolidated production servers | Check stock |
Prices are monthly in INR as listed on the SkyRainCloud store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.