Overview
Argos Mesh uses Redis as an in-memory data store for high-performance rate limiting and IP blacklisting. The Sentinel service leverages Redis to track request patterns and block malicious IPs in real-time.Connection Configuration
Basic Connection Settings
Redis server hostnameDefault:
redis_db (Docker service name)Production: Use FQDN or IP address of Redis clusterRedis server portDefault:
6379Redis authentication password (optional)Default: Not set in development
Application Properties Example
Docker Configuration
Redis runs as a Docker container with persistence enabled:docker-compose.yml
Append-Only File (AOF): The
--appendonly yes flag enables persistence. Redis logs every write operation, allowing data recovery after restart.Rate Limiting Implementation
The Sentinel service implements a sliding window rate limiter using Redis counters.Rate Limiter Configuration
Maximum requests allowed per time windowDefault:
50Location: TrafficAnalyzer.java:13Adjust this value based on your expected traffic patterns and capacity.
Time window for rate limiting (in seconds)Default:
10Location: TrafficAnalyzer.java:14Redis key prefix for rate limit countersDefault:
rate:ip:Key Pattern: rate:ip:{ip_address}Example: rate:ip:192.168.1.100Rate Limiting Algorithm
The system tracks requests per IP address using Redis INCREMENT operations:TrafficAnalyzer.java
How It Works
First Request
When an IP makes its first request, Redis creates a counter key (
rate:ip:192.168.1.100) and sets it to 1 with a 10-second TTL.Subsequent Requests
Each additional request increments the counter. The TTL remains unchanged (sliding window).
Why This Approach?
Why This Approach?
Advantages:
- O(1) complexity: INCREMENT is atomic and very fast
- No cleanup needed: Keys automatically expire via TTL
- Distributed: Works across multiple Sentinel instances
- Simple: Easy to understand and maintain
- Fixed window behavior (not true sliding window)
- Potential burst at window boundaries
- Consider using more sophisticated algorithms (token bucket, sliding log) for stricter control
IP Blacklist Implementation
The Sentinel service maintains a dynamic IP blacklist with automatic expiration.Blacklist Configuration
Redis key prefix for blacklisted IPsDefault:
blacklist:ip:Key Pattern: blacklist:ip:{ip_address}Example: blacklist:ip:192.168.1.100Ban duration in minutesDefault:
10 minutesConfigurable: Can be adjusted per ban eventBlacklist Service
RedisService.java
Ban Workflow
Redis Key Patterns
Key Naming Convention
| Key Pattern | Purpose | TTL | Value |
|---|---|---|---|
rate:ip:{ip} | Rate limit counter | 10 seconds | Integer (request count) |
blacklist:ip:{ip} | IP ban flag | 10 minutes | String ("BANNED") |
Key Expiration Strategy
Automatic Cleanup: Redis handles all key expiration automatically. No manual cleanup required.
Monitoring Redis
Using Redis CLI
Connect to the Redis container:Useful Commands
Performance Considerations
Memory Usage
Memory Usage
Key Size: Each IP address entry uses approximately 50-100 bytesEstimated Usage:
- 10,000 active IPs: ~1 MB
- 100,000 active IPs: ~10 MB
- 1,000,000 active IPs: ~100 MB
Operation Complexity
Operation Complexity
INCREMENT: O(1) - Constant timeSET with TTL: O(1) - Constant timeHASKEY: O(1) - Constant timeAll rate limiting and blacklist operations are extremely fast.
Persistence Trade-offs
Persistence Trade-offs
AOF (Append-Only File): Enabled in docker-composePros:
- Data survives Redis restarts
- Blacklists persist across deployments
- Slight performance overhead
- Disk I/O required
Scaling Redis
Scaling Redis
For high-traffic production deployments:
- Use Redis Cluster for horizontal scaling
- Use Redis Sentinel for high availability
- Consider Amazon ElastiCache for managed Redis
- Implement connection pooling (Lettuce handles this automatically)
Troubleshooting
Connection Refused
Connection Refused
Symptoms: Services can’t connect to RedisSolutions:
- Verify Redis container is running:
docker ps - Check health:
docker logs black_list - Test connection:
docker exec black_list redis-cli ping - Verify network connectivity between services
Keys Not Expiring
Keys Not Expiring
Symptoms: Blacklisted IPs never unbanSolutions:
- Check TTL:
redis-cli TTL blacklist:ip:192.168.1.100 - Verify
expire()is called afterincrement() - Check Redis memory policy:
redis-cli CONFIG GET maxmemory-policy - Ensure Redis has sufficient memory
High Memory Usage
High Memory Usage
Symptoms: Redis consuming excessive memorySolutions:
- Monitor key count:
redis-cli DBSIZE - Check for keys without TTL:
redis-cli KEYS * | xargs redis-cli TTL - Implement key eviction policy
- Reduce rate limit window or ban duration
Production Recommendations
Enable Authentication
Set
requirepass in redis.conf or use --requirepass flagConfigure Persistence
Choose between AOF (durability) or RDB (performance)
Set Memory Limits
Configure
maxmemory and eviction policyUse Connection Pooling
Spring Data Redis uses Lettuce with built-in pooling