Rate Limit Hyperledger Fabric Endorsement Requests
In this article
Rate limiting endorsement requests in Hyperledger Fabric prevents a single client or a burst of traffic from overwhelming the peers that execute chaincode and produce transaction endorsements. Without limits, a misbehaving or compromised client can exhaust peer CPU, memory, and connection pools, causing delays or outages for all other users. This guide shows you how to add practical rate limiting at the peer level using Fabric's built-in configuration and, where needed, an external reverse proxy for finer control.
What You'll Need
- A running Hyperledger Fabric network (v2.x or later) with at least one peer node.
- Administrative access to the peer's configuration file (
core.yaml) and the ability to restart the peer. - Basic familiarity with YAML syntax and Fabric peer operations.
- Optional: A reverse proxy (e.g., Nginx, HAProxy) if you need per-client or more granular limits than Fabric's built-in options.
Step-by-Step
- Identify the peer's
core.yamlfile. This file is typically located in the peer's config directory (e.g.,/etc/hyperledger/fabric/core.yamlor within your deployment's config volume). Open it in a text editor. - Locate the
peersection and find thelimitssubsection. In Fabric v2.x, the relevant section looks like this:peer: limits: concurrency: endorserService: 2500 deliverService: 2500 gatewayService: 500 rate: endorserService: 100 deliverService: 100 gatewayService: 50If thelimitsblock does not exist, you can add it underpeer. - Set the concurrency limits. The
concurrencyvalues define the maximum number of simultaneous requests the peer will process for each service.endorserServicehandles endorsement requests. Start with a value that matches your peer's capacity—typically between 500 and 2500 for a moderately sized deployment. Lower values (e.g., 100) provide stricter protection but may reduce throughput. - Set the rate limits. The
ratevalues define the maximum number of requests per second the peer accepts for each service. For endorsement requests, setendorserServiceto a value that your hardware can handle without degradation. A common starting point is 100 requests per second, but you should benchmark your peer to find the right number. - Save the changes and restart the peer. After modifying
core.yaml, restart the peer process. For a Docker deployment, you might rundocker restart peer0.org1.example.comor recreate the container. For a systemd service, usesudo systemctl restart peer. - Verify the limits are active. Send a burst of endorsement requests to the peer and observe its behavior. If the limits are working, requests beyond the set rate will be rejected with an error such as
ENDORSEMENT_POLICY_FAILUREor a gRPC resource exhaustion error. You can also check peer logs for messages likeToo many requestsorrate limit exceeded. - For per-client or IP-based limits, deploy a reverse proxy. If you need to limit requests from specific clients, place a reverse proxy in front of the peer. Configure the proxy to forward requests to the peer's gRPC endpoint (usually port 7051) and apply rate limiting rules there. For example, in Nginx, you can use the
limit_req_zonedirective to limit requests per IP address. - Test with a load generator. Use a tool like
hyperledger/fabric-samplesor a custom script to send a high volume of endorsement requests. Monitor the peer's CPU and memory usage to ensure the limits prevent overload.
Common Mistakes
- Setting limits too low. If you set the rate limit below your normal peak traffic, legitimate clients will experience failures. Always benchmark your peer's actual capacity before setting limits.
- Forgetting to restart the peer. Changes to
core.yamlare only applied after a restart. If you don't restart, the old settings remain active. - Misidentifying the service name. Endorsement requests go through the
endorserService, notdeliverService(which handles block delivery) orgatewayService(which handles gateway transactions). Setting limits on the wrong service won't protect your endorsers. - Ignoring the concurrency limit. The rate limit alone may not prevent a sudden burst of requests that all arrive in the same second. The concurrency limit acts as a safety net—set both appropriately.
- Not testing after configuration. Even if the config looks correct, you should always test with a load generator to ensure the peer behaves as expected.
Tips
- Start conservative and adjust. Begin with lower limits and gradually increase them while monitoring performance. This helps you find the sweet spot without risking an outage.
- Monitor peer metrics. Use Fabric's metrics endpoint (if enabled) to track request rates, latency, and error rates. This data helps you tune the limits.
- Use a reverse proxy for advanced scenarios. Fabric's built-in limits are global per service. If you need to limit per organization, client, or IP, a reverse proxy gives you that flexibility.
- Document your limits. Record the chosen values and the reasoning behind them in your deployment documentation. This helps future administrators understand the configuration.
- Combine with client-side throttling. Encourage SDK users to implement their own retry and backoff logic. This reduces the chance of overwhelming the peer even with rate limits in place.
Troubleshooting
- Limits not taking effect. Double-check that you edited the correct
core.yamlfile and that the peer is actually reading it. Some deployments use environment variables to override config values—check forCORE_PEER_LIMITS_RATE_ENDORSERSERVICEor similar overrides. - Legitimate requests failing. If you see errors like
RESOURCE_EXHAUSTEDorUNAVAILABLE, your limits are too low. Increase the rate and concurrency values, and consider scaling out by adding more peers. - Peer becomes unresponsive even with limits. The limits only apply to the services they are configured for. If other operations (e.g., block delivery) are causing the issue, you may need to set limits on those services as well. Also check that the peer has enough CPU and memory.
- Rate limit errors in logs but not in client responses. Some SDKs may not surface the underlying gRPC errors. Check the peer logs for messages like
rate limit exceededto confirm the limit is triggering. - Reverse proxy not forwarding correctly. Ensure the proxy is configured to use HTTP/2 and gRPC passthrough. A misconfigured proxy can strip the gRPC headers, causing the peer to reject requests.
Frequently Asked Questions
Can I rate limit endorsement requests per client or organization?
Fabric's built-in limits are global per service. For per-client or per-org limits, you need an external reverse proxy that can inspect client identities (e.g., via TLS certificates or JWT tokens) and apply separate limits.
What happens when the rate limit is exceeded?
The peer rejects the request with a gRPC error, typically RESOURCE_EXHAUSTED or UNAVAILABLE. The client SDK will receive this error and can decide to retry or fail.
Do I need to set both rate and concurrency limits?
Yes, they serve different purposes. The rate limit caps requests per second, while the concurrency limit caps the number of simultaneous in-flight requests. Both are needed to protect against different types of overload.
Will rate limiting affect transaction throughput?
Yes, if you set limits below your actual capacity, you will reduce throughput. The goal is to set limits just above your normal peak so that you only throttle abnormal bursts.
Can I change the limits without restarting the peer?
No, core.yaml is read at startup. Changing it requires a peer restart. For dynamic adjustments, consider using a reverse proxy with hot-reload capabilities.
Are there any official Fabric tools for load testing?
Fabric does not ship a dedicated load tester, but you can use the fabric-samples test network or write a custom script using the Fabric SDK to generate endorsement requests.