GridPulse is a production-style home energy tracking platform built with a microservices architecture to collect power usage events, aggregate consumption metrics, trigger alerts, and expose observability-ready APIs for real-time and historical energy insights.
GridPulse models how a real-world home energy management product ingests power readings from smart plugs or meters, processes high-volume device events reliably, stores relational and time-series data separately, and notifies residents when usage crosses predefined thresholds.
The system is designed around a practical backend architecture:
- HTTP APIs for users, devices, usage, alerts, and insights
- Kafka-based event streaming for decoupled ingestion and processing
- MySQL for durable domain and transactional data
- InfluxDB for time-series energy measurements
- JWT-secured API Gateway for centralized access control
- Observability stack with Prometheus and Grafana
- Local development tooling with Keycloak and Mailpit
- Spring AI-powered insights for energy usage summaries and recommendations
Raw energy telemetry from smart plugs and meters is noisy, high-volume, and continuous. A production-grade system must handle:
- Reliable ingestion without blocking client requests
- Decoupled processing for scalability
- Separate storage strategies for metadata and measurements
- Threshold-based alerting
- Auditability and operational visibility
- Resilient public APIs behind a single secure entry point
GridPulse demonstrates that split architecture in a clean, practical form.
- Track per-device energy usage over time
- Aggregate consumption for billing-style views
- Alert when instantaneous or total usage exceeds a limit
- Secure all public HTTP traffic through a gateway with JWT validation
- Inspect service health, latency, errors, and circuit-breaker state
- Generate AI-assisted energy insights and usage summaries
flowchart TB
%% =========================
%% CLEAN MODERN STYLING
%% =========================
classDef client fill:#f59e0b,stroke:#d97706,color:#fff,stroke-width:2px
classDef gateway fill:#2563eb,stroke:#1d4ed8,color:#fff,stroke-width:3px
classDef service fill:#0f172a,stroke:#334155,color:#fff,stroke-width:2px
classDef kafka fill:#dc2626,stroke:#991b1b,color:#fff,stroke-width:3px
classDef db fill:#059669,stroke:#047857,color:#fff,stroke-width:2px
classDef infra fill:#7c3aed,stroke:#6d28d9,color:#fff,stroke-width:2px
classDef ai fill:#ec4899,stroke:#be185d,color:#fff,stroke-width:2px
%% =========================
%% ENTRY
%% =========================
User[π€ User / Dashboard]:::client
Device[π Smart Plug / Meter]:::client
Gateway[π API Gateway<br/>:9000]:::gateway
User --> Gateway
Device --> Gateway
%% =========================
%% SERVICES
%% =========================
UserSvc[π€ User Service<br/>:8080]:::service
DeviceSvc[π Device Service<br/>:8081]:::service
IngestionSvc[π₯ Ingestion Service<br/>:8082]:::service
UsageSvc[β‘ Usage Service<br/>:8083]:::service
AlertSvc[π¨ Alert Service<br/>:8084]:::service
InsightSvc[π§ Insight Service<br/>:8085]:::service
Gateway --> UserSvc
Gateway --> DeviceSvc
Gateway --> IngestionSvc
Gateway --> UsageSvc
Gateway --> AlertSvc
Gateway --> InsightSvc
%% =========================
%% STREAMING
%% =========================
Kafka[(π₯ Apache Kafka)]:::kafka
IngestionSvc --> Kafka
Kafka --> UsageSvc
UsageSvc --> Kafka
Kafka --> AlertSvc
%% =========================
%% STORAGE
%% =========================
MySQL[(π’οΈ MySQL)]:::db
Influx[(π InfluxDB)]:::db
Mailpit[(βοΈ Mailpit)]:::db
UserSvc --> MySQL
DeviceSvc --> MySQL
AlertSvc --> MySQL
UsageSvc --> Influx
AlertSvc --> Mailpit
%% =========================
%% PLATFORM
%% =========================
Keycloak[π Keycloak]:::infra
Prom[π‘ Prometheus]:::infra
Grafana[π Grafana]:::infra
Ollama[π€ Ollama]:::ai
Gateway -. Auth .-> Keycloak
Prom --> Grafana
InsightSvc -. AI .-> Ollama
| Layer | Technology |
|---|---|
| Language | Java 21 |
| Framework | Spring Boot 4 for domain services and gateway |
| AI Service | Spring Boot 3.5 + Spring AI |
| Cloud Stack | Spring Cloud 2025.1.0 |
| Gateway | Spring Cloud Gateway (Server WebMVC) |
| Resilience | Resilience4j Circuit Breaker |
| Messaging | Apache Kafka (KRaft) |
| Relational DB | MySQL 8 |
| Time-Series DB | InfluxDB 2 |
| Identity | Keycloak |
| Mailpit | |
| Observability | Micrometer, Prometheus, Grafana |
| API Docs | springdoc-openapi |
| Containerization | Docker, Docker Compose |
| Build Tool | Maven with mvnw per service |
Acts as the single public entry point for all incoming HTTP traffic and centralizes request routing across internal services. Responsibilities
Technologies
|
Responsible for managing smart devices connected to the platform, including registration, ownership mapping, metadata storage, and lifecycle status management. Responsibilities
Technologies
|
Processes incoming energy consumption readings from the streaming pipeline and performs aggregation, threshold analysis, and time-series persistence. Responsibilities
Technologies
|
Monitors processed consumption events and evaluates predefined thresholds or abnormal usage patterns. Responsibilities
Technologies
|
Provides intelligent energy usage insights using Spring AI and optional Ollama integration. Responsibilities
Technologies
|
Handles outbound communication workflows such as alerts, warnings, and energy notifications. Responsibilities
Technologies
|
Provides authentication and identity management using JWT-based security. Responsibilities
Technologies
|
Implements production-style monitoring and diagnostics for operational visibility. Responsibilities
Technologies
|
- Secure JWT-based authentication
- Centralized API Gateway routing
- Event-driven processing with Kafka
- Separate storage for transactional and time-series workloads
- Threshold-based alerting pipeline
- AI-generated energy insights
- OpenAPI aggregation at the gateway
- Circuit breaker protection with Resilience4j
- Metrics and dashboards for runtime visibility
- Dockerized local development environment
- Maven wrapper support for consistent builds
- A smart device or simulated meter sends a power reading.
- The request enters through the API Gateway.
- The relevant service validates and persists domain data.
- The reading is published to Kafka.
- The Usage Service aggregates and stores measurements in InfluxDB.
- The Alert Service evaluates thresholds.
- Notification workflows are triggered when needed.
- Prometheus scrapes metrics and Grafana visualizes system health.
- Java 21
- Docker and Docker Compose
- Maven (or use the included
mvnwscripts)
docker compose up -dcd <service-name>
./mvnw spring-boot:run- API Gateway:
http://localhost:<gateway-port> - Keycloak:
http://localhost:<keycloak-port> - Grafana:
http://localhost:<grafana-port> - Prometheus:
http://localhost:<prometheus-port> - Kafka UI:
http://localhost:<kafka-ui-port> - Mailpit:
http://localhost:<mailpit-port>
Typical environment configuration includes:
- Kafka bootstrap servers
- MySQL datasource credentials
- InfluxDB token, bucket, and organization
- Keycloak issuer and client configuration
- SMTP settings for Mailpit
- Prometheus scrape endpoints
- OpenAPI route metadata at the gateway
GridPulse is built to be observable from day one.
Collected through Micrometer and exported to Prometheus.
Grafana dashboards can be used to inspect:
- Request latency
- Error rates
- Consumer lag
- Circuit-breaker state
- Service throughput
- Usage ingestion trends
Structured logs make tracing event flow and debugging service interactions easier.
- Public traffic is routed through the API Gateway
- JWT validation is enforced at the gateway layer
- Keycloak is used for local authentication and authorization
- Internal services can remain isolated from direct public access
- Event-driven microservices architecture
- Time-series optimized measurement storage
- Relational persistence for durable domain data
- Gateway-based security and routing
- Resilience patterns for downstream failures
- Operational visibility through metrics and dashboards
- Spring AI extension point for smart recommendations
gridpulse/
βββ alert-service/
βββ api-gateway/
βββ device-service/
βββ infra/
βββ insight-service/
βββ notification-service/
βββ usage-service/
βββ user-service/
βββ docker-compose.yml
βββ README.mdπ§βπ» Author
Ayush Gupta πΌ GitHub: https://github.com/Brew-and-Bugs-with-Ayush
π LinkedIn: https://www.linkedin.com/in/ayush-gupta004
π§ Email: [email protected]
π License
This project is licensed under the MIT License β feel free to use, learn, and build upon it.
π Support
If you find this project helpful, please β star the repository β it helps others discover it and motivates continued development!
βCode. Build. Flow. β Thatβs GridPulse.β π