RediServe is a distributed cache + DB fetcher microservices playground, built with:
- Java 17 + Spring Boot 3
- Spring Cloud Config (centralized configuration)
- Postgres (for persistence)
- Redis (for caching)
- Apache Kafka (for async cache policy + invalidation events)
- Docker Compose (for local infra)
This is a pet project to learn and experiment with:
- Horizontal scalability
- Cache-aside and read-through patterns
- Centralized cache policy management
- Event-driven orchestration with Kafka
- Configurable caching behavior
- Hot-reloading configs without redeploy
RediServe/
├── pom.xml # Parent Maven POM (manages versions + dependency management)
├── config-repo/ # Centralized configs (picked up by Spring Cloud Config Server)
│ ├── cache-gateway.yml
│ ├── db-fetcher.yml
│ └── orchestrator.yml
├── config-server/ # Spring Cloud Config Server
├── services/
│ ├── cache-gateway/ # Entrypoint for clients (talks to Redis + DB fetcher, listens to Kafka)
│ ├── db-fetcher/ # Fetches from Postgres, source of truth for data
│ └── orchestrator/ # Publishes cache policy + invalidation events via Kafka
└── docker-compose.yml # Infra: Redis + Postgres + Kafka + Zookeeper
- Java 17+
- Maven 3.9+
- Docker + Docker Compose
- (Optional) Homebrew for
redis-cli/psql curlor Postman for testing
Bring up Postgres, Redis, Kafka, and Zookeeper:
docker compose up -dCheck running containers:
docker psYou should see:
rediserve-postgresrediserve-redisrediserve-kafkarediserve-zookeeper
docker exec -it rediserve-redis redis-cli ping
# PONGdocker exec -it rediserve-postgres psql -U postgres -d rediserve
\conninfo;docker exec -it rediserve-kafka /usr/bin/kafka-topics --list --bootstrap-server localhost:9092You should see topics like:
cache.policy.updatescache.namespace.invalidate
Start Config Server first:
mvn spring-boot:run -pl config-serverThen run the apps:
mvn spring-boot:run -pl services/db-fetcher
mvn spring-boot:run -pl services/cache-gateway
mvn spring-boot:run -pl services/orchestratorCheck configs being served:
http://localhost:8888/cache-gateway/default
http://localhost:8888/db-fetcher/default
http://localhost:8888/orchestrator/default
curl -X GET "http://localhost:8081/cache/shop/products/1"- Reads from Redis if present.
- Falls back to
db-fetcheron cache miss (read-through).
curl -X POST "http://localhost:8083/admin/namespaces/shop/policy" \
-H "Content-Type: application/json" \
-d '{"ttlSeconds": 5, "consistencyMode": "READ_THROUGH"}'- Orchestrator publishes to
cache.policy.updates. - Cache-Gateway listens and updates its in-memory policy registry dynamically.
- No restart needed.
curl -X POST "http://localhost:8083/admin/namespaces/shop/invalidate"- Orchestrator publishes to
cache.namespace.invalidate. - Cache-Gateway listens and deletes all matching Redis keys.
- Infra running (
docker compose upworks, Redis + Postgres healthy) - Empty Spring Boot services build and start
- Verified connectivity (
PONGfrom Redis,\conninfofrom Postgres)
- Config Server running (
config-server/) - Centralized config files in
config-repo/ -
db-fetcherexposes REST endpoint to fetch products from Postgres -
cache-gatewayfetches from Redis, falls back todb-fetcheron cache-miss - Redis caching with type-safe serialization using
GenericJackson2JsonRedisSerializer - TTL is configurable per namespace/entity via policy registry
- Health endpoints exposed (
/actuator/health)
- Added orchestrator service for centralized cache admin
- Kafka topics for cache policy + invalidation events
- Gateway listens on Kafka and applies changes dynamically
- REST → Kafka → Gateway flow verified with curl
- Hot reload configs with Spring Cloud Config +
@RefreshScope - Policies updated at runtime via Orchestrator
- Cache-Gateway applies new TTLs / consistency modes without restart
- Deliverable: Change caching rules dynamically
- Add Docker Compose definitions for all services (cache-gateway, db-fetcher, orchestrator, config-server)
- Add integration tests (Redis + Postgres + Kafka + services)
- Explore service discovery (Eureka / Consul) instead of hardcoding hostnames
- Add metrics + dashboards (Prometheus + Grafana)
- Explore write-through and write-behind caching modes
- Add sequence diagrams to README for better architecture visibility