Rate Limiter
A rate limiter for REST and MCP requests is a mechanism used to control the frequency at which clients can make requests to the MDM Server. In other words, it limits the number of requests a client can make within a specified time interval, which helps prevent misuse or overloading the server.
Various limits can be set based on the URI address and/or the HTTP method.
In case the limiter gets overloaded, the 429 Too Many Requests response status code is returned.
General configuration
The following properties are defined in MDM Server Application Properties to configure the rate limiter:
-
ataccama.server.ratelimiter.enabled- If set totrue, the rate limiter is turned on. By default, the rate limiter is not used (default value:false). -
ataccama.server.ratelimiter.http.<limiter>.urls- Comma-separated list of URL prefixes. Can also contain the HTTP method.From the list provided, the most precise limiter is selected and the HTTP method is taken into consideration in case there are multiple patterns matched. If no URLs are matches, no limit is applied.
Configuration example
Assume we have the following configuration:
ataccama.server.ratelimiter.http.apilimit-rest-get.urls=GET:/api/rest/instance,GET:/api/rest/master
ataccama.server.ratelimiter.http.apilimit-rest-post.urls=POST:/api/rest/instance,POST:/api/rest/master
ataccama.server.ratelimiter.http.apilimit-rest.urls=/api/rest/instance
This means the following:
-
The
apilimit-rest-getrate limiter is applied to GET requests to/api/rest/instanceorapi/rest/master. -
The
apilimit-rest-postrate limiter is applied to POST requests to/api/rest/instanceorapi/rest/master. -
The
apilimit-restrate limiter is applied to all other requests to/api/rest. -
There are no limits applied to other requests.
Resilience4j setup
The rate limiter is implemented using Resilience4j. To learn more about this library, see articles Guide to Resilience4j With Spring Boot and Resilience4j RateLimiter documentation.
Use these properties to control the behavior of the rate limiter:
-
resilience4j.ratelimiter.instances.<RateLimiterName>.limit-for-period- Sets the maximum allowed number of operations within a defined time period. For example, if you set the value to10, a user can perform a maximum of 10 operations within the time period specified by thelimit-refresh-periodproperty. -
resilience4j.ratelimiter.instances.<RateLimiterName>.limit-refresh-period- Determines the time period after which the limit for the number of operations is refreshed. For example, if you set the value to1s, the limit for the number of operations is refreshed every second. -
resilience4j.ratelimiter.instances.<RateLimiterName>.timeout-duration- Specifies how long to wait for a request to be processed before it’s considered a failure. If this period elapses, the request is considered unsuccessful. -
resilience4j.ratelimiter.instances.<RateLimiterName>.register-health-indicator- Determines whether to register a health indicator for the specified rate limiter. If set totrue, a health indicator is available within Spring Boot actuators, allowing you to monitor the rate limiter’s status. We recommend enabling it for debugging or monitoring purposes.
MCP requests
The rate limiter also covers the MDM MCP Server.
All MCP requests, that is, tool calls as well as the initialize, ping, and listing requests, go through a single path, POST /mcp, so the limit applies to MCP requests as a whole.
To limit MCP requests, define a dedicated limiter for POST:/mcp:
ataccama.server.ratelimiter.enabled=true
ataccama.server.ratelimiter.http.mcp.urls=POST:/mcp
resilience4j.ratelimiter.instances.mcp.limit-for-period=20
resilience4j.ratelimiter.instances.mcp.limit-refresh-period=1s
resilience4j.ratelimiter.instances.mcp.timeout-duration=0s
In this example, a client can make at most 20 MCP requests per second, and requests over the limit are rejected immediately. To choose a suitable limit, check the MCP tool call metrics in MDM Monitoring Metrics.
Was this page useful?