Subgraphs in blockchain: Diving into Benefits, use cases, deployment, and more

We all know blockchain data indexing is extremely hard because the data remains stored in a distributed ledger globally. So, if you are looking for an easy means to index and query blockchain data, Subgraphs is exactly what you need. Using Subgraph, decentralized applications can query their specific data easily from the blockchain’s massive databases. 

This comprehensive Subgraph guide provides you with end-to-end information about Subgraph in blockchain, starting from definition to benefits, use cases, and deployment methods. 

What is Subgraphs in blockchain?

Subgraphs in blockchain are data indexing solutions offered by the Graph protocol. Basically, Subgraph processes bulks of raw blockchain data and convert them into a readable format so that it can be easily queried via GraphQL language. Web3 projects, enterprises, and dApp developers can build their Subgraphs, deploy Subgraph to hosted service, or use the existing Subgraphs–whichever is feasible for them. But, there are some exceptions to Graph’s decentralized network. We will learn about those exceptions later in this article.

Understanding working of Subgraph

Below is the easy, step-by-step flow that explains the entire working of Subgraph in blockchain:

  1. Decentralized applications submit data to the blockchain via smart contract transactions.

  2. The smart contract can emit one or multiple events while processing this transaction.

  3. Subgraph constantly scans events on the blockchain and looks for the data relevant to your Subgraph’s schema.

  4. Whenever any new data is added, the indexing process on Subgraph is triggered, and it runs mapping. The indexing process includes updating the subgraph’s internal data structures to reflect the real-time on-chain data.

  5. Consumers query data from their Graph Node from the blockchain using the node’s GraphQL endpoint. At this point, Graph Node translates the GraphQL queries into structured data.

  1. Finally, the dapp displays queried data in a rich UI for end-users, which they can utilize for various purposes, e.g. issuing new transactions. The cycle repeats.

And, here’s a graphical representation:

Exploring top use cases of Subgraph in blockchain

DeFi applications: 

DeFi ecosystem is vast; hence, it produces tons of data daily, making it challenging for DeFi solutions to retrieve on-chain data. Subgraph allows all kinds of DeFi solutions– be it exchange, investment platform, or liquidity aggregators to retrieve real-time and historical data instantly via GraphQL calls. The data can range from token & account balances, liquidity pool status, transaction details, swap data, TVL- Total value locked, deposits, collateral ratios, etc. 

Kunji Finance– the decentralized crypto investment platform opted for Subgraph to tackle data indexing complexities,  such as hassle of managing heavy RPC infrastructure, challenges of self-hosting of a graph node (e.g maintaining high-cost engineering resources and downtime issues) lack of technical support, downtime & data lag, and more.  As a solution, Kunji chose Zeeve’s hosted subgraph that streamlined its data indexing operations, allowed more queries to be processed within the same timeframe, boosted query speed by 5x, offered 24/7 support from professional team, and provided all the tooling for subgraph monitoring and maintenance. 

Learn more: Role of Subgraphs in data indexing for DeFi applications.

Web3 gaming applications: 

Subgraph allow game applications to access specific and right data to develop next-gen, feature-rich games. With Subgraph, game applications enjoy faster data indexing, consistent data flow, superior uptime, the ecosystem for managing multiple subgraphs, customized queries, and a lot more benefits that allow seamless retrieval of game-specific data such as ownership of digital assets, token balances, details about characters and in-game arts, and governance-based data. 

Popular gaming projects like Decentraland, Reboot gaming, Aavegotchi, Decentral Games DG, Axolittles, and Nifty league have already deployed their Subgraph for leveraging benefits like fast retrieval of game-related data ( for example- characters’ contract addresses, content IDs, asset ownership details, etc), low-cost infrastructure management, 27/4 support, and more.

Discover more about how Subgraphs are eliminating challenges related to data indexing in gaming applications:

Understanding the role of Subgraphs in gaming application development

NFT and tokenized assets:

NFT-based dApps like marketplaces always need easy and fast access to blockchain data to offer seamless buying, selling, and investment of NFT-backed digital assets. Subgraphs allow NFT marketplaces to index and query varied data such as NFT metadata, digital assets’ ownership and transfer data, smart contract information, user authentication and verification data, royalties information, etc. 

Opensea Subgraph and Foundation Subgraph are two main projects. Opensea uses Subgraph to retrieve raw blockchain data and process it to get insightful, readable analytics. Whereas, Foundation Subgraph fetches NFT-related data such as a specific amount of NFTs minted, and marketplace’s live activity insights

DAOs:

Decentralized autonomous organizations, or DAOs, rely heavily on the data of various smart contracts for managing their decentralized governance mechanisms. For example, DAO may need to retrieve proposal data, voting data, members’ information, token holdings, financial data, governance events, and more. 

Endaoment, ENS Subgraph, MakerDAO Subgraph, and Snapshot Subgraph are the popular DAO projects that have overcome data indexing challenges with Subgraphs. These projects enjoy fast retrieval of DAO-related data like contract addresses, data regarding grants, proposals, voting, and governance events’ statistics.

Custom data analytics tool: 

