This project is a backend service that ingests machine events in batches, validates and deduplicates them, stores them safely, and provides analytical statistics through REST APIs.
The system is designed to be thread-safe, scalable, and easy to extend.
- Java 21
- Spring Boot
- Spring Data JPA
- H2 In-memory Database
- visual studio(vs code)
- Maven
- JUnit 5
Controller → Service → Repository → Database
- Controller: Handles REST APIs.
- Service: Business logic, validation, deduplication, concurrency handling.
- Repository: Database access using JPA.
- Database: H2 in-memory database.
- Same eventId + identical payload → ignored (deduplicated).
- Same eventId + different payload + newer receivedTime → updated.
- Same eventId + different payload + older receivedTime → ignored.
- Database unique constraint on eventId.
- Transactional service layer.
- Concurrent inserts handled safely.
EventEntity:
- eventId
- eventTime
- receivedTime
- machineId
- durationMs
- defectCount
- factoryId
- lineId
- Batch processing
- Indexed columns
- In-memory DB for fast operations
- Future events rejected
- Invalid duration rejected
- defectCount = -1 ignored in calculations
- durationMs must be greater than 0.
- eventTime cannot be in the future.
- defectCount = -1 is ignored in statistics.
- for testing the test cases that are provided in EventServiceTest.java
- bash:mvn test
- bash :mvn spring-boot:run
- To view the database entity we can use from the local spring-boot run
- "https://localhost:8080/h2-console"
-
Persistent Database (Very Important) 🔹 Current *Using H2 in-memory database *Data is lost when application restarts 🔹 Improvement *Use PostgreSQL / MySQL *Enable migrations using Flyway or Liquibase
-
Observability (Logs, Metrics) 🔹 Current *Basic logs only 🔹 Improvement *Add structured logging *Metrics using Prometheus + Grafana *Health checks