Game changing optimization, right under our noses
If you build in web3, you need to test your decentralized applications. But testing on actual networks costs a lot of money. So web3 builders use testnets like Goerli, where it’s free to transact and validate behavior using testnet tokens.
To get testnet tokens, you need faucets. Faucets are a critical service that “drip” free testnet tokens to builders, so they can build on testnets like Goerli or Mumbai.
At Alchemy, our mission is to bring web3 to a billion people, especially these builders. So we built faucets that make it easier for developers to build, bringing unprecedented testnet token access to all developers, while simplifying and evangelizing development in web3.
The Goerli and Mumbai faucets currently serve so much traffic that running the faucets costs Alchemy multiple millions of dollars per year. But we recently realized a 300x cost savings, totaling over $3M a year saved.
How, you ask?
Using Alchemy Notify and the Alchemy SDK… our own products… right underneath our noses.
Read 👇 to learn how we optimized the faucets. Use our techniques to optimize your apps, too.
Problem: Excessive (and expensive) JSON-RPC calls
The two main problems with how we ran are faucets were:
- Excessive getTransactionReceipt calls
- Utilization of a legacy web3 library
Given the daily volume of faucet requests, the total number of RPC calls to our nodes added up fast.
Let’s dive into each problem.
1. No notification system to confirm mined transactions
Every time a user requested Goerli ETH (GETH) or Mumbai MATIC, we consecutively called getTransactionReceipt until the transaction was confirmed as mined, often requiring many calls to getTransactionReceipt per single user request.
With nominal faucet traffic, and without a legacy web3 library bug, this model would have been extremely silly, but not exorbitant.
We would have sent, on average, ~16 calls to getTransactionReceipt every time a user requested tokens from the faucet.
2. Using a legacy web3 library
Our service was using a legacy web3 library that, unbeknownst to us, had a bug. Even after confirming a successful transaction, the system would continue to call our nodes, drastically increasing the total number of (unnecessary) calls to getTransactionReceipt.
Solution: Alchemy Notify and the Alchemy SDK
The two main solutions we implemented to reduce expensive JSON-RPC calls to our nodes were:
- Replaced getTransactionReceipt calls with Alchemy Notify's webhook notifications
- Replaced the legacy web3 library with the Alchemy SDK
1. Migrating to Alchemy Notify
We have abandoned calling the raw getTransactionReceipt method, and started using Alchemy Notify’s webhooks to get real-time notifications when transactions are mined and dropped. With zero outbound calls, notifications are sent directly to us when users successfully receive GETH.
2. Upgrading to the Alchemy SDK
We migrated from the legacy web3 library to the Alchemy SDK, effectively fixing the bug that exponentially increased the number of required getTransactionReceipt calls.
Annualized Cost Savings
These two simple changes saved our team an annualized cost of over $3,000,000. To run our faucets, we reduced the total annual cost to approximately $560. 🤯
What this means for your project
They’re super easy to set up and the cost and time-saving benefits will ensure you can have the time and money to focus on your frontend core business, instead of worrying about your backend infrastructure.