erpc

How eRPC slashed Moonwell RPC calls by 67%

Moonwell is an open and decentralized lending and borrowing protocol built on Base, Optimism, Moonbeam, and Moonriver. We utilized eRPC to reduce RPC requests by two-thirds, thereby enhancing operational efficiency and significantly lowering costs.

Moonwell.fi Logo
eRPC Logo

Challenges

Moonwell relies heavily on real-time data to provide users with accurate information about their assets and the broader market. Our application performs numerous multicalls and background polling every few seconds to update data across dozens of smart contracts and user wallets. This involves fetching the balanceOf all collateral and underlying tokens for various markets, resulting in a staggering number of RPC requests. The high volume of these requests not only posed technical challenges but also led to significant RPC costs, impacting our operational efficiency.

Setup

To address these challenges, we adopted eRPC with the following infrastructure setup:

In-Memory Cache Implementation

We utilized eRPC in-memory cache, setting a maximum of 10 million items. This shift significantly improved data retrieval speeds, aligning better with our application real-time requirements.

Distributed Deployment for Low Latency

Our deployment strategy was pivotal in ensuring low-latency access for users worldwide. We utilized Railway, a container hosting service, to deploy eRPC instances across four strategic regions:

  • United States: West and East Coast
  • Europe: Amsterdam
  • Asia: Singapore

Each region hosts a single eRPC instance, ensuring that users are served from the nearest geographical location. To manage traffic efficiently, we employed a Cloudflare load balancer with dynamic traffic steering. This setup routes users to the closest eRPC instance based on real-time latency measurements from health checks, ensuring optimal performance.

Infrastructure diagram 1
Infrastructure diagram 2

Results

Implementing eRPC has yielded impressive results for Moonwell:

  • Reduction in RPC Requests/Costs: Prior to eRPC integration, our application made approximately 1.2 billion upstream RPC requests per month. With eRPC, we expect to reduce this number to less than 400 million RPC requests this month. This dramatic decrease not only streamlines our operations but also significantly lowers associated costs.
  • Data Egress Costs: The primary cost driver post-implementation has been data egress, currently amounting to around 5 TB per month. While this is a considerable expense, the reduction in RPC requests more than compensates for it, leading to overall cost efficiency.
  • Enhanced Data Handling: One of the standout benefits of eRPC is its ability to multiplex requests for the same data into a single upstream request. This optimization reduces redundant data fetching and improves overall system responsiveness. Additionally, while we employ multicall extensively, which inherently limits the benefits of batching, eRPC still contributes to performance gains through its intelligent request handling.
Infrastructure diagram 2