sgivu-purchase-sale) orchestrates vehicle purchase and sale transactions by coordinating data from User, Client, and Vehicle services.
Service Overview
Port
8084
Database
PostgreSQL
Type
Orchestration
Role
Transaction Management
Key Features
- Transaction orchestration across multiple services
- Purchase and sale record management
- Integration with User, Client, and Vehicle services
- Database migration with Flyway
- RESTful API with OpenAPI documentation
- Internal service authentication
Base Configuration
Server Settings
JPA Configuration
Disabling open-in-view enforces proper transaction boundaries in this orchestration service.
Flyway Migration
Database Configuration
- Development
- Production
This service maintains its own database for transaction records while querying other services for related data.
Service Integration
Eureka Registration
Service Discovery Map
This service integrates with all business services:Service Dependencies
Service Dependencies
- sgivu-auth: Token validation and authorization
- sgivu-client: Client (customer) information for transactions
- sgivu-user: User information for transaction recording
- sgivu-vehicle: Vehicle details for purchase/sale records
This is the only service that communicates with all other business services, making it a true orchestration layer.
Internal Service Authentication
Transaction Orchestration
The Purchase-Sale Service coordinates complex transactions:Purchase Flow Example
- Receive purchase request via API
- Validate user (call User Service)
- Validate client (call Client Service)
- Validate vehicle availability (call Vehicle Service)
- Create transaction record in local database
- Update vehicle status (call Vehicle Service)
- Return transaction confirmation
Sale Flow Example
- Receive sale request via API
- Validate seller (call User Service)
- Validate buyer client (call Client Service)
- Validate vehicle ownership (call Vehicle Service)
- Create sale record in local database
- Transfer vehicle ownership (call Vehicle Service)
- Generate sale documentation
Consider implementing the Saga pattern for distributed transaction management with compensating actions.
Observability
Actuator Endpoints
- Development
- Production
Distributed Tracing
Distributed tracing is especially valuable here to trace requests across User, Client, and Vehicle services.
Logging
API Documentation
- Production
Required Environment Variables
All Environments
| Variable | Description | Example |
|---|---|---|
SERVICE_INTERNAL_SECRET_KEY | Shared secret for internal APIs | your-secret-key |
Development
| Variable | Description | Default |
|---|---|---|
DEV_PURCHASE_SALE_DB_HOST | Database host | host.docker.internal |
DEV_PURCHASE_SALE_DB_PORT | Database port | 5432 |
DEV_PURCHASE_SALE_DB_NAME | Database name | Required |
DEV_PURCHASE_SALE_DB_USERNAME | Database username | Required |
DEV_PURCHASE_SALE_DB_PASSWORD | Database password | Required |
Production
| Variable | Description |
|---|---|
PROD_PURCHASE_SALE_DB_HOST | Database host |
PROD_PURCHASE_SALE_DB_PORT | Database port |
PROD_PURCHASE_SALE_DB_NAME | Database name |
PROD_PURCHASE_SALE_DB_USERNAME | Database username |
PROD_PURCHASE_SALE_DB_PASSWORD | Database password |
OPENAPI_SERVER_URL | Public API docs URL |
Optional
| Variable | Description | Default |
|---|---|---|
PORT | Service port | 8084 |
EUREKA_URL | Eureka server URL | http://sgivu-discovery:8761/eureka |
SGIVU_AUTH_URL | Auth service URL | http://sgivu-auth:9000 |
SGIVU_CLIENT_URL | Client service URL | http://sgivu-client:8082 |
SGIVU_USER_URL | User service URL | http://sgivu-user:8081 |
SGIVU_VEHICLE_URL | Vehicle service URL | http://sgivu-vehicle:8083 |
API Endpoints
Typical Purchase-Sale Service endpoints:All endpoints require authentication through the gateway.
Transaction Data Model
Typical transaction entity includes:- Transaction ID and type (purchase/sale)
- User ID (who processed the transaction)
- Client ID (customer)
- Vehicle ID
- Transaction amount and currency
- Transaction date and status
- Payment details
- Notes and metadata
Error Handling
The orchestration service must handle failures gracefully:Circuit Breaker Pattern
Consider implementing circuit breakers for service calls:Retry Strategy
Service Communication
RestTemplate / WebClient
The service uses Spring’s HTTP clients to call other services:Authentication Headers
Include the internal secret in requests:Performance Considerations
Caching
Cache frequently accessed data from other services:Parallel Service Calls
When data from multiple services is needed, call them in parallel:Security
Service-to-Service Authentication
All internal API calls must include the shared secret.Transaction Authorization
Verify user permissions before allowing transaction creation:- Check user role (admin, sales, etc.)
- Validate transaction limits
- Audit all operations
Monitoring
Key Metrics
Monitor these metrics for the orchestration service:- Transaction success/failure rates
- Service call latencies (User, Client, Vehicle)
- Database query performance
- Error rates by service
- Circuit breaker states
Alerts
Set up alerts for:- High failure rates
- Service unavailability
- Slow transaction processing
- Circuit breaker opens
Configuration Files
sgivu-purchase-sale.yml- Base configurationsgivu-purchase-sale-dev.yml- Development overridessgivu-purchase-sale-prod.yml- Production overrides
Related Services
User Service
User data provider
Client Service
Client data provider
Vehicle Service
Vehicle data provider
Auth Service
Token validation