Substreams-powered Subgraphs: Enabling faster data indexing for dApps
Tags: subgraphs
Published: 2023-12-27 09:12:09

<p>The Graph network is already a substantially grown, powerful, and new-age data indexing network. However, the core developer team at Graph continues to improve its existing capabilities, taking <a href="https://www.zeeve.io/subgraphs/">Subgraph’s blockchain data indexing</a> capabilities to the next level. Their recent addition is Substream-powered Subgraph, firehose-enabled technology for faster data indexing, complete with high-performance and query parallelization in a streaming-first method.&nbsp;</p>
<p>This article explains all the essential details about Substreaming-powered Subgraph, including basics working, key features, setup method, and more.</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/dedicated-data-indexers-1-1024x130.jpg" alt="" class="wp-image-53383"/></a></figure>
<h2 id="h-what-are-substreams-powered-subgraphs">What are Substreams-powered Subgraphs?</h2>
<p>Substream-powered Subgraphs are advanced <a href="https://www.zeeve.io/subgraphs/">data indexing solutions</a> designed to accommodate the existing capabilities of The Graph Network. It provides data consumers or web3 applications with a familiar GraphQL API with Substream modules integrated as data sources. However, to deploy a Substream-powered Subgraph, developers need a Firehose-enabled node. Further, they must write custom Rust modules to compose relevant data streams for specific extraction.&nbsp;&nbsp;</p>
<p>Substream supports <a href="https://www.zeeve.io/subgraphs/">data indexing</a> from all kinds of <a href="https://zeeve.io/blockchain-protocols/">blockchain networks</a> like <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-zksync-era-node/">zkSync Era</a>, Optimism Goerli, and <a href="https://www.zeeve.io/blockchain-protocols/deploy-arbitrum-node/">Arbitrum</a> at lightning speed. Substream is an independent <a href="https://www.zeeve.io/subgraphs/">blockchain data indexing technology</a> now supported on the Graph network’s <a href="https://www.zeeve.io/subgraphs/">Subgraph</a>. Since the Streaming-based Subgraph is new, there is some confusion around it. Let’s address them:</p>
<h3>What exactly is a Substream-based Subgraph :&nbsp;</h3>
<li>A streaming-first technology powered by gRPC, StreamingFast Firehose, and Protobuf..</li>
<li>Framework for offering highly cacheable and remote, parallelizable code execution.</li>
<li>Ecosystem for supporting the development of higher-order composable modules and individual modules.</li>
<h2 id="h-who-needs-substreams-powered-subgraphs">Who needs Substreams-powered Subgraphs?</h2>
<p>Substream-powered Subgraphs are mostly suited for web3 applications such as gaming apps, DEXs, wallets, or aggregators that require seamless access to accurate, up-to-dated blockchain data. Here, standard <a href="https://www.zeeve.io/subgraphs/">Subgraphs</a> can also be a feasible option, but it takes around time for syncing blockchain data. Substream subgraph reduces this period considerably. That means if your project needs extremely faster indexing time, then Substream is preferred. Otherwise, <a href="https://www.zeeve.io/subgraphs/">Subgraphs</a> are the way to go.</p>
<p>A good example is Uniswap-v3 Substream-powered Subgraph. Uniswap which has built <a href="https://www.zeeve.io/subgraphs/">Subgraph</a> to be leveraged for its liquid staking solution– Lido. Traditionally, Uniswap has to wait for around 2 months (1440 hours) to sync the data. Now, with Substream, the process is being completed in 20 hours- This shows a 72x increase in speed.</p>
<h2>How do Substreams-based Subgraphs enable faster data indexing?</h2>
<p>Substream subgraphs have a range of next-gen features and functionalities for allowing rapid-fast <a href="https://www.zeeve.io/subgraphs/">blockchain data indexing</a>. The main feature is Firehouse, which replaces the traditional linear indexing model of RPC-based Subgraphs with stream-based data queryability. Further, Firehose is optimized to tackle the data indexing challenges created by EIP-4444. Developers utilizing a Substream-powered subgraph can leverage the fastest data synchronization, which is more than 100x better. To enable this, Substreams breaks the data pipeline into four states:</p>
<li>Extract (using Firehouse)</li>
<li>Transform (using Substream-based Subgraph)</li>
<li>Load (to Postgres database)</li>
<li>Query (serving users’ queries)</li>
<p><a href="https://www.zeeve.io/subgraphs/">Subgraph</a> does the above process with its three core components— subgraph.yaml, mappings, and schema.graphql.&nbsp;</p>
<p>Below is the graphical representation of Subsreams Graph’s various modules that allow it to extract blockchain data:</p>

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s4lb6i47bpdc0z1g20rf.png)
<li>First, there’s the source– block, which is the input for the map_transfers module.</li>
<li>One map module receives data, maps filters, and feeds the data to the downward modules– store_balances and store_total_supply.</li>
<li>At the end, the graph_out module will feed the data to the Subgraph store., The rest of the two modules, map_accounts and map_block_total_supply_change, show how to use store modules, which means they are functions of the store.</li>
<p>That was all about Streaming Subgraph’s modules and working. Now let’s discuss its main features that enable faster data indexing:</p>
<h3>Support for RPC Poller:</h3>
<p>StreamingFast has introduced a novel technology for data extraction called RPC poller. This feature is now supported on Streaming-powered Subgraphs, complementing Substream, The Graph network, and Firehose's existing capabilities, allowing chains to index data 10x faster. To achieve this, the RPC poller uses standard <a href="https://www.zeeve.io/blog/how-to-connect-to-my-ec2-geth-node-with-json-rpc/">JSON-RPC</a> endpoints that are defined through <a href="https://www.zeeve.io/blockchain-protocols/deploy-ethereum-blockchain/">Ethereum</a> execution API with no requirement for additional tooling.</p>
<h3>Advanced parallelization technique:&nbsp;</h3>
<p>Substream-based Subgraph utilizes a unique parallelization technique for enabling fast and efficient processing of blockchain data, providing filtered data to different data stores and real-time applications.</p>
<h3>Streaming-fast approach:&nbsp;</h3>
<p>Substreams inherit all the benefits from <a href="https://firehose.streamingfast.io/" rel="nofollow">StreamingFast Firehose</a>, &nbsp;such as low-cost caching, high throughput processing, archiving blockchain data, and cursor-based reorgs handling. Firehose is an independent service that extracts data seamlessly as per various chain-specific extensions, for example- Ethereum’s <strong>eth_calls</strong>.</p>
<h3>Horizontal scaling features:</h3>
<p>With the ability to be horizontally scalable, the Substream-powered Subgraph can reduce the overall data processing time by adding more computing power or advanced machines.</p>
<h3>Composable Substreams modules:</h3>
<p>Unlike RPC-Subgraph, which listens to blocks, Substream-powered Subgraph uses Rust modules that offer hooks to the Substream’s data execution engine. Each module can have more than one input, either in the form of a map, store, block, or clock object coming from the blockchain’s data source.&nbsp;</p>
<h3>Data modeling and integration:</h3>
<p>Substream-based Subgraph utilizes Google Protocol Buffers in various programming languages. Protocol Buffers or protobufs are basically APIs for data models specific to be used for the different <a href="https://www.zeeve.io/blockchain-protocols/">blockchains</a>. While writing the manifest for your <a href="https://www.zeeve.io/subgraphs/">Subgraph</a>, you need to add references to the protobufs that will serve the module.</p>
<h2 id="h-benefits-of-substreams-powered-subgraphs-for-web3-developers">Benefits of Substreams-powered Subgraphs for Web3 Developers</h2>
<p>Substream Subgraphs offers a list of benefits for developers using The Graph Network, including:</p>
<li><strong>Lightening fast indexing</strong>- Substreams optimize the <a href="https://www.zeeve.io/subgraphs/">data indexing</a> speed through large-scale clusters running parallel (like BigQuery). Plus, it uses a prototype created by StreamingFast– Sparkle that can reduce the sync time to approximately 6 hours and scale across all the different chains’ Subgraphs.</li>
<li><strong>Easy composability</strong>-&nbsp; Developers can stack modules like LEGO blocks while also being able to build upon the community modules, refining the blockchain’s data.&nbsp;</li>
<li><strong>Sink anywhere:</strong> Sink data to your preferred place– for example, you can add it to PostgreSQL, MongoDB, Kafka, <a href="https://www.zeeve.io/subgraphs/">subgraphs</a>, flat files, or simply in Google Sheets.<br></li>
<li><strong>Programmability:</strong> Substream offers you the flexibility to customize and automate the data extraction, such as transformation-time aggregations for modeling the data outputs for multiple sinks.<br></li>
<li><strong>Benefits of the Firehose:</strong> As obvious, the Substream-powered Subgraph has all the benefits of Firehose, including the lowest latency, higher availability, no polling, data sinking to flat files, and the option to use the best data model.&nbsp;</li>
<h2 id="h-subgraphs-and-substream-powered-subgraph-which-one-should-you-choose">Subgraphs and Substream-powered Subgraph– which one should you choose?</h2>
<p>When choosing between Substreams and <a href="https://www.zeeve.io/subgraphs/">Subgraphs</a>, you must know their main differences, which are mentioned below:</p>
<li>Substreams modules are written in RUST, whereas Subgraph manifests are written in AssemblyScript.</li>
<li>Substream initiates ‘stateless’ requests via gRPC. <a href="https://www.zeeve.io/subgraphs/">Subgraphs</a> require persistent deployments.</li>
<li>Substream requires a gRPC connection, allowing you to have full control of the output message, while Subgraph uses GraphQL calls.</li>
<li>With Substream, you do not get a long–term database for storage, whereas Subgraph stores all the data persistently in Postgres.</li>
<li>Substream allows data to be consumed in real-time with its fork-aware model. Speaking about Subgraphs, they can be consumed via GraphQL and polling for ‘real-time’.&nbsp;</li>
<p>Now that you know the basics of Substream vs. Subgraph, here’s a simple explanation to help you choose one:</p>
<p>Both the standard <a href="https://www.zeeve.io/subgraphs/">Subgraph</a> and streaming-based Subgraphs offer distinct benefits, tailored for specific use cases. Like, Substreams offer extremely fast data indexing through parallelization and live-streaming capabilities for both the historical and real-time data requirements. If you index the same historical data with Subgraphs, it will take much time, maybe months.&nbsp; However, building a Substream-powered Subgraph is difficult. You have to setup a whole new set of infrastructure, write rust modules with node-js, and manage firehose-enabled <a href="https://www.zeeve.io/blog/how-to-deploy-a-blockchain-node-in-minutes-zeeve/">blockchain nodes</a>.</p>
<p>With <a href="https://www.zeeve.io/subgraphs/">Subgraphs</a>, you just need to write manifest, do mappings, add schema and your Subgraph is ready for deployment. That’s because subgraph fetches data from archived nodes via <a href="https://www.zeeve.io/blog/how-to-connect-to-my-ec2-geth-node-with-json-rpc/">JSON-RPC</a> method, which is easy for most developers. For a conclusion, we can say that Substreams and Subgraphs, both are suitable based on your use case-specific requirements, hence analyze all your requirements well to make an informed decision.&nbsp;</p>
<h2 id="h-launch-your-subgraph-easily-with-zeeve">Launch your Subgraph easily with Zeeve</h2>
<p><a href="https://www.zeeve.io/">Zeeve</a> offers a comprehensive stack for seamless <a href="https://www.zeeve.io/subgraphs/">deployment of custom Subgraphs</a> on its <a href="https://www.zeeve.io/">enterprise-grade infrastructure</a>. Whether you want to build a custom, single-use Subgraph or you want to <a href="https://www.zeeve.io/subgraphs/">deploy your subgraph</a> on a shared infrastructure for per-subgraph pricing model— <a href="https://www.zeeve.io/">Zeeve</a> offers you flexibility in deployment options. As required, you can opt for general-use or <a href="https://www.zeeve.io/subgraphs/">application-specific Subgraphs</a>.</p>
<p>Since Zeeve offers managed service, you do not have to do the heavy lifting of managing Graph nodes, delegating tokens to indexers or curators, or programming modules or manifests. Everything will be handled by <a href="https://www.zeeve.io/">Zeeve</a>. With Zeeve’s hosted service, <a href="https://www.zeeve.io/case-study/kunji-finance/">Kunji Finance</a>– a crypto investment platform has witnessed benefits like high-speed data indexing, hassle-free infrastructure management, streamlined operations, and a major reduction in <a href="https://www.zeeve.io/subgraphs/">subgraph deployment</a> and management costs.<br>For more information on how <a href="https://www.zeeve.io/">Zeeve</a> is simplifying Subgraph-based services or to discuss your requirements, talk to our experts in <a href="https://www.zeeve.io/subgraphs/">blockchain data indexing</a>. You can drop your queries via email or <a href="https://www.zeeve.io/talk-to-an-expert/">schedule a one-on-one call</a> for a detailed discussion.</p>