Subgraphs in blockchain: Diving into Benefits, use cases, deployment, and more
Tags: subgraphs
Published: 2023-12-26 06:58:09

<p>We all know <a href="https://www.zeeve.io/subgraphs/">blockchain data indexing</a> 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, <a href="https://www.zeeve.io/subgraphs/">Subgraphs</a> is exactly what you need. Using Subgraph, decentralized applications can query their specific data easily from the blockchain’s massive databases.&nbsp;</p>
<p>This comprehensive Subgraph guide provides you with <a href="https://www.zeeve.io/blog/what-is-end-to-end-encryption-e2ee-explained-for-beginners/">end-to-end</a> information about <a href="https://www.zeeve.io/subgraphs/">Subgraph in blockchain</a>, starting from definition to benefits, use cases, and deployment methods.&nbsp;</p>
<h2 id="h-what-is-subgraphs-in-blockchain">What is Subgraphs in blockchain?</h2>
<p>Subgraphs in blockchain are <a href="https://www.zeeve.io/subgraphs/">data indexing</a> 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. <a href="https://www.zeeve.io/blog/rise-of-web3-with-5g-automated-era-with-5g-blockchain-metaverse-ai/">Web3 projects</a>, <a href="https://www.zeeve.io/enterprise-blockchain/">enterprises</a>, 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.</p>
<figure class="wp-block-image aligncenter size-large"><a href="https://www.zeeve.io/subgraphs/"><img src="https://www.zeeve.io/wp-content/uploads/2023/12/HOSTEDSUBGRAPH-1024x130.jpg" alt="" class="wp-image-52493"/></a></figure>
<h2 id="h-understanding-working-of-subgraph">Understanding working of Subgraph</h2>
<p>Below is the easy, step-by-step flow that explains the entire working of <a href="https://www.zeeve.io/subgraphs/">Subgraph in blockchain</a>:</p>
<li>Decentralized applications submit data to the blockchain via <a href="https://www.zeeve.io/blog/smart-contract-standardization-a-necessity-for-the-large-scale-adoption-of-blockchain/">smart contract</a> transactions.<br></li>
<li>The smart contract can emit one or multiple events while processing this transaction.<br></li>
<li><a href="https://www.zeeve.io/subgraphs/">Subgraph</a> constantly scans events on the blockchain and looks for the data relevant to your Subgraph’s schema.<br></li>
<li>Whenever any new data is added, the indexing process on <a href="https://www.zeeve.io/subgraphs/">Subgraph</a> 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.<br></li>
<li>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.</li>
<li>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.</li>
<p>And, here’s a graphical representation:</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gwfl4zlzxjp79msyquve.png)
<h2 id="h-exploring-top-use-cases-of-subgraph-in-blockchain">Exploring top use cases of Subgraph in blockchain</h2>
<h3>DeFi applications:&nbsp;</h3>
<p><a href="https://www.zeeve.io/blog/blockchain-bridges-helping-the-growth-of-defi">DeFi ecosystem</a> is vast; hence, it produces tons of data daily, making it challenging for DeFi solutions to retrieve on-chain data. <a href="https://www.zeeve.io/subgraphs/">Subgraph</a> allows all kinds of <a href="https://www.zeeve.io/blog/blockchain-bridges-helping-the-growth-of-defi">DeFi solutions</a>- 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 &amp; account balances, liquidity pool status, transaction details, swap data, TVL- Total value locked, deposits, collateral ratios, etc.&nbsp;</p>
<p>Kunji Finance– the decentralized crypto investment platform opted for Subgraph to tackle data indexing complexities,&nbsp; such as hassle of managing heavy <a href="https://www.zeeve.io/blog/how-to-connect-to-my-ec2-geth-node-with-json-rpc/">RPC infrastructure</a>, challenges of self-hosting of a graph node (e.g maintaining high-cost engineering resources and downtime issues) lack of technical support, downtime &amp; data lag, and more.&nbsp; As a solution, Kunji chose <a href="https://www.zeeve.io/subgraphs/">Zeeve’s hosted subgraph</a> 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.&nbsp;</p>
<p>Learn more: <a href="https://www.zeeve.io/blog/how-defi-applications-can-benefit-using-subgraphs-for-data-indexing/">Role of Subgraphs in data indexing for DeFi applications</a>.</p>
<h3>Web3 gaming applications:&nbsp;</h3>
<p><a href="https://www.zeeve.io/subgraphs/">Subgraph</a> allow game applications to access specific and right data to develop next-gen, feature-rich games. With Subgraph, game applications enjoy faster <a href="https://www.zeeve.io/subgraphs/">data indexing</a>, 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 <a href="https://www.zeeve.io/blog/tokenization-of-assets-how-blockchain-is-rewriting-asset-management/">digital assets</a>, token balances, details about characters and in-game arts, and governance-based data.&nbsp;</p>
<p>Popular gaming projects like Decentraland, Reboot gaming, Aavegotchi, Decentral Games DG, Axolittles, and Nifty league have already deployed their <a href="https://www.zeeve.io/subgraphs/">Subgraph</a> 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.</p>
<p>Discover more about how <a href="https://www.zeeve.io/subgraphs/">Subgraphs</a> are eliminating challenges related to data indexing in <a href="https://www.zeeve.io/blog/how-web3-will-change-the-gaming-industry/">gaming applications</a>:</p>
<p><a href="https://www.zeeve.io/blog/role-of-subgraphs-in-gaming-application-development/"><strong>Understanding the role of Subgraphs in gaming application development</strong></a></p>
<h3>NFT and tokenized assets:</h3>
<p>NFT-based dApps like marketplaces always need easy and fast access to blockchain data to offer seamless buying, selling, and investment of NFT-backed <a href="https://www.zeeve.io/blog/tokenization-of-assets-how-blockchain-is-rewriting-asset-management/">digital assets</a>. <a href="https://www.zeeve.io/subgraphs/">Subgraphs</a> allow <a href="https://www.zeeve.io/blog/a-simple-and-comprehensive-guide-on-non-fungible-tokens/">NFT marketplaces</a> to index and query varied data such as NFT metadata, <a href="https://www.zeeve.io/blog/tokenization-of-assets-how-blockchain-is-rewriting-asset-management/">digital assets</a>’ ownership and transfer data, <a href="https://www.zeeve.io/blog/smart-contract-standardization-a-necessity-for-the-large-scale-adoption-of-blockchain/">smart contract information</a>, user authentication and verification data, royalties information, etc.&nbsp;</p>
<p>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</p>
<h3>DAOs:</h3>
<p><a href="https://www.zeeve.io/blog/what-is-dao-decentralized-autonomous-organization/">Decentralized autonomous organizations</a>, or DAOs, rely heavily on the data of various <a href="https://www.zeeve.io/blog/smart-contract-standardization-a-necessity-for-the-large-scale-adoption-of-blockchain/">smart contracts</a> 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.&nbsp;</p>
<p>Endaoment, ENS Subgraph, MakerDAO Subgraph, and Snapshot Subgraph are the popular <a href="https://www.zeeve.io/blog/what-is-dao-decentralized-autonomous-organization/">DAO projects</a> 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.</p>
<h3>Custom data analytics tool:&nbsp;</h3>
<p>By leveraging <a href="https://www.zeeve.io/subgraphs/">subgraphs</a>, 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 <a href="https://www.zeeve.io/subgraphs/">custom Subgraph</a> 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.&nbsp;</p>
<h2 id="h-benefits-of-using-subgraph-for-web3-data-querying">Benefits of using Subgraph for web3 data querying&nbsp;</h2>
<p><a href="https://www.zeeve.io/subgraphs/">Subgraph</a> simplifies the process of querying on-chain data. Hence, they are beneficial for data consumers in multiple ways, such as:&nbsp;</p>
<p><strong>Simplicity of deployment and management:</strong></p>
<p><a href="https://www.zeeve.io/subgraphs/">Subgraphs</a> 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.&nbsp;</p>
<p><strong>Zero infrastructure setup cost:&nbsp;</strong></p>
<p>By <a href="https://www.zeeve.io/subgraphs/">deploying Subgraph</a>, 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.&nbsp;</p>
<p><strong>Quick data retrieval for the fastest response:&nbsp;</strong><br>Compared to the <a href="https://www.zeeve.io/blog/how-to-connect-to-my-ec2-geth-node-with-json-rpc/">JSON-RPC method</a> 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.&nbsp;</p>
<p><strong>Option to custom your queries:</strong></p>
<p>Queries on <a href="https://www.zeeve.io/subgraphs/">Subgraphs</a> 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 <a href="https://www.zeeve.io/blog/introduction-to-token-standards-erc-20-erc-721-erc-777-and-erc-1155/">ERC-20, ERC-721, or ERC-1155</a>, you can do so by modifying the mapping, schema, and manifest while creating the Subgraph itself. Projects like <a href="https://www.zeeve.io/blog/a-simple-and-comprehensive-guide-on-non-fungible-tokens/">NFTs</a>, <a href="https://www.zeeve.io/blog/blockchain-in-gaming-industry-better-virtual-gaming-experiences/">gaming</a>, and <a href="https://www.zeeve.io/blog/what-is-dao-decentralized-autonomous-organization/">DAOs</a> are often in need of custom data retrieval to add very specific functionality to their applications.</p>
<p><strong>Support for diverse networks:&nbsp;</strong></p>
<p>Graph’s decentralized network currently supports <a href="https://www.zeeve.io/subgraphs/">Subgraph</a> for all the popular networks, such as <a href="https://www.zeeve.io/blockchain-protocols/deploy-ethereum-blockchain/">Ethereum</a>, <a href="https://www.zeeve.io/blockchain-protocols/deploy-polygon-blockchain/">Polygon</a>, <a href="https://www.zeeve.io/blockchain-protocols/deploy-arbitrum-node/">Arbitrum</a>, <a href="https://www.zeeve.io/blockchain-protocols/deploy-avalanche-node/">Avalanche</a>, Gnosis Chain, and Celo. Also, Graph has a Hosted Service where a range of networks are supported, but it will sunset soon. Here, <a href="https://www.zeeve.io/">Zeeve</a> can provide you with a solution. The hosted services at <a href="https://www.zeeve.io/">Zeeve</a> supports all the networks supported at Graph.&nbsp; And, for your preferred blockchain, <a href="https://www.zeeve.io/">Zeeve</a> will setup custom data indexers, which can be dedicated or shared, as you need.&nbsp;&nbsp;</p>
<p><strong>Non-stop data flow with 100% uptime:</strong></p>
<p><a href="https://www.zeeve.io/subgraphs/">Deploying your Subgraph</a> 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.</p>
<h2 id="h-how-you-can-query-data-from-subgraph"><strong>How you can query data from Subgraph?</strong></h2>
<p>Following are the three different ways to use <a href="https://www.zeeve.io/subgraphs/">Subgraphs</a> for Web3 data indexing and querying:</p>
<p><strong>Option-1:&nbsp; Build your own Subgraph in Subgraph Studio</strong></p>
<p>You can also build your <a href="https://www.zeeve.io/subgraphs/">subgraph</a> 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.&nbsp;</p>
<p><strong>Option-2: Deploy to the hosted service:&nbsp;</strong></p>
<p>The Hosted service works like managed service. For this, you do not need a wallet, <a href="https://www.zeeve.io/blog/smart-contract-standardization-a-necessity-for-the-large-scale-adoption-of-blockchain/">smart contract</a> 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.&nbsp;</p>
<p><strong>Option-3: Query data from Subraphs in Graph’s Explorer:</strong></p>
<p>Not every project necessarily needs to build its own <a href="https://www.zeeve.io/subgraphs/">Subgraph</a>. Instead, they can query blockchain data from the Subgraph explorer, such as Uniswap v3 Subgraph, Party Finance, and Carbon Subgraph.&nbsp;</p>
<p>Want to read in-depth information about all these three options? Refer to our comprehensive guide below:</p>
<p><a href="https://www.zeeve.io/blog/how-to-query-web3-data-using-the-graph-protocol-and-subgraphs/"><strong>How to query Web3 data using The Graph Protocol and Subgraphs?</strong></a></p>
<h2 id="h-deploy-subgraphs-seamlessly-with-zeeve-s-hosted-subgraph-service">Deploy Subgraphs seamlessly with Zeeve’s hosted Subgraph Service</h2>
<p><a href="https://www.zeeve.io/">Zeeve</a> offers a reliable hosted service to deploy and manage all your <a href="https://www.zeeve.io/subgraphs/">Subgraphs</a> 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.</p>
<p>So if you need indexed data for any of the public blockchains, your <a href="https://www.zeeve.io/appchains/">custom appchains</a>, or <a href="https://www.zeeve.io/rollups/">rollup</a>, you might need <a href="https://www.zeeve.io/subgraphs/">Subgraphs</a>. Based on your requirements, you can opt for a shared indexer, dedicated indexer, or custom Subgraph development. <a href="https://www.zeeve.io/">Zeeve</a> eliminates the hassle of managing nodes and getting delegators and indexers for your Subgraph because everything is managed by <a href="https://www.zeeve.io/">Zeeve</a>. 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.</p>
<p>For more information on why <a href="https://www.zeeve.io/subgraphs/">Zeeve’s hosted Subgraph service</a> is helpful, you can contact our experts anytime via mail or even <a href="https://www.zeeve.io/talk-to-an-expert/">schedule a one-to-one call</a> for a detailed discussion.&nbsp;</p>