Files
pos-system/docs/en/architecture/service-communication.md
Ho Ngoc Hai 4da46b5b8e Sure! Pl
2025-12-27 01:31:10 +07:00

1.3 KiB

Service Communication

Communication Patterns

Synchronous Communication (HTTP/REST)

Services communicate synchronously via HTTP REST APIs through Traefik API Gateway.

Example:

// Web App -> Auth Service
const response = await fetch('http://api.goodgo.vn/api/v1/auth/login', {
  method: 'POST',
  body: JSON.stringify({ email, password }),
});

Service-to-Service Communication

Services can communicate directly via internal network:

// Auth Service -> Notification Service (future)
const response = await fetch('http://notification-service:5003/api/v1/notifications', {
  method: 'POST',
  headers: { 'X-Service-Auth': process.env.INTERNAL_API_KEY },
  body: JSON.stringify({ userId, message }),
});

API Gateway Routing

Traefik routes requests based on:

  • Host header (api.goodgo.vn)
  • Path prefix (/api/v1/auth)

Error Handling

All services follow consistent error response format:

{
  "success": false,
  "error": {
    "code": "AUTH_001",
    "message": "Invalid credentials",
    "details": {}
  },
  "timestamp": "2024-01-01T00:00:00.000Z"
}

Retry and Circuit Breaker

Future implementation:

  • Exponential backoff for retries
  • Circuit breaker pattern for fault tolerance
  • Fallback mechanisms