Optimizing blockchain infrastructure: Adding a dedicated API service for RPC requests

Isidro Vega Bresciano
6 min readJun 26, 2023

--

With the increasing adoption of web3, thousands of smart contracts, transactions, applications make millions of requests daily to the blockchain nodes to retrieve the information they require and permanently store the information.

Blockchain nodes are a central part of this new era, as they are in charge of validating, storing, and informing all the transactions, contracts and activities executed by decentralized applications (dApps).

With the increase in adoption, it became crucial for blockchains to start separating the activities executed by the nodes related to the basic tasks from supporting activities, such as serving the information required by the applications.

In this article we are going to describe why it is a good idea to have a dedicated RPC service associated with blockchain nodes, in order to improve not just the performance of the public nodes, but also the developer’s experience when developing new applications.

Blockchain nodes activities

The main activities executed by blockchain nodes can be separated in two main groups, both group of activities are essential:

Core activities:

  • consensus: to ensure agreement and validity of transactions across the network.
  • transaction validation: nodes are responsible for validating incoming transactions, ensuring that transactions are authentic and compliant with the blockchain’s protocol.
  • blockchain validation and propagation: once a set of transactions is validated, and a new block is created, it is propagated to other nodes in the network.
  • mining (on proof of work blockchains): nodes solve complex mathematical puzzles to create new blocks and append them to the blockchain. This takes significant computational resources.

Side activities:

  • network connectivity and peer-to-peer communication: nodes maintain communication with other nodes in the network, exchanging information about transactions, blocks, and consensus-related messages.
  • storage and maintenance of blockchain data: each node stores a copy of the blockchain’s data, keeping it synchronized with the network.
  • RPC API services: these services enable external applications to interact with the blockchain, by allowing them to retrieve information and submit transactions.

RPC services

Decentralized applications need to interact with the blockchain in order to retrieve information, such as transactions and logs, as well as writing and executing smart contracts, and this interaction is done via Remote Procedure Call (RPC).

RPC is a type of API (Application Programming Interface) that allows developers to run code that can be executed on servers remotely. It is essential to build decentralized applications and projects, as they need to access the blockchain. For instance, when users access a Decentralized Exchange or use a wallet such as MetaMask to make transactions, check their wallet balances, etc., their requests go through the RPC API to connect them with the blockchain nodes.

This implies that applications access information like block numbers, node connections, transactions, and historical blockchain data by making millions of requests, meaning that the nodes are being used to access and retrieve massive amounts of information on top of the core mining and consensus activities, which already are computing intensive.

In addition to that, the fact that blockchain nodes have to respond to RPC requests opens the door to security vulnerabilities, as someone could intentionally overload the node by making millions of requests to specific methods, activity known as a denial of service attack (DoS).

So with the development of more decentralized applications, it became crucial to separate the node’s core activities from the data retrieval activities, and in fact, many public nodes choose to block RPC calls to avoid having to deal with that burden.

Separating nodes main roles

In order to take activities such as historical data retrieval out of the nodes, there are ways to approach this separation, and leave the public nodes for the core activities only.

The first approach is that developers run their own node with restricted access to RPC methods to their applications only. This means that they can have unrestricted access to transactions and information on a stable node, which is also synced with the other nodes in the ecosystem, but with the disadvantage that running a node requires a lot of work unrelated to smart contract development, while it also increases the cost and time required to have a minimum viable product.

The second approach is to have a dedicated service that can handle information requests in a more convenient way, by having a specific API with a dedicated database with all the blockchain’s transactions and events to quickly respond to dApps requests.

By doing that, it is possible to safeguard the stability of the node, respond faster to information requests, reduce latency and improve the overall user experience, taking care of the overall performance of the node. For example, by implementing this approach, response times can be 4 times faster than querying directly from the node, and with even better results when caching is implemented.

On the security side, it allows to isolate the public nodes from specific attacks and add additional security layers, as well as specific filters and limits on the queries.

Importance of RPC API services for dApp development

In the initial stages of development, it is crucial for developers to have easy access to an RPC service rather than setting up and maintaining their own node, which can take weeks just to set it up and synchronize. This offers significant benefits, enabling developers to streamline their development process, reduce overhead costs, and focus on innovation, while being able to quickly prototype and experiment with different functionalities and use cases.

For this reason, some private companies like Alchemy, Ankr, and Infura stepped out to fulfill the need, by developing RPC APIs as a service for developers. This allows not just to take the burden of serving transaction data and logs out of the nodes, but also streamlines the initial stages of the development process, as developers can opt to use these services at the beginning, and once the dApp is in production, they could choose either to run their own node or keep using these services. As an example, Metamask uses Infura as RPC service provider, although it can easily be changed by the user of the wallet for its preferred service.

In the case of Rootstock, the service providers that currently have the service are NowNodes, Get Block, Blockscout and Covalent. While NowNodes and Get Block offer the same Ethereum RPC methods for Rootstock on Mainnet, BlockScout and Covalent offer custom methods through their Unified API. Also soon there will be more alternatives for fulfilling RPC API requirements and helping developers to streamline their development process into the Rootstock ecosystem.

Conclusion

Implementing a separate RPC API service for retrieving blockchain information offers numerous advantages in terms of performance and security for the blockchain ecosystem, as well as a streamlined development process, providing an easier onboarding process for developers into smart contracts development on the blockchain’s ecosystem.

By maintaining a dedicated database and providing an API that mirrors the node’s data, it is possible to achieve a clear separation of concerns, allowing public nodes to focus on critical tasks, and with enhanced performance, increased security, and improved scalability, a separate RPC service becomes a vital component in building robust and efficient blockchain networks.

--

--