Ankr’s RPC Performance Advantage: Data Caching & Advanced APIs
April 26, 2023
7 min read
Powering ultra-fast multichain interactions with pre-stored data for the most popular requests – all available via a single endpoint.
When Web3 developers are asked about what matters most in their RPC service, the most common answers are speed and reliability. When it comes to speed, there are a variety of things Web3 infrastructure providers can do to optimize performance. However, there are three core areas that make a big impact on Ankr’s RPC API response times.
Three Keys To Improving Response Times
Making sure requests reach nodes fast: Quickly routing RPC requests to nodes that can serve them is the important job of load balancers.
Improving available node distribution and performance: Having full and archive nodes up and running around the world is important to reduce latency by serving RPC requests closer to users.
Have cached data ready and waiting for requests: Sometimes, it is possible for users’ blockchain requests to skip the process of querying nodes as the response has already been completed and stored (cached) for future use.
Data Caching & Ankr’s Advanced APIs Explained
Data caching in the context of Remote Procedure Call (RPC) requests refers to the practice of storing the results of requests temporarily in a cache so that if the same request is made again, the cached result can be returned almost instantaneously without having to recompute or fetch the data from remote nodes. This can significantly reduce latency and the traffic load for nodes, as well as improve the overall performance of decentralized applications, especially multichain apps.
Data caching can be thought of as a shortcut for requests to deliver their desired outcomes. We cache many query responses in our load balancing layer for fast turnaround on common requests of data close to the chaintip. On top of this, Ankr’s Advanced APIs index node responses for common archive data queries, which provide the fastest possible round-trip request times for large archive data queries. The data is stored according to response type, so it is ready for rapid delivery to clients, serving as an additional way to reduce request processing times in many scenarios.
Ankr’s Advanced APIs take blockchain data and optimize, index, and cache it to make it readily accessible, as well as combine multiple query results for specific use cases such as NFTs and Token data. The Advanced APIs support major EVM-compatible blockchains, so you can search once across several different blockchains at the same time, for example, to see the balance of your address and assets on Ethereum and Polygon in one query. You can start using Advanced API methods by using the single endpoint available below.
Get Started for Free and use all Advanced APIs with just one endpoint
An Analogy: The Efficient Librarian
To understand data caching simply, we can use an example of a physical library you might visit frequently to find books. You always go to the librarian and ask her for help in finding a specific book. She then writes down your book request on a note and travels up two flights of stairs to locate the book in the stacks, heads down the stairs, and back to you to deliver your book.
However, this is a very smart librarian, and she’s always thinking of ways she can speed this process up and avoid all those stairs. She’s formed a new habit of keeping notes of the most popular book requests. She then stashes copies of the most requested books in her “cache” under the front desk. This way, the next time you come in, she can hand you your requested books almost as soon as the words leave your mouth. Additionally, she keeps track of the most requested books from different libraries (different blockchains) and keeps those on hand as well. That way, your single request for information is returned in one response from each library automatically instead of needing to make the request each time per library (blockchain). These are the same principles Ankr’s Advanced APIs use to deliver data to clients faster.
How Ankr Used Advanced APIs To 5x Loading Speeds
Ankr is a unique company in that we are often the first to beta-test our own products. As soon as Ankr created our Advanced APIs, we put them to work for one of our products – Ankr Staking. The Ankr Staking dashboard lets users know where their assets stand, whether they are staked on the platform or held in their wallets. To have the front end properly populate all this information for users, it needs to get a history of events for everything that will affect the users’ balances. Here’s how Advanced APIs revamped this process:
The staking dashboard needed to perform in the realm of 1500 requests to update the front end in a process that took up to 60 seconds to load – a wait time that is less than ideal for user experience.
Ankr’s team implemented the Advanced API method ankr_getLogs to decrease the number of requests needed to just 100 thanks to the ability to query multiple chains at once with very fast response times.
Now, the dashboard loads in usually no longer than 10 seconds and optimally just 2-3, making a much better experience for all those using Ankr Staking.
Advanced API Methods
Ankr currently has three powerful Advanced APIs: NFT, Query, Token, as well as some Early Access queries that show the results of our R&D towards the increased utility of the API. All of these methods can be employed via a single endpoint as mentioned above: Below, you can explore each one of these APIs and how they work.
NFT API: Pull NFT Data Across Web3
Projects that integrate NFTs, like virtual worlds, decentralized games, galleries, marketplaces, and others, often need to pull data across a breadth of collections across chains, which can be a challenge. Ankr’s NFT API makes it simple. The API makes it easy to find the details about which collection an NFT belongs to, when it was minted, its past transaction history, who currently owns it, and much more.
The API can request NFT-related data (owners, listings for particular wallet addresses, collections, time of minting, transaction history, and other metadata) across several EVM-compatible chains at once with a single request.
Easily query NFT data across virtual worlds, games, chains, galleries, marketplaces, and more with the following methods:
- ankr_getNFTsByOwner — Retrieves a list of holders (wallet addresses) of the specified NFT.
- ankr_getNFTMetadata — Retrieves the metadata of to the specified NFT (ERC721/ERC1155/ENS/POAP).
- ankr_getNFTHolders — Retrieves a list of holders (wallet addresses) of the specified NFT.
Query API: Near-Instant Blockchain Data Retrieval
Query API is an access-ready solution that enables your projects to interact with multiple blockchains in a single request. By indexing blockchain data from all eight currently supported chains, searching through large amounts of data is easier and faster than ever before. Query API has almost instantaneous processing speeds (thanks to new key-value filtering) for searches that might ordinarily take hours to process. Query API serves to request info on the ranges of blocks (max range is 100) for a full list of block metadata.
Search a wide range of blocks across chains and get nearly instant results for addresses, events, block ranges, logs & other stats by using:
- ankr_getBlockchainStats – Retrieves blockchain statistics.
- ankr_getBlocks – Retrieves details of the specified range of blocks.
- ankr_getLogs – Retrieves historical data for the specified range of blocks.
- ankr_getTransactionsByHash – Retrieves details of the transaction specified by its hash.
- ankr_getInteractions – Retrieves a list of blockchains on which interactions (tokens, NFTs, transactions) were registered for the specified address.
Token API: Token Data at Your Fingertips
Ankr’s Token API helps deliver information about tokens on any of the currently supported chains. The Token API allows developers to query things like account balances, how many currencies exist on a given blockchain, how many token holders a given currency has, and a token’s current value.
Notably, our Token API uses on-chain data only, leaving third parties and potential inaccuracies behind. Ankr constantly scans for on-chain transactions coming from DEXs — flagging transactions and aggregating data into accurate token price feeds in real-time. These tools are crucial for Web3 projects like marketplaces and exchanges looking for efficient ways to query accurate, on-chain data for tokenized assets.
Query data for balances, currencies, token holders, and prices across blockchains with the following methods:
- ankr_getAccountBalance – Retrieves the balance of a particular account.
- ankr_getCurrencies – Retrieves a list of all currencies used on the specified blockchain.
- ankr_getTokenPrice – Retrieves the USD price of the specified token.
- ankr_getTokenHolders – Retrieves the metadata and a list of holders (wallet addresses) of the specified token.
- ankr_getTokenHoldersCount – Retrieves the number of holders of the specified token.