By leveraging subgraphs, enterprises can build data analytics tools tailored to their dApps’ specific needs. Using this tool, data can be parsed through non-compiled blockchain databases, providing precise and highly usable data insights based on its custom Subgraph manifest. Let’s say, if your business is NFT-focused, you can customize your data analytics tool to query only NFT-related on-chain data. e.g. aggregated NFTs ownership of a user by its specific characteristics. 

Benefits of using Subgraph for web3 data querying 

Subgraph simplifies the process of querying on-chain data. Hence, they are beneficial for data consumers in multiple ways, such as: 

Simplicity of deployment and management:

Subgraphs are easy to set up and manage on the Graph network. Anyone can start by running a Graph node without special hardware, software, or other technical requirements. All you need is a Subgraph with clearly defined schema, manifest, and mappings to start querying web3 data. And, since Graph protocol is decentralized, there will be no outages due to a single point of failure. Hence, you can concentrate on building groundbreaking applications. 

Zero infrastructure setup cost: 

By deploying Subgraph, you eliminate the need to set up heavy data servers, backing up regularly, troubleshooting or any expensive engineering resources. Hence, your infrastructure cost declines to almost nil. Further, there will be no additional contracts and no monthly fees. Only, you will be charged for queries. 

Quick data retrieval for the fastest response: 
Compared to the JSON-RPC method of retrieving blockchain data, Subgraphs enable blazing-fast responses to every response via GraphQL API calls. Decentralized applications can get responses to their queries within seconds regardless of the volume of queries– which can be 30k to 30M per month. Further, Queries will not be interrupted due to redundancy or low synchronization. 

Option to custom your queries:

Queries on Subgraphs are fully customizable, which allows decentralized applications to retrieve very specific on-chain data seamlessly exactly similar to general-purpose queries. For example, if you want data other than existing Ethereum standards such as ERC-20, ERC-721, or ERC-1155, you can do so by modifying the mapping, schema, and manifest while creating the Subgraph itself. Projects like NFTs, gaming, and DAOs are often in need of custom data retrieval to add very specific functionality to their applications.

Support for diverse networks: 

Graph’s decentralized network currently supports Subgraph for all the popular networks, such as Ethereum, Polygon, Arbitrum, Avalanche, Gnosis Chain, and Celo. Also, Graph has a Hosted Service where a range of networks are supported, but it will sunset soon. Here, Zeeve can provide you with a solution. The hosted services at Zeeve supports all the networks supported at Graph.  And, for your preferred blockchain, Zeeve will setup custom data indexers, which can be dedicated or shared, as you need.  

Non-stop data flow with 100% uptime:

Deploying your Subgraph to Graph’s decentralized network means you get access to geographic redundancy, which is something not possible with self-hosting. All your Subgraph queries will be served reliably through hundreds of independent indexes that ensure 100% data flow and 99.9% uptime for superior performance.

How you can query data from Subgraph?

Following are the three different ways to use Subgraphs for Web3 data indexing and querying:

Option-1:  Build your own Subgraph in Subgraph Studio

You can also build your subgraph using Subgraph Studio and start retrieving data from it, if indexed. However, your subgraph will be available only when it adds value to the Graph network and attracts enough indexers, curators, and delegators. 

Option-2: Deploy to the hosted service: 

The Hosted service works like managed service. For this, you do not need a wallet, smart contract or Graph nodes. All you need is a GitHub account to create your Subgraph in a few steps and start querying the data because the infrastructure, delegation, indexing, and all the other things will be managed on Graph’s end. As discussed, Hosted Service from Graph will be unavailable soon. 

Option-3: Query data from Subraphs in Graph’s Explorer:

Not every project necessarily needs to build its own Subgraph. Instead, they can query blockchain data from the Subgraph explorer, such as Uniswap v3 Subgraph, Party Finance, and Carbon Subgraph. 

Want to read in-depth information about all these three options? Refer to our comprehensive guide below:

How to query Web3 data using The Graph Protocol and Subgraphs?

Deploy Subgraphs seamlessly with Zeeve’s hosted Subgraph Service

Zeeve offers a reliable hosted service to deploy and manage all your Subgraphs on an enterprise-grade infrastructure— optimized for low cost, superior performance, scalability, and security guaranteed with ISO 27001 and SOC 2 Type 2 compliance. Projects can build Subgraph from scratch or migrate from Graph’s hosted service since it will be unavailable soon.

So if you need indexed data for any of the public blockchains, your custom appchains, or rollup, you might need Subgraphs. Based on your requirements, you can opt for a shared indexer, dedicated indexer, or custom Subgraph development. Zeeve eliminates the hassle of managing nodes and getting delegators and indexers for your Subgraph because everything is managed by Zeeve. On top of this, your Subgraph will be monitored 24/7 to reduce the chance of downtime or performance-related issues. This initiative will reduce costs significantly while you can get benefits like 99.9% API SLA, up to 5x faster data indexing and 2x lower data lagging.

For more information on why Zeeve’s hosted Subgraph service is helpful, you can contact our experts anytime via mail or even schedule a one-to-one call for a detailed discussion. 

Zeeve logo
Subscribe to Zeeve and never miss a post.
#subgraphs#blockchain
  • Loading comments...