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.java with @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: CacheItem data model with Jackson serialization
  • CRaC Integration: RedisCracResource for 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 value
  • POST / - Store key-value pair
  • POST /ttl - Store with Time-To-Live
  • PUT /{key} - Update existing value
  • DELETE /{key} - Remove specific key
  • GET / - List all keys
  • DELETE / - Clear all cache
  • GET /{key}/expiration - Get TTL information

Catalog Operations (/api/catalog)###

  • GET /{id} - Get cached catalog item with @Cacheable
  • POST /{id} - Update catalog with @CachePut
  • DELETE /{id} - Evict specific item with @CacheEvict
  • DELETE /all - Evict all catalog cache

Health Monitoring (/health)###

  • GET /redis - Comprehensive Redis health check
  • GET /redis/simple - Basic ping test
  • Actuator endpoints at /actuator/health

CRaC Administration (/admin)###

  • POST /checkpoint - Trigger CRaC checkpoint via Core.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###

  1. Application starts with -XX:CRaCCheckpointTo=cr JVM argument
  2. Checkpoint triggered via /admin/checkpoint endpoint or jcmd JDK.checkpoint
  3. Graceful shutdown of Tomcat server
  4. Application state saved to checkpoint files

Restore Process###

  1. Restore with -XX:CRaCRestoreFrom=cr JVM argument
  2. Spring lifecycle beans restart automatically
  3. Tomcat server restarts on port 8080
  4. Cache data persists across the restore cycle

Caching Strategy##

Spring Cache Integration###

  • @Cacheable for read-through caching
  • @CachePut for write-through updates
  • @CacheEvict for 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