Course contentsShow
← Software Engineering
Lesson 822 of 1,93325. RPC and GraphQL API DesignFree lesson

Subscription Scalability Challenges

Managing real-time GraphQL subscriptions at scale with WebSocket connections and event distribution.

Subscription Scalability Challenges

What you'll learn: How real-time GraphQL subscriptions can strain your infrastructure and what makes them hard to scale.

The Core Challenge

Unlike queries and mutations that complete immediately, GraphQL subscriptions maintain long-lived WebSocket connections between clients and servers to deliver real-time updates. This creates unique scaling challenges because each active subscription consumes server resources continuously.

Imagine a REST API as a series of phone calls—you dial, get your answer, and hang up. Subscriptions are like keeping thousands of phones off the hook simultaneously, waiting to shout updates the moment something changes. Your server must track every open connection, remember what each client subscribed to, and push relevant events only to the right listeners.

Key Scalability Problems

Connection overhead: Each WebSocket connection requires memory. With 10,000 concurrent users subscribed to chat updates, your server maintains 10,000 active connections—even if most users aren't actively chatting.

Event distribution: When a mutation triggers a subscription event (like a new message), the server must identify which of those 10,000 connections care about that specific message (perhaps only users in one chat room) and fan out updates efficiently.

Stateful connections: Unlike REST's stateless requests, subscriptions tie clients to specific server instances. Horizontal scaling becomes complex—if Server A holds a user's WebSocket connection but Server B processes the mutation that should trigger their update, you need infrastructure (like Redis pub/sub or message queues) to route events between servers.

Resource exhaustion: Without proper limits, malicious or buggy clients can open hundreds of subscriptions, exhausting memory and CPU.

Key Takeaway: GraphQL subscriptions trade REST's stateless simplicity for real-time capabilities, requiring careful connection management, event routing infrastructure, and resource limits to scale beyond a few hundred concurrent users.