GraphQL Federation excels for multi-client consumer platforms (iOS, Android, Web, and Smart TV apps) requiring rich cross-entity relationships and bespoke field selections. REST API gateways excel for high-throughput streaming, B2B partner integrations, sub-millisecond edge caching, and zero-parsing-overhead microservices.
Architectural Comparison: Federation vs REST Gateways
| Dimension | GraphQL Federation v2 | REST API Gateway (Envoy/Kong) |
|---|---|---|
| Client Integration | Single endpoint; clients query precise nested graphs | Multiple domain endpoints (/v1/users, /v1/orders) |
| Network Round-trips | 1 client request fetches data from 10 microservices | Client or BFF must orchestrate multiple HTTP calls |
| HTTP Caching | Complex (POST bodies; requires Persisted Queries) | Native (Standard HTTP 200/304, Cache-Control, CDN) |
| Gateway CPU Overhead | Higher (Query AST validation & planning) | Minimal (L7 proxying in C++ / Rust) |
| Schema Contracts | Strict SDL with automated composition validation | OpenAPI / Swagger specs (often drift without tooling) |
Federation v2 Subgraph Composition
In Apollo Federation, domain teams own independent subgraphs. The router dynamically merges them using entity keys (@key):
# products-subgraph.graphql
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.5",
import: ["@key", "@shareable", "@override"])
type Product @key(fields: "id") {
id: ID!
title: String!
priceCents: Int!
inventory: InventoryInfo @shareable
}
type InventoryInfo @shareable {
inStock: Boolean!
leadTimeDays: Int
}
type Query {
product(id: ID!): Product
featuredProducts(limit: Int = 10): [Product!]!
}The federation router parses incoming queries, generates an optimized parallel execution plan, and resolves sub-entity dependencies across team boundaries in a single query pass.
High-Throughput REST Gateways with Envoy
For latency-critical B2B APIs processing 50,000+ requests per second, Envoy provides low-overhead rate limiting, TLS termination, and mTLS pod-to-pod security:
// envoy.yaml - High-Throughput REST Gateway Route Configuration
static_resources:
listeners:
- name: https_gateway
address:
socket_address: { address: 0.0.0.0, port_value: 443 }
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
stat_prefix: ingress_http
route_config:
name: enterprise_routes
virtual_hosts:
- name: api_service
domains: ["api.endurancesoftwares.com"]
routes:
- match: { prefix: "/v1/products" }
route: { cluster: product_service, timeout: 0.5s }
typed_per_filter_config:
envoy.filters.http.local_ratelimit:
token_bucket: { max_tokens: 1000, tokens_per_fill: 100, fill_interval: 1s }
- match: { prefix: "/v1/checkout" }
route: { cluster: checkout_service, timeout: 2.0s }Preventing GraphQL Query Explosions & Denial of Service
Unlike REST where every endpoint has fixed resource boundaries, open GraphQL endpoints can be attacked with deeply nested recursive queries. Essential production guardrails:
- Query Depth Limiting: Reject queries deeper than 6 nesting levels.
- Static Cost Calculation: Assign complexity points to fields and reject requests exceeding 500 points.
- Persisted Queries: Disallow arbitrary GraphQL strings in production; accept only pre-approved query hashes from client builds.
Edge Caching: Persisted Queries vs HTTP GET
By converting approved GraphQL operations into GET /graphql?hash=... requests, modern edge CDNs (Cloudflare, Fastly) can cache federated GraphQL responses with the exact same efficiency as traditional REST endpoints.
API Architecture Selection Checklist
✓ Federation chosen when multiple client platforms need disparate field sets
✓ REST chosen for third-party public developer APIs and webhooks
✓ Schema checks integrated into CI/CD to prevent breaking changes
✓ Persisted queries enabled to protect against arbitrary AST DOS attacks
✓ DataLoader pattern implemented in subgraphs to eliminate N+1 queries
✓ Distributed tracing (OpenTelemetry) traces subgraph resolution spans
✓ Automatic schema linting enforces consistent naming standards
✓ Circuit breakers isolate slow subgraphs from cascading failures
Architect Modern APIs with Endurance Softwares
We help scale backend systems with high-throughput API gateways, GraphQL federation supergraphs, and microservice orchestration.
Consult With Our Backend SpecialistsFrequently Asked Questions
Can you use GraphQL Federation and REST together?
Yes! Many enterprise architectures use REST or gRPC for internal inter-service communication while exposing an Apollo Federation router as the unified Backend-for-Frontend (BFF) layer for web and mobile apps.
How do subgraphs resolve the N+1 database problem?
Subgraphs use batching mechanisms (such as Dataloader) to collect individual entity lookups from the federation router into a single SQL WHERE id IN (...) query.
Is GraphQL Federation hard to monitor in production?
Apollo GraphOS and OpenTelemetry provide out-of-the-box field-level usage analytics, allowing you to deprecate unused schema fields safely with zero guessing.