A high-performance distributed cache system built with Spring Boot and Redis, designed for high availability and scalability. This system implements consistent hashing for data distribution, circuit breakers for fault tolerance, and comprehensive monitoring.
- High Availability: 99.9% uptime with automatic failover
- Performance: Sub-millisecond latency and 10,000+ RPS support
- Scalability: Horizontal scaling with consistent hashing
- Fault Tolerance:
- Circuit breaker pattern
- Retry mechanism with exponential backoff
- Data replication across nodes
- Monitoring:
- Real-time metrics via Spring Boot Actuator
- CloudWatch integration
- Health check endpoints
- Batch Operations: Support for bulk cache operations
Client Applications
β β
API Gateway Layer
β β
Cache Service Layer (Spring Boot)
β β
Redis Cluster (AWS ElastiCache)
- Java 17 or higher
- Maven 3.6 or higher
- Redis Cluster (AWS ElastiCache recommended)
- AWS account for CloudWatch monitoring
# Redis Configuration
export REDIS_CLUSTER_NODES=redis-cluster.xxxxx.clustercfg.use1.cache.amazonaws.com:6379
export REDIS_PASSWORD=your_redis_password
# AWS Configuration
export AWS_REGION=us-east-1spring:
redis:
cluster:
nodes: ${REDIS_CLUSTER_NODES:localhost:6379}
password: ${REDIS_PASSWORD:}
timeout: 2000
lettuce:
pool:
max-active: 8
max-idle: 8
min-idle: 2
management:
endpoints:
web:
exposure:
include: health,metrics,prometheus
metrics:
export:
cloudwatch:
namespace: CacheService
enabled: true
region: ${AWS_REGION:us-east-1}git clone https://github.com/your-username/distributed-cache-system.git
cd distributed-cache-systemmvn clean package# Using environment variables
export REDIS_CLUSTER_NODES=your_redis_nodes
export REDIS_PASSWORD=your_password
java -jar target/distributed-cache-system-1.0-SNAPSHOT.jar
# Or using command line arguments
java -jar target/distributed-cache-system-1.0-SNAPSHOT.jar \
--spring.redis.cluster.nodes=your_redis_nodes \
--spring.redis.password=your_passwordcurl -X POST http://localhost:8080/api/cache/my-key \
-H "Content-Type: text/plain" \
-d "my-value" \
-G --data-urlencode "ttlSeconds=3600"curl http://localhost:8080/api/cache/my-keycurl -X DELETE http://localhost:8080/api/cache/my-keycurl -X POST http://localhost:8080/api/cache/batch \
-H "Content-Type: application/json" \
-d '{"key1": "value1", "key2": "value2"}' \
-G --data-urlencode "ttlSeconds=3600"curl http://localhost:8080/api/healthResponse:
{
"status": "UP",
"redis": "UP",
"clusterNodes": ["node1:6379", "node2:6379"],
"nodeCount": 2
}-
Cache Operations:
cache.operations: Count of cache operationscache.operation.latency: Operation latency in millisecondscache.hits: Number of cache hitscache.misses: Number of cache misses
-
Circuit Breaker:
resilience4j.circuitbreaker.state: Current state of the circuit breakerresilience4j.circuitbreaker.calls: Number of calls
-
Redis:
redis.connection.pool.active: Active connectionsredis.connection.pool.idle: Idle connections
-
Spring Boot Actuator:
curl http://localhost:8080/actuator/metrics
-
CloudWatch Dashboard:
- Navigate to AWS CloudWatch
- Select "CacheService" namespace
- View metrics and create dashboards
The system implements several fault tolerance mechanisms:
-
Circuit Breaker:
- Opens when failure rate exceeds 50%
- Waits 1 second before allowing new requests
- Requires 2 successful calls to close
-
Retry Mechanism:
- Maximum 3 retry attempts
- 100ms wait between retries
- Exponential backoff
-
Data Replication:
- Data replicated to 2 backup nodes
- Automatic failover support
- Connection Pooling: Optimized Redis connection pool
- Batch Operations: Redis pipelining for bulk operations
- Consistent Hashing: Efficient data distribution
- Memory Management: Proper TTL handling
mvn test# Using Apache Benchmark
ab -n 10000 -c 100 http://localhost:8080/api/cache/test-key- Redis authentication required
- SSL/TLS for Redis connections
- Proper IAM roles for AWS resources
- VPC and security group configuration
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
For support, please open an issue in the GitHub repository or contact the maintainers.