Spring Boot Microservices Standards
Priority: P0
Implementation Guidelines
Sync Communication (REST & API Interface)
- Clients: Use
Spring Cloud OpenFeignorHTTP Interfaces(Spring 6/Java 21). - Resilience: Implement
Resilience4jwithCircuit Breaker,Retry (Exponential Backoff), andRateLimiter. Use fallback methods to return cached or default data on failure. Configure timeout values on all Feign clients. - Contracts: Share
DTO Recordsvia aMaven BOMorAPI Contractmodule. - Tracing: Ensure
Micrometerspropagation for Distributed Tracing.
Async Communication (Spring Cloud Stream)
- Architecture: Use
Message-Drivenpatterns withSpring Cloud Stream. - Functions: Define message handlers as
java.util.function.Function,Consumer, orSupplier. - Serialization: Use
JSONorAvrofor events. - Reliability: Implement
Dead Letter Queues(DLQ) andIdempotentconsumers.
Data & Isolation
- DB per Service: NEVER share databases between microservices.
- Shared Libs: Minimize shared logic to shared DTOs/Clients only.
- Discovery: Use
Spring Cloud Gatewayfor routing and auth.
Anti-Patterns
- No Shared DB: Services must communicate via APIs or Events only.
- No Shared Entities: Share DTOs via Maven BOM, never JPA entities.
- No Sync Call Chains: Use async messaging to prevent distributed monolith.
References
- Implementation Examples