A production-grade, event-driven microservices platform that ingests system events, detects anomalies using statistical AI models, and manages incidents β built to demonstrate backend engineering, distributed systems design, and DevOps expertise.
- About
- Architecture
- Tech Stack
- Service Breakdown
- Data Flow
- How to Run
- API Reference & Demo
- Key Engineering Decisions
- CI/CD Pipeline
- Project Structure
Modern distributed systems generate millions of events per hour β logs, traces, alerts. Manual triage is slow, noisy, and error-prone. This platform solves that by:
- Ingesting raw events via a REST API and streaming them through Kafka.
- Enriching events with severity scoring and persisting to MongoDB + Elasticsearch.
- Managing incidents with CRUD APIs backed by MySQL and Redis caching.
- Scoring anomalies using a Python AI service with z-score-based statistical analysis.
βββββββββββββββββββββββββββββββ
β Client / curl β
ββββββββ¬βββββββββββββββββββββββ
β POST /api/events
βΌ
βββββββββββββββββββββββββ
β Event Ingestion Svc β (Java Β· Spring Boot)
β :6001 β
βββββββββββββ¬ββββββββββββ
β Kafka β raw-events
βΌ
βββββββββββββββββββββββββ
β Processor Service β (Java Β· Spring Boot)
β :6002 β
ββββ¬βββββββββ¬βββββββββ¬βββ
β β β
βββββββββββΌβββ βββββΌβββββ βββΌββββββββββββββββ
β MongoDB β β ES β β Kafka β
β (raw docs) β β(search)β β enriched-events β
ββββββββββββββ ββββββββββ ββββββββββ¬βββββββββ
β
βββββββββββββββββββββββββββββΌββββββββ
β Incident Service β (Java Β· Spring Boot)
β :6003 β
ββββββββ¬βββββββββββββ¬ββββββββββββββββ
β β
βββββββΌββββ βββββββΌββββ
β MySQL β β Redis β
β (CRUD) β β (cache) β
βββββββββββ βββββββββββ
βββββββββββββββββββββββββ
β AI Analysis Service β (Python Β· FastAPI)
β :6004 β
βββββββββββββββββββββββββ
Stateless anomaly scoring
via z-score + severity model
| Layer | Technology |
|---|---|
| Backend | Java 17, Spring Boot 3.3, Spring Data JPA, Kafka |
| AI Service | Python 3.11, FastAPI, Pydantic, NumPy |
| Messaging | Apache Kafka (Confluent 7.5) with Zookeeper |
| Databases | MySQL 8.4 (relational), MongoDB 7.0 (document) |
| Search | Elasticsearch 8.15 (full-text event search) |
| Caching | Redis 7.2 (incident lookup caching via @Cacheable) |
| DevOps | Docker, Docker Compose, Jenkins CI/CD |
| Observability | Spring Actuator (/health, /metrics, /info) |
| Aspect | Detail |
|---|---|
| Language | Java 17 Β· Spring Boot 3 |
| Purpose | REST gateway β accepts raw events and publishes to Kafka |
| Key Classes | EventController β validates request β EventPublisherService β Kafka raw-events topic |
| Input | JSON with serviceName, severity, message, traceId, tags |
| Output | Async acknowledgement + Kafka message keyed by traceId |
| Aspect | Detail |
|---|---|
| Language | Java 17 Β· Spring Boot 3 |
| Purpose | Consumes raw events, enriches with anomaly scores, persists |
| Key Classes | RawEventConsumer β EnrichmentService (severity-based scoring) β PersistenceService |
| Stores To | MongoDB (raw event documents), Elasticsearch (searchable index), Kafka enriched-events topic |
| Aspect | Detail |
|---|---|
| Language | Java 17 Β· Spring Boot 3 |
| Purpose | Incident lifecycle management (Create, Read, Update status) |
| Key Classes | IncidentController β IncidentService β IncidentRepository (JPA) |
| Features | MySQL persistence, Redis @Cacheable for reads, composite DB index on (status, severity, updatedAt) |
| Aspect | Detail |
|---|---|
| Language | Python 3.11 Β· FastAPI |
| Purpose | Stateless anomaly scoring and root-cause suggestion |
| Algorithm | Weighted composite: 40% latency z-score + 30% error rate + 30% severity factor |
| Output | anomaly_score, summary, probable_root_cause, remediation steps |
1. Client sends POST /api/events to Ingestion Service
2. Ingestion validates & publishes to Kafka topic "raw-events" (keyed by traceId)
3. Processor consumes from "raw-events":
a. Enriches payload with severity-based anomaly score
b. Saves to MongoDB (raw_events collection)
c. Indexes into Elasticsearch (events-index)
d. Publishes enriched event to Kafka topic "enriched-events"
4. Incident Service manages incident lifecycle via REST APIs (MySQL + Redis)
5. AI Analysis Service can be called on-demand to score any event for anomalies
- Docker Desktop (Docker Engine + Docker Compose)
- Ports
6001β6004available on localhost
cd projects/ai-incident-intelligence
docker compose up -d --buildThis spins up 10 containers: 4 application services + Kafka + Zookeeper + MySQL + MongoDB + Redis + Elasticsearch.
# Event Ingestion
curl http://localhost:6001/actuator/health # {"status":"UP"}
# Processor
curl http://localhost:6002/actuator/health # {"status":"UP"}
# Incident Service
curl http://localhost:6003/actuator/health # {"status":"UP"}
# AI Analysis
curl http://localhost:6004/health # {"status":"ok"}docker compose downcurl -X POST http://localhost:6001/api/events \
-H 'Content-Type: application/json' \
-d '{
"serviceName": "checkout-service",
"severity": "HIGH",
"message": "Timeout spikes while writing order",
"traceId": "abc-123",
"tags": ["checkout", "mysql"]
}'Response:
{
"status": "ACCEPTED",
"traceId": "abc-123",
"timestamp": "2026-03-03T10:15:30.123Z"
}curl -X POST http://localhost:6003/api/incidents \
-H 'Content-Type: application/json' \
-d '{
"incidentKey": "INC-001",
"serviceName": "checkout-service",
"severity": "HIGH",
"summary": "Persistent timeout in checkout flow"
}'curl http://localhost:6003/api/incidents?status=OPENcurl -X PATCH http://localhost:6003/api/incidents/1/status \
-H 'Content-Type: application/json' \
-d '{"status": "RESOLVED"}'curl -X POST http://localhost:6004/analyze \
-H 'Content-Type: application/json' \
-d '{
"service_name": "checkout-service",
"severity": "HIGH",
"message": "Timeout spikes",
"recent_latencies_ms": [120, 130, 125, 450, 980],
"error_rate": 0.35
}'Response:
{
"anomaly_score": 0.593,
"summary": "checkout-service shows anomaly score 0.593. Severity=HIGH, error_rate=0.35.",
"probable_root_cause": "Transient service degradation",
"remediation": [
"Check p95/p99 latency and DB connection pool usage",
"Inspect recent deploys and dependency health",
"Scale affected service and enable circuit-breaker policy"
]
}| Decision | Rationale |
|---|---|
| Kafka as event backbone | Decouples producers from consumers, enables replay, and supports back-pressure β essential for high-throughput event streams |
| Polyglot persistence (MySQL + MongoDB + Elasticsearch + Redis) | Each store is used for what it's best at: relational integrity, flexible documents, full-text search, and low-latency caching |
| Polyglot services (Java + Python) | Java/Spring Boot for robust backend services; Python/FastAPI for lightweight ML/statistical workloads β demonstrates cross-language microservice communication |
| traceId as Kafka partition key | Ensures all events from the same trace land in the same partition β ordering guarantee per trace |
| Z-score based anomaly detection | Lightweight statistical approach for latency spike detection without heavy ML dependencies; easily replaceable with a trained model |
Composite DB index on (status, severity, updatedAt) |
Optimizes the most common query pattern for incident dashboards |
Redis @Cacheable |
Prevents repeated DB hits for frequently accessed incident lookups |
| Multi-stage Docker builds | Keeps production images small (JRE-only, no build tools) |
The project includes a Jenkinsfile with a 5-stage pipeline:
Checkout β Unit Tests β Build Docker Images β Deploy β Smoke Tests
- Each Java service is tested independently with
mvn test. - Docker images are tagged with the Jenkins build number (
$BUILD_NUMBER). - Deploy stage is templated for AWS (ECS/EC2) deployment scripts.
ai-incident-intelligence/
βββ docker-compose.yml # Orchestrates all 10 containers
βββ Jenkinsfile # CI/CD pipeline definition
βββ PROJECT_OVERVIEW.md # β You are here
βββ README.md
βββ docs/
βββ infrastructure/
β βββ mysql-init.sql # DB + user bootstrap script
βββ services/
βββ event-ingestion-service/ # Java Β· REST β Kafka producer
β βββ Dockerfile
β βββ pom.xml
β βββ src/main/java/com/aiincident/ingestion/
β βββ api/EventController.java
β βββ config/KafkaProducerConfig.java
β βββ domain/EventRequest.java
β βββ service/EventPublisherService.java
β
βββ processor-service/ # Java Β· Kafka consumer β Mongo + ES
β βββ Dockerfile
β βββ pom.xml
β βββ src/main/java/com/aiincident/processor/
β βββ config/KafkaConfig.java
β βββ consumer/RawEventConsumer.java
β βββ domain/EventEnvelope.java
β βββ service/{EnrichmentService, PersistenceService}.java
β
βββ incident-service/ # Java Β· MySQL + Redis CRUD
β βββ Dockerfile
β βββ pom.xml
β βββ src/main/java/com/aiincident/incident/
β βββ api/IncidentController.java
β βββ domain/{Incident, IncidentRequest}.java
β βββ repository/IncidentRepository.java
β βββ service/IncidentService.java
β
βββ ai-analysis-service/ # Python Β· FastAPI anomaly scorer
βββ Dockerfile
βββ requirements.txt
βββ app/main.py
Nikhil Srivastava β GitHub