DEV Community

Cover image for Optimizing Cost Control: Introducing the Tiered HBAR Rate Limiter for Hedera JSON-RPC Relay
Hedera Team
Hedera Team

Posted on • Originally published at hedera.com

Optimizing Cost Control: Introducing the Tiered HBAR Rate Limiter for Hedera JSON-RPC Relay

By Mica Cerone

Introduction
As the Hedera ecosystem continues to grow, operators of the Hedera JSON-RPC Relay face new challenges, particularly in managing the costs associated with user transactions—especially in public environments. Imagine this: you have allocated a daily, monthly, or yearly HBAR budget and want to ensure it isn’t exceeded. Everything is running smoothly until certain users start submitting abnormally high-cost transactions. These transactions quickly deplete your HBAR resources, leaving less for other users and leading to an unfair distribution of the budget.

To address this challenge, we have re-engineered our previous HBAR rate limiter. The earlier version simply tracked a single total limit over a specified period. In contrast, the new design introduces a customizable Tiered HBAR Rate Limiter, integrated into the relay, allowing for more granular control and flexibility in managing rate limits. This new feature empowers operators to take control of their spending by categorizing users into tiers with defined spending limits.

In this blog post, we’ll explore how this tiered approach works, why it matters, and how operators can use it to protect their financial resources while supporting the Hedera ecosystem.

Understanding the Economic Model
Before diving into the functionality of the HBAR rate limiter, let’s establish some context regarding the relay’s economic model and how it compares to similar systems, such as Ethereum.

The Role of the Hedera JSON-RPC Relay

Image description

The Hedera JSON-RPC Relay serves as a critical bridge, connecting EVM-based applications to the Hedera network. By translating Ethereum Virtual Machine (EVM) JSON-RPC calls into Hedera-compatible requests, the relay enables dApp developers to leverage Hedera’s benefits seamlessly without modifying their existing codebases. These codebases are often built using third-party tools developed for the Ethereum network, such as Ethers.js and Web3.js.

EVM Equivalence and Gas Costs
To maintain EVM equivalence, gas costs charged to users reflect the computational work required, similar to Ethereum. However, in addition to executing transactions within the EVM, certain operations require additional Hedera File Service (HFS) transactions to process large requests.

Who Pays for These HFS Transaction Fees?
Currently, the relay operator bears the costs of these additional HFS transactions. In most cases, these costs are negligible. However, some users may repeatedly deploy large contracts (requiring multiple file transactions on Hedera) or submit high transaction volumes. Without a proper rate-limiting mechanism, these activities can lead to costs that exceed an operator’s initial estimates, quickly becoming unsustainable.

Introducing the Tiered HBAR Rate Limiter
To address these cost management challenges, we developed the Tiered HBAR Rate Limiter. By assigning different spending limits to users based on their tier, we enable sustainable and predictable cost management while still supporting the network’s growth.

How Does the Tiered System Work?
The tiered system assigns users (or groups of users) to specific HBAR spending plans tailored to their behavior and contribution to the network. Think of it like Netflix subscriptions—spending plans can be assigned individually or to groups, similar to personal and family subscription categories.

Basic Tier: General Users
By default, every new user who sends a request to our relay is automatically assigned a unique spending plan under the BASIC tier (Tier 3).

Extended Tier: Supported Projects
Users who exceed the usual activity levels but contribute significantly to the network may qualify for an EXTENDED tier (Tier 2) spending plan.

Privileged Tier: Trusted Partners
The PRIVILEGED tier (Tier 1) is reserved for strategic or critical partnerships, providing users with a significantly higher spending limit.

Configuring the Rate Limiter
Operators can fine-tune the rate limiter to match their specific needs. The relay’s documentation provides a comprehensive guide to configuration options.

Explore the detailed configuration guide in this GitHub repository.

Benefits of the Enhanced HBAR Rate Limiter

  • Cost Control: Operators can define and enforce spending limits for different user groups, ensuring expenses remain manageable.
  • Flexibility: High-value users or strategic projects can receive additional resources while maintaining overall budget discipline.
  • User Management: With monitoring tools, operators can easily track activity, adjust user tiers, and allocate resources efficiently.
  • Transparency: By clearly communicating spending tiers, operators set user expectations and encourage responsible usage.

Conclusion
The newly redesigned HBAR rate limiter is a powerful tool for JSON-RPC Relay operators to control costs and manage user activity effectively. By assigning tiered spending limits to different user groups, operators can support the growth of the Hedera ecosystem while safeguarding their financial resources and ensuring fair allocation.

Call to Action
If you're a relay operator, we encourage you to explore the new rate limiter features and consider how they can benefit your operations. For users, understanding these tiers can help align your activity with operator policies and optimize your interaction with the Hedera network.

Check out this GitHub repository for a detailed configuration guide.

Top comments (0)