throttlecrab-server
A high-performance rate limiting server with multiple protocol support, built on throttlecrab.
Features
- Multiple protocols: HTTP (JSON) and gRPC
- High performance: Lock-free shared state with Tokio async runtime
- Production ready: Health checks, metrics endpoint, configurable logging, systemd support
- Flexible deployment: Docker, binary, or source installation
- Shared rate limiter: All protocols share the same store for consistent limits
- Observability: Prometheus-compatible metrics for monitoring and alerting
Installation
Install the server binary with cargo:
Or build from source:
Usage
Start the throttlecrab server (at least one transport must be specified):
# Run with HTTP transport
# Run with HTTP transport on custom port
# Run multiple transports simultaneously
# Specify different hosts and ports for each transport
# Configure store type and parameters
# Use periodic store with custom cleanup interval
# Use probabilistic store
# Set custom buffer size and log level
Environment Variables
All CLI arguments can be configured via environment variables with the THROTTLECRAB_ prefix:
# Transport configuration
# Store configuration
# General configuration
# CLI arguments override environment variables
THROTTLECRAB_HTTP_PORT=8080
# Server will use port 7070 (CLI takes precedence)
Transport Comparison
| Transport | Protocol | Throughput | Latency (P99) | Latency (P50) | Use Case |
|---|---|---|---|---|---|
| HTTP | JSON | 173K req/s | 309 μs | 177 μs | Easy integration |
| gRPC | Protobuf | 163K req/s | 370 μs | 186 μs | Service mesh |
Protocol Documentation
HTTP REST API
Endpoint: POST /throttle
Request Body (JSON):
Note: quantity is optional (defaults to 1).
Response (JSON):
gRPC Protocol
See proto/throttlecrab.proto for the service definition. Use any gRPC client library to connect.
Client Integration
Rust
Use established HTTP clients like reqwest for reliable production deployments:
[]
= { = "0.12", = ["json"] }
Other Languages
- Go: Use gRPC with generated client
- Python: Use HTTP/JSON API
- Node.js: Use HTTP/JSON API
- Java: Use gRPC with generated client
See examples/ directory for implementation examples.
Running Benchmarks
Criterion Benchmarks
The project includes several Criterion benchmarks that require running servers. Use the provided script:
# Run all benchmarks
# Run specific benchmark
The script will:
- Build the server in release mode
- Start required servers (HTTP on port 9092, gRPC on port 9093)
- Run the benchmarks
- Clean up servers on exit
Results are saved in target/criterion/.
Production Deployment
Performance Tuning
# Optimal settings for production
Monitoring
- Health endpoint:
GET /health(available on HTTP port) - Metrics endpoint:
GET /metrics(Prometheus format, available on HTTP port) - Logs: Structured logging with configurable levels
- Performance metrics: Available via
/metricsendpoint
Available Metrics
throttlecrab_uptime_seconds: Server uptimethrottlecrab_requests_total: Total requests processedthrottlecrab_requests_by_transport{transport="..."}: Requests per transportthrottlecrab_requests_allowed: Total allowed requeststhrottlecrab_requests_denied: Total denied requeststhrottlecrab_connections_active{transport="..."}: Active connections per transportthrottlecrab_request_duration_bucket: Request latency histogramthrottlecrab_active_keys: Number of active rate limit keysthrottlecrab_store_evictions: Total key evictions
Store Configuration
| Store Type | Use Case | Cleanup Strategy |
|---|---|---|
standard |
Small datasets | Every operation |
periodic |
Predictable load | Fixed intervals |
probabilistic |
High throughput | Random sampling |
adaptive |
Variable load | Self-tuning |
Example Configurations
High-throughput API
Web Service
Microservices
License
Licensed under either of:
- MIT license (LICENSE or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.