This project demonstrates a microservice architecture using Spring Boot, Apache Kafka, and an observability stack.
This project demonstrates:
- Microservice Architecture: Service decomposition and communication
- Event-Driven Design: Asynchronous processing with Kafka
- Observability: Monitoring, logging, and distributed tracing
- Containerization: Docker setup
- Configuration Management: Environment-based configuration
- Documentation: API documentation
- Framework: Spring Boot 3.5.5
- Language: Java 17
- Message Broker: Apache Kafka 4.1.0
- Build Tool: Gradle
- Containerization: Docker & Docker Compose
- Monitoring: Prometheus, Grafana, Loki, Promtail
- Distributed Tracing: Zipkin with Micrometer Tracing
- Documentation: OpenAPI 3 / Swagger
This project demonstrates an event-driven microservice architecture with the following components:
- notification-gateway: REST API that receives requests and publishes to Kafka
- notification-dispatcher: Kafka consumer that processes notification events
- common-lib: Shared DTOs and models
- Observability Stack: Prometheus, Grafana, Loki, Promtail, and Zipkin
- Java 17+
- Docker & Docker Compose
- Gradle (optional, using wrapper)
Note: Includes VS Code devcontainer with development tools.
-
Clone the repository
git clone <repository-url> cd spring-boot-kafka-microservice-example
-
Start all services with Docker Compose
docker-compose up -d
-
Verify services are running
docker-compose ps
Send a notification via REST API:
curl -X POST http://localhost:8080/api/notifications \
-H "Content-Type: application/json" \
-d '{
"type": "EMAIL",
"to": "user@example.com",
"message": "Hello from Spring Boot Kafka!"
}'Expected Response:
{
"id": "generated-uuid",
"message": "Notification queued successfully",
"timestamp": "2025-09-22T10:30:00Z"
}The notification will be:
- Received by the notification-gateway
- Published to Kafka topic
notifications - Consumed by notification-dispatcher
- Processed based on notification type (EMAIL, WEB, PUSH)
- Purpose: REST API for receiving notification requests
- Tech Stack: Spring Boot, Spring WebFlux, Kafka Producer
- Health Check:
http://localhost:8080/actuator/health - API Documentation: Swagger UI is available at startup (
http://localhost:8080/swagger-ui/index.html)
- Purpose: Kafka consumer for processing notifications
- Tech Stack: Spring Boot, Kafka Consumer, Strategy Pattern
- Health Check:
http://localhost:8081/actuator/health - Processing: Supports EMAIL, WEB, and PUSH notification types
- Broker: Apache Kafka 4.1.0
- Topic:
notifications(auto-created) - UI: Kafdrop is available at
http://localhost:9000
Access the monitoring stack:
| Service | URL | Credentials | Purpose |
|---|---|---|---|
| Grafana | http://localhost:3000 | admin/admin123 | Dashboards & Visualization |
| Prometheus | http://localhost:9090 | - | Metrics Collection |
| Zipkin | http://localhost:9411 | - | Distributed Tracing |
| Kafdrop | http://localhost:9000 | - | Kafka Topic Browser |
- Application metrics (JVM, HTTP requests)
- Kafka metrics (producer/consumer performance)
- System metrics (CPU, memory)
- Logs with trace correlation
- Request tracing across services
The project includes pre-configured Grafana dashboards:
- Notification Service Logs: Service logs with filtering and trace correlation
- API Flow Monitoring: Real-time monitoring of the notification flow
- Consumer Processing: Kafka consumer processing logs and metrics
- Trace ID Search: Search and correlate logs by trace ID across services
Access dashboards at: http://localhost:3000 (admin/admin123)
# Build all modules
./gradlew build
# Build specific module
./gradlew :notification-gateway:build
./gradlew :notification-dispatcher:build-
Start Kafka locally
docker-compose up -d kafka kafdrop
-
Run services with Gradle
# Terminal 1 - Gateway ./gradlew :notification-gateway:bootRun # Terminal 2 - Dispatcher ./gradlew :notification-dispatcher:bootRun
| Variable | Default Value | Description |
|---|---|---|
KAFKA_BOOTSTRAP |
kafka:9092 |
Kafka broker connection string |
NOTIFICATIONS_TOPIC |
notifications |
Kafka topic name |
ZIPKIN_ENDPOINT |
http://zipkin:9411/api/v2/spans |
Zipkin tracing endpoint |
TRACING_SAMPLING_PROBABILITY |
1.0 |
Trace sampling rate (0.0 to 1.0) |
Services use application.yml for configuration.
The project includes examples of pre-configured files for the observability stack:
observability/grafana/provisioning/datasources/datasources.yml- Auto-configures Prometheus, Loki, and Zipkin data sourcesobservability/grafana/provisioning/dashboards/notification-logs-dashboard.json- Service logs dashboard with filteringobservability/grafana/provisioning/dashboards/api-flow-monitoring.json- Real-time API flow monitoring dashboard
observability/prometheus.yml- Scrape configuration for Spring Boot Actuator endpoints
observability/loki-config.yml- Log storage and querying configuration
observability/promtail-config.yml- Log shipping configuration with Spring Boot log parsing