Real-Time GraphQL Subscriptions: Push Updates to Clients
SD
ScaleDojo
May 11, 2026
2 min read580 words
The Slack Notification Problem
You are building a chat app. Users need to see new messages instantly - not after polling every 2 seconds, not after refreshing the page. Slack, Discord, and every real-time app solve this with server push. GraphQL subscriptions give you this power using the same query language you already know for fetching data.
# Server (Python + Strawberry GraphQL):
import strawberry
from strawberry.types import Info
import asyncio
from typing import AsyncGenerator
@strawberry.type
class Subscription:
@strawberry.subscription
async def message_received(
self, chat_id: str
) -> AsyncGenerator[Message, None]:
# Subscribe to Redis pub/sub channel
async for event in redis.subscribe(f'chat:{chat_id}'):
yield Message(
id=event['id'],
text=event['text'],
sender=event['sender'],
sent_at=event['sent_at']
)
# Client (JavaScript):
const subscription = graphql`
subscription OnMessage($chatId: String!) {
messageReceived(chatId: $chatId) {
id, text, sender { name, avatar }, sentAt
}
}
`;
// Client gets EXACTLY the fields it asked for - no more, no less
Scaling Subscriptions Across Servers
Single server: simple
[Client] <--WS--> [Server with all subscriptions in memory]
Multi-server: needs pub/sub backbone
[Client A] [Client B] [Client C]
| | |
[Server 1] [Server 2] [Server 3]
| | |
+-------[Redis Pub/Sub]----------+
Problem: User A is on Server 1, User B on Server 2.
User B sends message -> mutation hits Server 2.
Server 2 publishes event to Redis channel.
Server 1 receives event from Redis.
Server 1 pushes to Client A's WebSocket.
Memory per subscription: ~1-5 KB
100K active subscribers: ~100-500 MB
Redis pub/sub latency: ~1-5 ms added
Subscriptions vs Polling vs SSE
Approach Latency Efficiency Complexity Best For
-------------- --------- ---------- ---------- ----------------
Polling 1-10s Low (waste) Simple Legacy clients
Long Polling ~instant Medium Medium Simple real-time
SSE ~instant High Medium One-way streams
WebSocket ~instant High High Bidirectional
GQL Sub (WS) ~instant High Medium Type-safe push
Interview Tip
When designing a real-time feature with a GraphQL API, say: 'I would use GraphQL subscriptions over WebSocket for push updates. The client subscribes using the same query language as reads, requesting exactly the fields it needs. For multi-server scaling, I would add Redis Pub/Sub as a backbone so events published on any server reach the correct subscriber. I would filter events server-side to avoid waking every subscription on every event - only subscribers interested in the specific chat room receive the push.'
<Architecture overview
/blockquote>
Key Takeaway
GraphQL subscriptions provide real-time push updates using the same query language as the rest of your API. They run over WebSockets and need pub/sub infrastructure for multi-server deployment. Use them for chat, live feeds, and dashboards where polling is too slow.
No comments yet. Be the first to start the thread!
Related Articles
Enjoyed this content?
Your support keeps us creating free resources
We put a lot of hours into researching and writing these guides. If it helped you, consider buying us a coffee. Every bit goes toward keeping ScaleDojo's content free and growing.
$
One-time payment via Stripe. ScaleDojo account required.