Skip to main content

Rate Limiting

DreamFactory's Limits feature caps how many API requests can be made in a time window. Limits protect backends from overload, keep a single caller from monopolizing the instance, and return HTTP 429 Too Many Requests when a caller is over quota.

There are no default limits. Nothing is throttled until you create a limit.

Quick Reference

ConceptDescription
Admin UI pathSecurity → Rate Limiting
REST API/api/v2/system/limit
Required fieldsname, type, rate, period
Periodsminute, hour, day, 7-day, 30-day
Over-limit responseHTTP 429 (TooManyRequestsException)
Not limitedSystem administrators, and requests made from event scripts

Creating a rate limit

Limit types

Each limit has a type that decides which requests it counts. Types combine instance, user, role, service, and endpoint:

TypeCounts requests…
instanceacross the whole instance
instance.userfor one specific user (user_id)
instance.each_userseparately for every authenticated user
instance.rolefor every caller in a role (role_id)
instance.serviceagainst one service (service_id)
instance.user.servicefor one user against one service
instance.each_user.serviceper user, against one service
instance.service.endpointagainst one service endpoint (endpoint)
instance.user.service.endpointfor one user against one endpoint
instance.each_user.service.endpointper user, against one endpoint

A specific-user limit (instance.user…) overrides the matching each_user limit at the same level. You can also attach an HTTP verb (GET, POST, and so on) so the limit only counts that method.

Endpoint paths are bucketed before they are keyed. Numeric IDs become :id, UUIDs become :uuid, and long hex hashes become :hash. That keeps /api/v2/db/_table/orders/1 and /api/v2/db/_table/orders/2 in the same bucket, so changing the record id cannot bypass the limit.

There is no per-API-key limit type. The closest fits are instance.role (the role the API key is bound to) or instance.user if the caller is a user.

Creating limits in the admin UI

  1. In the left sidebar open Security, then Rate Limiting.
  2. Click the + button.
  3. Set a name, type, rate (number of requests), and period.
  4. Fill in the type-specific fields (user_id, role_id, service_id, endpoint, verb) as required.
  5. Leave Active enabled and save.

Creating limits via the System API

curl -X POST "https://your-dreamfactory-instance.com/api/v2/system/limit" \
-H "X-DreamFactory-Api-Key: YOUR_ADMIN_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "1000 requests per minute, whole instance",
"type": "instance",
"rate": 1000,
"period": "minute",
"is_active": true
}'

Per-service example:

curl -X POST "https://your-dreamfactory-instance.com/api/v2/system/limit" \
-H "X-DreamFactory-Api-Key: YOUR_ADMIN_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "db reads, 100 per minute per user",
"type": "instance.each_user.service",
"rate": 100,
"period": "minute",
"service_id": 5,
"verb": "GET",
"is_active": true
}'
FieldRequiredDescription
nameYesLabel shown in the admin UI
typeYesOne of the types in the table above
rateYesMaximum requests allowed in the period
periodYesminute, hour, day, 7-day, or 30-day
user_idWhen type includes a specific userUser the limit applies to
role_idWhen type is instance.roleRole the limit applies to
service_idWhen type includes a serviceTarget service
endpointWhen type includes an endpointResource path, for example _table/employees
verbNoRestrict the limit to one HTTP method
descriptionNoOptional notes
is_activeNoDefaults to active; set false to disable without deleting

List limits with GET /api/v2/system/limit. Reset counters with the system/limit_cache resource. Deleting a user, role, or service also deletes the limits that pointed at it.

Periods and counters

period is a named window, not a number of seconds:

PeriodWindow
minute60 seconds
hour1 hour
day24 hours
7-day7 days
30-day30 days

Counters live in DreamFactory's cache store (Redis or Memcached in production; the file/database cache on smaller installs). The same cache backend used for the rest of the instance holds the hit counts.

Over-limit responses

When a caller exceeds an active limit, DreamFactory returns HTTP 429 with a TooManyRequestsException body. The 429 response includes:

HeaderMeaning
X-RateLimit-LimitMaximum requests in the current window
X-RateLimit-RemainingRequests left in the window (0 when exceeded)
Retry-AfterSeconds until the window reopens
X-RateLimit-ResetUnix timestamp when the window reopens

System administrators and script-initiated calls skip limit checks.