A public RPC endpoint without a rate limit is a matter of time, not a matter of if. Somebody will find it, and somebody will hammer it. Sometimes it is a scraper replaying expensive calls in a loop. Sometimes it is a launch-day wallet app retrying every failed request ten times a second. Sometimes it is your own team, with a script that has no backoff and no idea it is the problem. The result is the same: your node spends its CPU and disk on junk requests, real users get timeouts, and your launch-day support channel fills up with people who think your chain is down. Rate limiting is the cheapest insurance a node operator can buy, and it takes about twenty minutes to set up.
If you have not set up the endpoint itself yet, read our private RPC setup guide first. This post assumes the node is running and reachable, and it covers the layer in front of it: how to decide what a fair limit is, how to enforce it with NGINX, and how to make the limit fail gracefully instead of failing loudly. If you run two endpoints for redundancy, read our RPC failover guide alongside this one, because limits and failover have to agree with each other.
Why an RPC endpoint is a target
Not all RPC methods cost the same. A simple eth_blockNumber call is cheap. An eth_getLogs call across a wide block range is expensive: it reads a lot of state, holds memory, and can take seconds on a busy node. An eth_call that runs a heavy contract function is somewhere in between. Attackers and careless clients do not care about this difference. They send whatever they send, and the node pays for it. A single client looping eth_getLogs over thousands of blocks can slow every other caller on the same node, including your own app.
There is also a discovery problem. RPC endpoints leak. They end up in public lists, in GitHub repos, in Discord messages, in browser dev tools. Once an endpoint is public, it stays public. You cannot unshare it. The only durable answer is to assume the endpoint is known and to limit what any one caller can do with it. That is what rate limiting is for: it does not hide the endpoint, it bounds the damage any single client can cause.
The three layers of a limit
A good setup limits on three axes at once. First, per IP: one address gets a fair share and no more. Second, per API key: your own apps and your paying users get higher limits than anonymous traffic, and you can revoke a key without touching anyone else. Third, per method: expensive calls get stricter limits than cheap ones. One flat limit for everything is better than nothing, but it is a blunt tool. A flat limit set high enough for normal traffic lets a logs scraper through. A flat limit set low enough to stop the scraper breaks your own app. The three layers together let you be generous where it is cheap and strict where it is expensive.
Start with numbers you can defend. For a small private endpoint, 10 requests per second per IP with a burst allowance of 20 is a reasonable starting point for read traffic. Your own backend, behind its own key, might get 100 requests per second. An eth_getLogs call might get 1 request per second per IP. These are starting points, not laws. Watch your logs for a week, see what normal looks like, then tighten. A limit you set from a guess and never revisit is only slightly better than no limit at all.
NGINX rate limiting in practice
NGINX has rate limiting built in, and it works on the leaky bucket idea: requests arrive as fast as they arrive, and the bucket drains at the rate you set. When the bucket overflows, the extra requests are rejected. You define a shared memory zone once, in the http block, and then apply it where it matters.
# In the http block: define the zone
# 10 MB of shared memory, 10 requests per second per IP
limit_req_zone $binary_remote_addr zone=rpc:10m rate=10r/s;
# In the server block: apply it to the RPC path
location / {
limit_req zone=rpc burst=20 nodelay;
limit_req_status 429;
proxy_pass http://127.0.0.1:8545;
}
The pieces matter. The zone key $binary_remote_addr tracks by client IP in a compact binary form, so a 10 MB zone holds roughly 160,000 IPv4 addresses. The rate 10r/s means one request allowed every 100 milliseconds per IP. The burst=20 setting lets a client send 20 extra requests at once instead of rejecting them immediately, which absorbs normal spikes like a page load that fires several calls together. The nodelay flag means those burst requests are processed right away instead of being queued and delayed. And limit_req_status 429 changes the rejection code from the NGINX default of 503 to 429, which is the correct HTTP status for rate limiting and the one well-behaved clients know how to handle.
Per-key limits with a map
Per-IP limits alone punish everyone behind the same NAT, and they do nothing to reward your own apps. The fix is to limit by API key when one is present, and fall back to IP when it is not. NGINX does this with a map that reads the key from a header.
# Use the API key as the limit key when present, else the IP
map $http_x_api_key $rpc_limit_key {
default $binary_remote_addr;
"~^.+$" $http_x_api_key;
}
limit_req_zone $rpc_limit_key zone=rpc_keyed:10m rate=100r/s;
limit_req_zone $binary_remote_addr zone=rpc_anon:10m rate=10r/s;
With this setup, a caller with a valid key gets the higher keyed limit, and anonymous traffic gets the stricter IP limit. Rotating a compromised key becomes a one-line change instead of an incident. If you issue keys per customer or per app, you can also give each one its own zone and its own rate, so one customer's runaway script cannot eat another customer's allowance.
Stricter limits for expensive methods
The most common RPC abuse is not volume, it is cost: a flood of eth_getLogs or eth_call requests. You can route those to a stricter zone by matching the request body, or more simply by giving your logs endpoint its own path and its own limit. A practical approach is a dedicated location for the methods you know are heavy, with a rate of 1 request per second and a small burst. Your indexer or explorer can use a key with a higher allowance on that path, while anonymous callers get the strict default. Measure which methods actually cost you CPU before you decide the numbers: your node's slow-query log will tell you more than any blog post can.
What to return when the limit hits
A limit that returns the wrong signal is almost as bad as no limit. The correct response is HTTP 429, Too Many Requests, ideally with a Retry-After header telling the client how long to wait. The NGINX default is 503, which tells clients the server is broken, so they retry harder, which makes the problem worse. Set limit_req_status 429 explicitly. On top of that, log every rejection with the client key and the method, so you can tell the difference between one abusive client and a hundred normal ones. If a single key is responsible for most of your 429s, that key is the problem, not your limit.
Also tell your users what the limits are. Publish them in your docs: requests per second, burst size, and what happens on a 429. A limit nobody knows about feels like an outage. A limit that is documented feels like a service guarantee. If you run a public endpoint, put the limits in the same place you publish the endpoint URL, so nobody has to discover them by hitting them.
Limits and failover must agree
Rate limits and failover interact in ways that surprise people. If your primary endpoint starts returning 429s and your client's failover logic treats any error as a reason to switch, all of your traffic jumps to the fallback at once, and now the fallback is overloaded too. Make sure your health checks and your failover triggers distinguish a 429 from a real failure. A 429 means the node is alive and protecting itself. It is not a reason to fail over. Only sync lag, timeouts, and connection errors should trigger a switch. And set the same limits on both endpoints, so a failover does not suddenly give every client ten times the allowance.
Test the whole arrangement before launch day. Run a load test against your own endpoint, watch the 429s appear at the rate you set, confirm your app backs off and retries instead of crashing, and confirm the fallback stays quiet during the test. Our Grafana monitoring guide shows which numbers to watch while you do this: request rate, 429 rate, upstream latency, and node CPU. If the 429 rate is zero during a load test, your limit is too generous. If your own app is getting 429s during normal use, it is too strict.
A starting checklist
Put the endpoint behind NGINX or another reverse proxy, never expose the node port directly. Define one zone per IP and one per key, with a higher rate for keyed traffic. Give expensive methods their own stricter zone. Return 429 with a Retry-After header, and log every rejection. Publish the limits in your docs. Keep failover triggers away from 429s, and mirror the limits on every endpoint. Revisit the numbers after a week of real traffic, and again after your first launch spike. A rate limit is not a setting you finish, it is a setting you tune. The operators who get this right are the ones whose nodes stay up on the day everyone else's falls over.
If your RPC setup is growing past a single NGINX box, that is the point where managed infrastructure pays for itself. Our blockchain node setup service covers private RPC, failover, and monitoring as one package, and you can book a free infra audit with DevOpsBY to get a second pair of eyes on your limits before your next launch.
Disclaimer: This post is educational only, not financial advice. Figures are listing or project data as of 2026-11-10 and may change - always confirm version numbers, requirements, and dates in the official docs before acting on them.
