Spring Boot Redis CRaC Project#
Project Summary##
This is a Spring Boot 3.4.6 application demonstrating Java CRaC (Coordinated Restore at Checkpoint) functionality integrated with Redis caching. The project showcases application checkpoint/restore capabilities while maintaining cache persistence across checkpoint cycles.
Technical Architecture##
Core Technologies###
- Spring Boot Version: 3.4.6
- Java Version: 17 (requires CRaC-enabled JDK)
- Redis Client: Lettuce (CRaC-compatible, non-blocking)
- CRaC Library Version: 1.5.0
- Documentation: SpringDoc OpenAPI 3 (v2.3.0)
- Build Tool: Maven with spring-boot-maven-plugin
Application Structure###
The application follows a layered architecture:
- Main Application:
SpringRedisCracApplication.javawith@EnableCaching - Configuration Layer: Redis and OpenAPI configuration classes
- Controller Layer: REST endpoints for cache, health, catalog, and admin operations
- Service Layer: Business logic for cache operations and health monitoring
- Model Layer:
CacheItemdata model with Jackson serialization - CRaC Integration:
RedisCracResourcefor lifecycle logging
Performance Characteristics##
Startup Times (from logs)###
- Cold Start: 12.366 seconds (process running for 11.47 seconds)
- CRaC Restore: Approximately 1 second (92% faster startup)
- JVM Restore Process: 1024ms as logged in the execution
Cache Persistence###
The application demonstrates that cached data survives checkpoint/restore cycles, maintaining state across CRaC operations.
API Endpoints##
Cache Operations (/api/cache)###
GET /{key}- Retrieve cached valuePOST /- Store key-value pairPOST /ttl- Store with Time-To-LivePUT /{key}- Update existing valueDELETE /{key}- Remove specific keyGET /- List all keysDELETE /- Clear all cacheGET /{key}/expiration- Get TTL information
Catalog Operations (/api/catalog)###
GET /{id}- Get cached catalog item with@CacheablePOST /{id}- Update catalog with@CachePutDELETE /{id}- Evict specific item with@CacheEvictDELETE /all- Evict all catalog cache
Health Monitoring (/health)###
GET /redis- Comprehensive Redis health checkGET /redis/simple- Basic ping test- Actuator endpoints at
/actuator/health
CRaC Administration (/admin)###
POST /checkpoint- Trigger CRaC checkpoint viaCore.checkpointRestore()
Configuration Management##
Environment Variables###
SPRING_REDIS_HOST(default: localhost)SPRING_REDIS_PORT(default: 6379)REDIS_SSL_ENABLED(default: false)
Profile-Based Configuration###
- default: Basic development setup
- dev: Debug logging enabled
- test: Test-specific Redis configuration
- prod: Production settings with disabled Swagger UI
Redis Configuration###
- Connection pooling with Lettuce
- Configurable timeout (2000ms default)
- Jackson JSON serialization for values
- String serialization for keys
- Pool settings: max-active: 8, max-idle: 8, min-idle: 0
CRaC Integration Details##
Checkpoint Process###
- Application starts with
-XX:CRaCCheckpointTo=crJVM argument - Checkpoint triggered via
/admin/checkpointendpoint orjcmd JDK.checkpoint - Graceful shutdown of Tomcat server
- Application state saved to checkpoint files
Restore Process###
- Restore with
-XX:CRaCRestoreFrom=crJVM argument - Spring lifecycle beans restart automatically
- Tomcat server restarts on port 8080
- Cache data persists across the restore cycle
Caching Strategy##
Spring Cache Integration###
@Cacheablefor read-through caching@CachePutfor write-through updates@CacheEvictfor cache invalidation- Two cache regions: "cache" and "cache_collection_attribute"
Redis Operations###
- Direct RedisTemplate usage for low-level operations
- Key prefixing with "cache:" for organization
- TTL support with configurable time units
- Bulk operations for key management
Error Handling and Monitoring##
Health Checks###
- Redis connection validation via ping
- Template operation testing
- Key count monitoring
- Connection factory status reporting
Exception Management###
- Comprehensive error responses with status codes
- Logging at appropriate levels (INFO, DEBUG, ERROR)
- Graceful degradation for unavailable services
Testing Infrastructure##
- JUnit 5 with Spring Boot Test
- Test profiles with separate configuration
- Testcontainers support for integration testing
- Context loading verification
Build and Deployment##
Maven Configuration###
- Spring Boot starter dependencies for web, Redis, cache, actuator
- CRaC library inclusion
- Test execution configuration with Surefire and Failsafe plugins
- JVM arguments configuration for CRaC support
Execution Requirements###
- Linux environment (CRaC requirement)
- CRaC-enabled JDK (e.g., Azul Zulu with CRaC support)
- Redis server (local or network accessible)
- Specific JVM flags for checkpoint/restore operations
API Documentation##
- Swagger UI available at
/swagger-ui.html - OpenAPI 3 specification at
/v3/api-docs - Comprehensive operation descriptions with examples
- Request/response schemas with validation annotations
- Environment-specific server configuration
This project serves as a production-ready demonstration of CRaC technology integration with Spring Boot and Redis, showing significant startup performance improvements while maintaining cache state persistence.
Architecture Diagram
Drag to pan, scroll to zoom