Overview
Argos Mesh implements a comprehensive DDoS protection strategy that combines rate limiting, IP blocking, and real-time alerting to defend against distributed denial-of-service attacks. The Sentinel service acts as a security gateway, analyzing traffic patterns and automatically mitigating threats.The DDoS protection system runs on Java 21 Virtual Threads, enabling it to handle thousands of concurrent connections with minimal resource overhead.
Protection Architecture
The DDoS protection system consists of three integrated components:TrafficAnalyzer
Monitors request rates using a sliding window algorithm and identifies abusive traffic patterns.
RedisService
Manages a distributed IP blacklist with automatic expiration, shared across all service instances.
SalesListener
Processes events in real-time, coordinating traffic analysis and alert generation.
How DDoS Protection Works
Event Flow
Here’s the complete flow from an incoming request to threat mitigation:public record ProductSoldInternalEvent(
Long productID,
Integer quantity,
String ipAddress,
LocalDateTime timeStamp
) {}
@RabbitListener(queues = "argos.sales.queue")
public void processSalesEvents(ProductSoldInternalEvent data) {
String ip = data.ipAddress();
if (redisService.isBanned(ip)) {
return;
}
if (analyzer.processAndCheckLimit(ip)) {
AlertInternalEvent event = new AlertInternalEvent(
"Suspicious behavior",
ip,
"CRITICAL",
LocalDateTime.now()
);
rabbitTemplate.convertAndSend(
RabbitMQConfig.ALERT_EXCHANGE,
"argos.alert.security",
event
);
} else {
System.out.println("[ Sentinel🛡️ ] Normal traffic of the IP: " + ip);
}
}
public boolean processAndCheckLimit(String ip) {
if (redisService.isBanned(ip)) return true;
String key = RATE_PREFIX + ip;
Long currentCount = redisTemplate.opsForValue().increment(key);
if (currentCount != null && currentCount == 1) {
redisTemplate.expire(key, Duration.ofSeconds(WINDOW_SECONDS));
}
if (currentCount != null && currentCount > LIMIT) {
redisService.banIp(ip, 10);
return true;
}
return false;
}
public void banIp(String ipAddress, long durationMinutes) {
redisTemplate.opsForValue().set(
BLACKLIST_PREFIX + ipAddress,
"BANNED",
Duration.ofMinutes(durationMinutes)
);
}
AlertInternalEvent event = new AlertInternalEvent(
"Suspicious behavior",
ip,
"CRITICAL",
LocalDateTime.now()
);
rabbitTemplate.convertAndSend(
RabbitMQConfig.ALERT_EXCHANGE,
"argos.alert.security",
event
);
Java 21 Virtual Threads
The Sentinel service leverages Java 21 Virtual Threads for high-concurrency request processing:sentinel/src/main/resources/application.properties
Why Virtual Threads?
Massive Concurrency
Handle thousands of concurrent requests without the overhead of traditional threads. Each request gets its own lightweight virtual thread.
Low Memory Footprint
Virtual threads use ~1KB of memory vs ~1MB for platform threads, enabling massive scalability on limited hardware.
Simple Blocking Code
Write straightforward blocking I/O code without callbacks or reactive patterns. Virtual threads make blocking operations efficient.
DDoS Resilience
During an attack, thousands of malicious requests can be processed simultaneously without exhausting thread pools.
Virtual threads are automatically used by Spring Boot 3.2+ when RabbitMQ listeners process messages, making the Sentinel service highly resilient to traffic spikes.
Protection Scenarios
Scenario 1: Scalping Bot Attack
Attack Pattern: A bot attempts to purchase all limited-edition products by making rapid requests.Request 1-50: ✅ Processed normally
Request 51: ❌ LIMIT EXCEEDED → IP BANNED
Request 52-100: ❌ Dropped (IP blacklisted)
{
"type": "Suspicious behavior",
"sourceIp": "203.0.113.42",
"severity": "CRITICAL",
"timeStamp": "2026-03-05T14:32:18"
}
Scenario 2: Distributed DDoS
Attack Pattern: A botnet of 1,000 infected devices sends traffic from different IPs.Bot 1 (192.168.1.10): Requests 1-50 ✅ | Request 51+ ❌ BANNED
Bot 2 (192.168.1.11): Requests 1-50 ✅ | Request 51+ ❌ BANNED
Bot 3 (192.168.1.12): Requests 1-50 ✅ | Request 51+ ❌ BANNED
...
Bot 1000 (192.168.1.1000): Requests 1-50 ✅ | Request 51+ ❌ BANNED
Scenario 3: Legitimate Traffic Spike
Pattern: Your product goes viral on social media, causing a sudden surge in legitimate traffic.User 1: 8 requests over 30 seconds ✅ Not rate limited
User 2: 12 requests over 45 seconds ✅ Not rate limited
User 3: 35 requests over 60 seconds ✅ Not rate limited
Concurrent requests: 10,000
Virtual threads created: 10,000
Memory usage: ~10MB for threads
All requests processed successfully ✅
Configuration Recommendations
Development Environment
Production Environment
High-Security Environment
For e-commerce platforms during high-traffic events (Black Friday, product launches), consider temporarily raising the limit to prevent false positives.
Monitoring DDoS Protection
Real-Time Metrics
Monitor these key metrics to assess DDoS protection effectiveness:Alert Queue Analysis
Query the alert queue to see DDoS activity:Grafana Dashboard
Create a Grafana dashboard to visualize DDoS metrics:Banned IPs Over Time
Track the number of banned IPs to detect attack patterns.
Rate Limit Violations
Graph the frequency of rate limit violations to identify attack intensity.
Alert Volume
Monitor the number of security alerts generated per minute.
Request Processing Time
Ensure virtual threads maintain low latency even under attack.
Defense Layers
Argos Mesh implements defense in depth:Each layer provides protection, but the Sentinel service’s application-layer defense is critical because it understands business logic and can make intelligent decisions about what constitutes abuse.
Best Practices
Deploy Multiple Sentinels
Run multiple Sentinel service instances for high availability. They share Redis state automatically.
Use Redis Cluster
For large-scale deployments, use Redis Cluster to distribute blacklist and counter data.
Monitor Alert Queue
Set up automated monitoring to notify security teams when alert volume spikes.
Implement Whitelisting
Add IP whitelist logic to prevent false positives for internal services and monitoring systems.
Log All Bans
Implement structured logging to track when and why IPs are banned for audit purposes.
Tune for Your Traffic
Adjust rate limits based on your application’s normal traffic patterns. Monitor false positives.
Limitations
Extending Protection
Add CAPTCHA for Suspicious Traffic
Instead of immediately banning, challenge suspicious IPs with CAPTCHA:Implement Progressive Penalties
Add Machine Learning
Train a model to detect anomalous patterns:Related Resources
Rate Limiting
Detailed explanation of the sliding window algorithm
IP Blocking
How to manually manage the IP blacklist
Architecture
Understand how Sentinel fits into the overall system
Event-Driven Design
Learn about the RabbitMQ event flow