Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Incident Intelligence Platform

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.


Table of Contents


About

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:

  1. Ingesting raw events via a REST API and streaming them through Kafka.
  2. Enriching events with severity scoring and persisting to MongoDB + Elasticsearch.
  3. Managing incidents with CRUD APIs backed by MySQL and Redis caching.
  4. Scoring anomalies using a Python AI service with z-score-based statistical analysis.

Architecture

                                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                β”‚        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

Tech Stack

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)

Service Breakdown

1. Event Ingestion Service β€” :6001

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

2. Processor Service β€” :6002

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

3. Incident Service β€” :6003

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)

4. AI Analysis Service β€” :6004

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

Data Flow

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

How to Run

Prerequisites

  • Docker Desktop (Docker Engine + Docker Compose)
  • Ports 6001–6004 available on localhost

Start (single command)

cd projects/ai-incident-intelligence
docker compose up -d --build

This spins up 10 containers: 4 application services + Kafka + Zookeeper + MySQL + MongoDB + Redis + Elasticsearch.

Verify All Services Are Healthy

# 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"}

Stop Everything

docker compose down

API Reference & Demo

1. Ingest an Event

curl -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"
}

2. Create an Incident

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"
  }'

3. List Open Incidents

curl http://localhost:6003/api/incidents?status=OPEN

4. Update Incident Status

curl -X PATCH http://localhost:6003/api/incidents/1/status \
  -H 'Content-Type: application/json' \
  -d '{"status": "RESOLVED"}'

5. AI Anomaly Analysis

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"
  ]
}

Key Engineering Decisions

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)

CI/CD Pipeline

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.

Project Structure

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

Contact

Nikhil Srivastava β€” GitHub

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages