The enhanced gateway now monitors and ensures all microservices are synchronized with the shared knowledge version.
Key Benefits:
- Automatic Sync Detection: Monitors shared knowledge versions across all services
- Health Integration: Combines service health with sync status
- Proactive Alerts: Identifies out-of-sync services before they cause issues
- Zero Downtime: Ensures compatibility during service updates
Intelligent request coordination across multiple services for complex operations.
Features:
- Dashboard Orchestration: Combines user data from multiple services
- Caching Layer: Reduces redundant service calls
- Graceful Degradation: Works even when some services are unavailable
- Request Tracing: Full visibility into cross-service requests
Automatic fault tolerance to prevent cascade failures.
Protection:
- Failure Detection: Monitors service failure rates
- Automatic Recovery: Tests service health periodically
- Fast Failure: Fails fast when services are down
- Statistics: Detailed metrics on service reliability
# Required
JWT_SECRET=your-super-secret-jwt-key-32-chars-minimum
# Service URLs
AUTH_SERVICE_URL=https://your-auth-service.herokuapp.com
COMMENT_SERVICE_URL=https://your-comment-service.herokuapp.com
INDUSTRY_SERVICE_URL=https://your-industry-service.herokuapp.com
NPS_SERVICE_URL=https://your-nps-service.herokuapp.com
# Sync Configuration (Optional)
SHARED_KNOWLEDGE_VERSION=1.0.0
SYNC_CHECK_INTERVAL=300000
SYNC_WARNING_THRESHOLD=1800000
SYNC_CRITICAL_THRESHOLD=3600000
# Features (Optional - all enabled by default)
FEATURE_SYNC_MONITORING=true
FEATURE_ORCHESTRATION=true
ORCHESTRATION_CACHE_ENABLED=true
CIRCUIT_BREAKER_ENABLED=true
# Install dependencies
npm install
# Start with enhanced features
npm run dev:enhanced
# Check sync status
npm run sync:check
# View sync status via API
npm run sync:status
# Check overall sync status
GET /health/sync
# Detailed sync information
GET /api/gateway/sync/status
# Force sync check (admin only)
POST /api/gateway/sync/force
# User dashboard (orchestrated)
GET /api/orchestration/user/:userId/dashboard
# Gateway service stats
GET /api/gateway/stats
# Basic health (unchanged)
GET /health
# Enhanced health with sync status
GET /health/services
# Service management
GET /api/gateway/services
# Check all services
node scripts/check-sync.js
# Gateway only
node scripts/check-sync.js --gateway-only
# Individual services only
node scripts/check-sync.js --services-only
# JSON output
node scripts/check-sync.js --json
# Development - detailed logs
LOG_LEVEL=debug
# Production - essential logs only
LOG_LEVEL=info
# Enable colored output
ENABLE_COLORS=true
Client Request β Gateway β Enhanced Health Check
β
Circuit Breaker Check
β
Sync Status Validation
β
Service Orchestration (if needed)
β
Proxy to Service
β
Response + Sync Info Collection
Gateway Timer β Check All Services β Collect Versions
β
Compare with Expected Version
β
Update Service Status
β
Log Warnings/Alerts if Out of Sync
CLOSED β Requests pass through normally
β (failures exceed threshold)
OPEN β Requests fail fast
β (timeout expires)
HALF_OPEN β Test single request
β (success) β (failure)
CLOSED OPEN
// Recommended production settings
{
sync: {
checkInterval: 300000, // 5 minutes
warningThreshold: 1800000, // 30 minutes
criticalThreshold: 3600000, // 1 hour
autoUpdate: false // Manual updates only
},
orchestration: {
timeout: 10000, // 10 seconds
cacheExpiry: 300000, // 5 minutes
retryAttempts: 3
},
circuitBreaker: {
failureThreshold: 5, // 5 failures
resetTimeout: 60000 // 1 minute
}
}
// Recommended development settings
{
sync: {
checkInterval: 60000, // 1 minute
warningThreshold: 300000, // 5 minutes
criticalThreshold: 600000, // 10 minutes
autoUpdate: true // Auto-update in dev
},
orchestration: {
timeout: 5000, // 5 seconds
cacheExpiry: 60000, // 1 minute
retryAttempts: 2
}
}
Services showing as out-of-sync:
# Check specific service
curl http://your-service.com/api/shared-knowledge/status
# Force sync check
curl -X POST http://localhost:3000/api/gateway/sync/force \
-H "Authorization: Bearer YOUR_ADMIN_TOKEN"
Circuit breaker stuck open:
# Check circuit breaker status
curl http://localhost:3000/api/gateway/stats
# Reset circuit breaker (admin)
curl -X POST http://localhost:3000/api/gateway/circuit-breaker/reset \
-H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
-d '{"service": "service-name"}'
High response times:
# Check orchestration cache stats
curl http://localhost:3000/api/gateway/stats | jq '.orchestration'
# Clear cache if needed
curl -X DELETE http://localhost:3000/api/gateway/cache \
-H "Authorization: Bearer YOUR_ADMIN_TOKEN"
# Enable verbose logging
LOG_LEVEL=debug FEATURE_REQUEST_TRACING=true npm run dev
# Monitor sync in real-time
watch -n 30 'npm run sync:check --services-only'
- User Data: 10 minutes TTL
- Dashboard: 2 minutes TTL
- Industries: 15 minutes TTL
- Recent Jobs: 2 minutes TTL
- Parallel Service Calls: Multiple services called simultaneously
- Circuit Breaker: Fast failure for unhealthy services
- Request Pooling: Reuse connections where possible
- Gzip Compression: Automatic response compression
- Automatic Cache Cleanup: Expired entries removed every minute
- Token Cache: JWT tokens cached for 5 minutes
- Circuit Breaker Reset: Failure counts decay over time
- JWT Token Caching: Reduce auth service load
- Role-Based Access: Granular permission control
- Request Tracing: Full audit trail
- Rate Limiting: Per-user and per-endpoint limits
- Request Signing: Gateway signs all outbound requests
- Header Forwarding: Secure context propagation
- API Key Validation: Service authentication
- CORS Configuration: Precise origin control
-
Update Environment Variables:
# Add sync configuration SHARED_KNOWLEDGE_VERSION=1.0.0 SYNC_CHECK_INTERVAL=300000
-
Update Service Dependencies:
npm install # Will install enhanced dependencies
-
Test Enhanced Features:
npm run sync:check npm run dev:enhanced
-
Deploy with Zero Downtime:
# Services can be updated one at a time # Gateway handles mixed versions gracefully
For full sync monitoring, services should implement:
# Health endpoint with version info
GET /health
Response: { "status": "healthy", "sharedKnowledgeVersion": "1.0.0" }
# Optional: Dedicated sync endpoint
GET /api/shared-knowledge/status
Response: { "version": "1.0.0", "lastUpdated": "2024-01-15T10:30:00Z" }
git clone <repository>
cd gateway-service
npm install
cp .env.example .env
# Update .env with your service URLs
npm run dev:enhanced
npm test # Unit tests
npm run test:coverage # Coverage report
npm run test:integration # Integration tests
npm run validate # Lint + test
This enhanced gateway maintains the small project size while significantly improving service coordination, monitoring, and reliability. The sync monitoring ensures all services stay coordinated, while orchestration provides intelligent request handling across the microservices architecture.