Перейти к основному содержимому

API Rate Limiting Deep Dive

Protect your API from abuse with rate limiting.

Configuration

THROTTLE_TTL=60
THROTTLE_LIMIT=100

This allows 100 requests per 60 seconds per IP.

Per-Endpoint Limits

@Throttle({ default: { limit: 5, ttl: 60 } })
@Post('auth/login')
async login(@Body() dto: LoginDTO) {}

@Throttle({ default: { limit: 1000, ttl: 60 } })
@Get('employee')
async findAll() {}

Rate Limit Headers

HeaderDescription
X-RateLimit-LimitMax requests per window
X-RateLimit-RemainingRemaining requests
X-RateLimit-ResetWindow reset timestamp
Retry-AfterSeconds until retry (429)

Response on Rate Limit

{
"statusCode": 429,
"message": "ThrottlerException: Too Many Requests"
}

Redis-Based Rate Limiting

For multi-instance deployments, use Redis storage:

ThrottlerModule.forRoot({
throttlers: [{ ttl: 60, limit: 100 }],
storage: new ThrottlerStorageRedisService(redisClient),
});
Endpoint TypeLimitWindow
Login5 attempts60s
Password Reset3 attempts300s
CRUD Read1000 requests60s
CRUD Write100 requests60s
File Upload10 uploads60s
Export5 exports300s