In today's digital landscape, real-time updates aren't just a luxury – they're an expectation. Whether you're building financial dashboards, instant messaging tools, or interactive gaming experiences, your users expect immediate, live updates.
We’re excited to announce that Hasura Data Delivery Network (DDN) now offers GraphQL subscriptions, making it easy for developers to build real-time features into their applications. GraphQL subscriptions feature is currently in beta, and available to all Hasura DDN users. Try it for free in your Hasura DDN projects – we’d love to hear what you think!
What are GraphQL subscriptions?
GraphQL subscriptions are a way for clients to receive automatic, real-time updates whenever specific data changes. Think of it like tracking live football match scores – when a goal is scored or the score changes, you automatically receive the real-time update.
GraphQL subscriptions enable real-time updates by allowing clients to listen for specific data changes. When the specified data changes on the server, the updates are sent to all connected clients that are actively subscribed. This is particularly powerful because developers can precisely specify (in their GraphQL schema) which data changes should trigger these real-time updates.
GraphQL subscriptions in Hasura DDN
Like all other API features (e.g. filters, sorting, pagination, etc.), Hasura DDN makes GraphQL subscriptions effortless, too. Simply connect to your data sources to instantly provision an API with default GraphQL subscriptions enabled on all models. Or, explicitly subscribe to specific models via metadata configuration.
Secure by default
With GraphQL subscriptions in Hasura DDN, access control permissions are automatically applied to subscribed changes. This means any real-time updates are automatically filtered based on user roles and permissions – your users only receive real-time updates for data they're authorized to see.
Performance and scaling
Without GraphQL subscriptions, it’s complex and resource-intensive to build and scale real-time features traditionally. Many applications rely on polling repeatedly requesting data to check for updates, which is inefficient and does not scale:
- Excessive server load from constant API requests
- High bandwidth consumption from repeated polling
- Complex client-side implementation for managing polling states
- Scaling difficulties as the user base grows
GraphQL subscriptions in Hasura DDN elegantly solve these challenges by establishing a constant connection to the database that pushes updates directly to clients when data changes occur.
What makes GraphQL subscriptions so powerful?
With this new functionality – instead of your application constantly asking "Has anything changed?" – now, GraphQL subscriptions proactively tell your application "Here's what changed!" This fundamental shift in data-to-application connectivity brings several advantages:
- Instant updates: Changes are pushed to clients immediately, ensuring that your application always shows the latest data.
- Resource efficiency: Eliminates unnecessary API calls and reduces server load.
- Precise data control: Like regular GraphQL queries, you specify exactly what data you need.
- Simple implementation: If you know how to use GraphQL, you already know how to use subscriptions.
Here's an example of a GraphQL subscription query:
subscription UserNotificationSubscription {
notifications(where: { user_id: { _eq: 123 } }) {
id
created_at
message
}
}
When this subscription is active, it establishes a persistent connection to the server. Any time new notifications are created, modified, or deleted for user 123 (in this case), the server automatically pushes an update, each of which will include the id
, created_at
, and message
fields for the affected notifications.
This is much more efficient than polling the server repeatedly to check for new notifications. Instead, updates are pushed to the client immediately when they occur.
Real-world use cases
GraphQL subscriptions power real-time features across various domains:
- Financial services: Live stock updates, transaction alerts, instant balance changes
- Gaming and sports: Leaderboards, player statuses, match statistics
- Collaboration tools: Chat messages, task updates, live editing status
- IoT and monitoring: Sensor data, device statuses, system health metrics
These are just a few examples of what’s possible. The flexibility of GraphQL subscriptions allows you to implement real-time updates in virtually any application.
Start building real-time applications today!
Real-time capabilities are becoming increasingly critical to success, as applications evolve. With GraphQL subscriptions in beta on Hasura DDN, you can build these features quickly, efficiently, and at scale. This eliminates the complexity traditionally associated with real-time features, allowing you to focus on what matters most – creating exceptional user experiences.
We're excited to see what you'll build with GraphQL subscriptions. Whether upgrading an existing application or starting a new project, our team is here to support your journey into real-time data integration.
Take the next step
Ready to transform your application with real-time capabilities? Getting started with GraphQL subscriptions is straightforward.
→ For new projects
- Set up a Hasura DDN project using the quickstart guide.
- Add your models to the supergraph.
- Subscriptions are automatically generated!
→ For existing projects
Run a single command:
ddn codemod upgrade-graphqlconfig-subscriptions
Test your subscriptions
Once your subscriptions are set up, you can test them directly in the GraphiQL console, which provides an interactive way to run GraphQL queries, mutations, and subscriptions.
To open the console, simply run:
ddn console