Compound is a decentralized protocol for the frictionless borrowing of Ethereum assets and a safe positive-yield approach to storing assets. By providing interest rate markets on the Ethereum blockchain, Compound allows users to earn interest on crypto that they’ve supplied to the lending pool. The team’s goal is to integrate the Compound protocol into many DeFi products across the globe, ensuring that all assets, when sitting idle, are moved into Compound and earning interest.
As the DeFi protocol has become increasingly popular, the Compound team has encountered infrastructure challenges around the DevOps time and costs to run nodes and ensure uninterrupted network availability. By using Infura’s Ethereum API and unifying requests, Compound has optimized the logistics of their node infrastructure and positioned the protocol to effectively handle recent historic spikes in network activity.
Compound initially handled all of the logistics of blockchain infrastructure, including running their own nodes in Kubernetes and making requests to the nodes, all by themselves. They tried running both Geth and Parity, but both applications hogged memory, bandwidth, and disk IO from their other containers in the cluster. With this setup, performing basic tasks—like pulling event logs from the blockchain—required a significant chunk of their DevOps' time. Additionally, they needed to constantly upgrade their nodes to maintain compatibility with network hard forks.
Solution: A More Efficient DeFi Infrastructure
Compound’s team decided to explore alternatives to running their own nodes and decided on Infura, both because of the team’s deep expertise in infrastructure engineering and because of the product’s ease-of-use. Infura’s API suite allowed the Compound team to abstract away a lot of the difficult parts of running and querying Ethereum nodes so they could focus their time and resources on product development instead. They are now using Infura’s Ethereum APIs in a variety of ways.
First, the Compound interface reads directly from Infura to pull all of the details of the Compound protocol and the user's account. This is beneficial because even if Compound servers have an issue, users can still access Compound through the interface. Second, they use Infura to power their API by querying all event logs from the blockchain and then pushing the event data into a stream processor. This allows them to simplify the systems that consume and present the data they read from Infura.
The team has also found unique ways to optimize their Infura usage. To gather each single piece of data from the blockchain for each single user would require a separate transaction for querying user's data. That can add up. Blockchain transactions cost money, as does querying an API service. To streamline their Infura usage, Compound has created a way to unify all of their requests on chain into one large request via a view contract. In other words, instead of pulling the user's balance in each supported asset, they create and deploy a contract that, given a user address, loops and returns all the balances for a user in a single Web3 call. Given the amount of data points required to populate a page, this can save a huge amount of round-trips to Infura.
In March, Compound saw historic volume of network activity in response to global market volatility, as did many other Ethereum protocols. Infura’s infrastructure support helped the team remain confident in the protocol’s resilience and focused on the next chapter of DeFi adoption.