Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
**/mvnw text eol=lf
*.cmd text eol=lf
*.sh text eol=lf
*.java text eol=lf
*.xml text eol=lf
*.properties text eol=lf
*.yml text eol=lf
*.gitattributes text eol=lf
*.gitignore text eol=lf
*.md text eol=lf
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
products/HELP.md
**/target/
../.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
15 changes: 15 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,18 @@ services:
- K6_OUT=influxdb=http://influxdb:8086/k6
extra_hosts:
- "host.docker.internal:host-gateway"
products-redis:
image: 'redis:latest'
ports:
- "6379:6379"
products:
environment:
- SPRING_DATA_REDIS_HOST=products-redis
- SPRING_DATA_REDIS_PORT=6379
- SERVER_PORT=5000
- EXTERNAL_API_HOST=simulado
build: ./products
ports:
- "5000:5000"
depends_on:
- products-redis
3 changes: 3 additions & 0 deletions products/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wrapperVersion=3.3.4
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.14/apache-maven-3.9.14-bin.zip
14 changes: 14 additions & 0 deletions products/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM maven:3.9-eclipse-temurin-21 AS build
WORKDIR /app
COPY pom.xml .
COPY mvnw .
COPY .mvn .mvn
RUN chmod +x mvnw
COPY src ./src
RUN mvn clean package -DskipTests

FROM eclipse-temurin:21-jre
WORKDIR /app
COPY --from=build /app/target/*.jar app.jar
EXPOSE 5000
ENTRYPOINT ["java", "-jar", "app.jar"]
48 changes: 48 additions & 0 deletions products/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Products Service

A high-performance microservice built to manage and serve product information efficiently, utilizing caching strategies and resilient communication patterns with external dependencies.

## 🛠 Tech Stack

* **Runtime:** Java 21
* **Framework:** Spring Boot 3
* **Caching:** Redis
* **Resilience:** Resilience4j (Circuit Breaker, Retry patterns)
* **Observability:** Spring Boot Actuator
* **Testing:**
* JUnit 5
* Mockito
* Spring Boot Starter Test
* WireMock (for mocking external HTTP dependencies)
* Embedded Redis (for integration testing)

## 🚀 Getting Started

To launch the complete infrastructure, including the application, database, and monitoring tools, use the following command:

```bash
docker compose up -d simulado grafana influxdb products products-redis
```

### Performance Testing
The k6 performance tests should be executed following the same procedure described in the original project documentation. Ensure the environment is fully up before initiating load tests.

---

### 🔍 Validation & Monitoring

Once the containers are running, you can verify the application's health and the status of the integrated resilience patterns through the following Actuator endpoints:

* **System Health & Infrastructure:** [http://localhost:5000/actuator/health](http://localhost:5000/actuator/health)
Displays the overall status of the application, including the connection status to the Redis cache and the health of the configured Circuit Breakers.
* **Circuit Breaker Status:** [http://localhost:5000/actuator/circuitbreakers](http://localhost:5000/actuator/circuitbreakers)
Shows the current state (`CLOSED`, `OPEN`, `HALF_OPEN`) of the `productClient` circuit breaker, along with real-time metrics (failure rate, buffered calls, etc.).
* **Circuit Breaker Events:** [http://localhost:5000/actuator/circuitbreakerevents](http://localhost:5000/actuator/circuitbreakerevents)
Provides a chronological log of the latest events, useful for seeing exactly when the circuit opens due to timeouts or 5xx errors from the external mocks.

---

### 📝 Architectural Decisions

#### Error Handling & API Contract
A specific design choice was made regarding error propagation: **the application does not return 5xx status codes on its endpoints.** This decision is rooted in the established contract between the backend and the frontend. By intercepting internal or downstream failures and mapping them to specific client-side expectations, we ensure the frontend can handle state transitions gracefully without encountering unhandled server-side exceptions. This maintains a robust and predictable user experience even when external dependencies are unavailable.
Loading