Microservices using Spring boot 3.5 Keycloak, Caching and API limiting
Project Overview
This project is a Spring Boot 3.5–based web application designed to demonstrate a modern, production-ready microservice architecture. The core functionality is a simple “Hello World” REST API, but the application integrates several enterprise-grade features that highlight best practices in scalability, security, and performance optimization.
Security and JWT-Based Authorization
The application uses Keycloak as an external Authorization Server, implementing OAuth2 and OpenID Connect standards. When a user logs in, Keycloak issues a JWT (JSON Web Token), which is then included in the Authorization header of API requests. The Spring Boot application validates this JWT to authenticate users and determine their access permissions.
Access to the controller endpoints is protected using role-based authorization, specifically requiring the ROLE_USER authority. This ensures that only authenticated users with the appropriate role can access secured APIs, maintaining a strong and flexible security boundary between users and services.
Performance Optimization with Redis
To enhance performance and reduce latency, the project incorporates Redis as a distributed caching layer. Frequently accessed data and authentication tokens are cached to minimize repetitive database calls and improve response times. This integration demonstrates how Spring Boot applications can achieve high performance and scalability through efficient caching strategies.
API Rate Limiting and Resilience
The project also includes Resilience4j, a lightweight fault tolerance library, to implement API rate limiting and improve system resilience. By configuring rate limiters, circuit breakers, and bulkhead patterns, the application prevents overloading, ensures graceful degradation under heavy traffic, and protects backend services from abuse or failure cascades.
Containerization and Deployment
A Docker Compose configuration is included to simplify local deployment and environment setup. The docker-compose.yml file orchestrates three core services:
- Redis — for caching and performance optimization
- Keycloak — for authentication and token management
- Spring Boot Application — the main service providing the REST API
This setup allows the entire stack to be started with a single command, ensuring consistent and reproducible environments for development and testing.
Summary
Overall, this project showcases how to build a secure, performant, and resilient microservice using Spring Boot 3.5. It combines modern Java development practices with powerful open-source tools — Keycloak for security, Redis for caching, and Resilience4j for stability — resulting in a clean, extensible foundation suitable for enterprise-grade applications.
