A high-performance Weather API Proxy engineered with Spring Boot 4 and Redis, demonstrating advanced backend architecture patterns such as dual-mapper serialization for secure polymorphic caching and distributed rate limiting.
Problem: Redis requires type metadata (e.g., @class) for correct deserialization, but exposing this metadata in API responses is a security risk.
Solution: Implemented the Local Mapper Pattern:
- Internal Dirty Mapper (Redis): Uses
activateDefaultTyping+JsonTypeInfo.As.PROPERTYto store type metadata. - External Clean Mapper (API): Standard Spring Boot mapper without class metadata.
Result:
- Cache deserializes cleanly.
- Frontend receives clean, safe JSON.
A custom jakarta.servlet.Filter protects the API from overuse.
Mechanism:
- Client IP is extracted.
- Redis
INCRincrements a counter key:rate_limit:{ip}. - TTL of 60 seconds is applied on the first request.
- If count > 10, return 429 Too Many Requests.
Why Redis? Works across distributed instances, making it horizontally scalable.
graph LR
A[Client Request] --> B{Redis Counter < 10?}
B -- Yes --> C[Proceed to Controller]
B -- No --> D[Return 429 Too Many Requests]
- Uses Spring Boot 4 (Preview) and modern Jackson 3 (
tools.jackson.databind). - Fully migrated from
com.fasterxml.jackson.
- Framework: Spring Boot 4.0 (Snapshot/Preview)
- Language: Java 17+
- Caching/DB: Redis (Dockerized)
- Libraries: Spring Data Redis, Jackson 3, Lombok
- Tools: Maven, Docker, Postman
All incoming requests pass through the custom RedisRateLimitingFilter.
-
Cache Hit: Return cached weather data instantly.
-
Cache Miss:
- Call external Weather API
- Serialize with internal mapper
- Store in Redis with TTL
- Return clean API JSON
- Java 17+
- Maven
- Redis (localhost:6379)
docker run -d -p 6379:6379 --name my-redis redisgit clone https://github.com/your-username/advanced-redis-weather-api.git
cd advanced-redis-weather-api
mvn clean installmvn spring-boot:runGET http://localhost:8080/weather/London{
"city": "London",
"country": "UK",
"temperature": 15.5,
"condition": "Cloudy",
"source": "Api Call"
}Status: 429 Too Many Requests
{
"error": "Too Many Requests",
"message": "Rate limit exceeded. Try again later."
}src/main/java
├── configs
│ └── RedisConfigs.java
├── controller
│ └── WeatherController.java
├── filter
│ └── RedisRateLimitingFilter.java
├── model
│ └── WeatherResponse.java
├── services
│ └── WeatherService.java
└── RedisCachingApplication.java
(Images + direct links)
- Implemented Cache-Aside pattern reducing API calls by ~90%.
- Built a distributed rate limiter using Redis atomic operations.
- Early adopter of Spring Boot 4 + Jackson 3 modernization.
Built by Vishal







