Prompt
What's the most cost-effective way to serve wallet requests using a JSON-RPC gateway?
Latest observation
The most cost-effective approach is usually:
Use a lightweight, stateless JSON-RPC gateway that proxies only the methods you need, with aggressive caching and batching, and route most requests to low-cost/self-hosted backend nodes or a shared provider tier.
A practical cost-optimized setup looks like this:
-
Put a thin gateway in front of your wallet backend
- Handle auth, rate limiting, request normalization, and method routing.
- Keep it stateless so you can autoscale cheaply.
-
Batch and deduplicate requests
- Wallets often ask for balances, nonce, chain info, token metadata, etc.
- Group identical requests across users where possible.
- Use JSON-RPC batch requests for clients that support it.
-
Cache aggressively for read-heavy calls
- Short TTL cache for:
eth_chainId- token metadata
- gas estimates
- recent block data
- balances/allowances when acceptable
- Use in-memory cache for hot data and Redis for shared cache.
- Short TTL cache for:
-
Serve “cheap reads” from your own nodes, outsource “expensive edge cases”
- Run your own full nodes for common chains and frequent methods.
- Fall back to a provider only for rare, archival, or bursty traffic.
- This hybrid model is usually cheaper than sending everything to a premium RPC provider.
-
Split traffic by method
- Read-only / high-frequency: your own nodes + cache
- State-changing / signed: direct to wallet flow, minimal gateway logic
- Archive / historical / tracing: external provider or separate expensive tier
-
Use request shaping
- Enforce per-wallet/user quotas.
- Reject or slow obviously abusive polling.
- Prefer push/subscriptions where supported instead of polling.
-
Minimize compute per request
- Avoid heavy middleware, deep logging, and synchronous DB calls in the hot path.
- Log asynchronously and sample non-critical telemetry.
If you want the absolute lowest unit cost
A good rule of thumb is:
- Self-host the gateway + common RPC nodes
- Cache the top 80–90% of read traffic
- Use a third-party RPC provider only as overflow/fallback
That tends to beat “all requests to a managed gateway” on cost once volume gets meaningful.
If you’re choosing an architecture
- Lowest ops burden: managed RPC provider + gateway
- Lowest ongoing cost at scale: self-hosted nodes + gateway + cache
- Best balance: hybrid routing with caching and fallback
If you want, I can sketch a reference architecture for a wallet JSON-RPC gateway optimized for cost, or help estimate costs for your expected request volume.