Rate Limiting System
FlavumHive implements a sophisticated rate limiting system to ensure responsible platform usage and prevent abuse. This document explains the rate limiting concepts and implementation.
Overview
The rate limiting system:
- Prevents platform API abuse
- Maintains natural interaction patterns
- Ensures compliance with platform limits
- Manages resource utilization
Implementation
Rate Limit Configuration
{
"platforms": {
"twitter": {
"rate_limits": {
"tweets_per_hour": 5,
"likes_per_hour": 20,
"follows_per_day": 50,
"min_delay_between_actions": 30
}
},
"reddit": {
"rate_limits": {
"posts_per_hour": 2,
"comments_per_hour": 10,
"min_delay_between_actions": 60
}
}
}
}
Database Schema
CREATE TABLE rate_limits (
id INTEGER PRIMARY KEY AUTOINCREMENT,
platform TEXT NOT NULL,
action_type TEXT NOT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
window_start DATETIME NOT NULL,
window_end DATETIME NOT NULL,
count INTEGER DEFAULT 1
);
Rate Limit Types
Time-Based Limits
- Actions per minute
- Actions per hour
- Actions per day
- Minimum delay between actions
Platform-Specific Limits
- Twitter API limits
- Reddit API limits
- Platform-specific cooldowns
- Action-specific quotas
Resource-Based Limits
- CPU usage limits
- Memory constraints
- Network bandwidth
- Storage quotas
Implementation Details
Rate Limit Checking
async def check_rate_limit(
platform: str,
action_type: str,
window_seconds: int
) -> bool:
"""
Check if action is within rate limits.
Args:
platform: Platform name
action_type: Type of action
window_seconds: Time window
Returns:
bool: True if action is allowed
"""
Rate Limit Recording
async def record_action(
platform: str,
action_type: str
) -> None:
"""
Record an action for rate limiting.
Args:
platform: Platform name
action_type: Type of action
"""
Best Practices
-
Configuration
- Set conservative limits
- Account for platform rules
- Include safety margins
- Regular limit reviews
-
Monitoring
- Track limit usage
- Monitor violations
- Alert on threshold
- Log all actions
-
Error Handling
- Graceful backoff
- Retry mechanisms
- Error notifications
- Violation handling