Before running the system, ensure you have the following installed:
- Docker & Docker Compose: For containerized services
- Java 17: For Spring Boot services
- Maven: For building Java services
- Node.js & npm: For React frontend
- Git: For version control
- Memory: Minimum 8GB RAM recommended
- Storage: At least 10GB free space
- Network: Internet connection for pulling Docker images
- Ports: The following ports should be available:
- 3000 (React Web App)
- 8080 (HAProxy Load Balancer)
- 8081, 8083 (Write Layer Services)
- 8082 (Public API)
- 8087 (Coupon Service)
- 5672 (RabbitMQ)
- 6379 (Redis)
- 8000 (DynamoDB Local)
- 9092 (Kafka)
- Clone the repository:
git clone <repository-url>
cd eventually-consistent-highly-scalable-system- Start all services:
docker compose up -d-
Wait for services to initialize (approximately 2-3 minutes)
-
Access the application:
- Web Application: http://localhost:3000
- API Gateway: http://localhost:8080
- Keycloak Admin: http://localhost:8080/auth/admin
The system uses Docker Compose to orchestrate multiple services:
| Service | Port | Description | Dependencies |
|---|---|---|---|
| web-app | 3000 | React frontend application | keycloak |
| haproxy | 8080 | Load balancer and API gateway | All backend services |
| write-layer | 8081 | Primary write service | rabbitmq, dynamodb, keycloak |
| write-layer-2 | 8083 | Secondary write service | rabbitmq, dynamodb, keycloak |
| public-api | 8082 | Public read API | redis, dynamodb |
| coupon-service | 8087 | Coupon management service | redis, dynamodb, keycloak |
| keycloak | 8090 | Authentication server | postgres |
| postgres | 5432 | Keycloak database | - |
| rabbitmq | 5672, 15672 | Message broker | - |
| redis | 6379 | Cache and session store | - |
| dynamodb | 8000 | NoSQL database | - |
| kafka | 9092 | Event streaming platform | zookeeper |
| zookeeper | 2181 | Kafka coordination service | - |
- Profile:
dev - Database: DynamoDB Local
- Authentication: Keycloak with default realm
- Caching: Redis (single instance)
- Message Queue: RabbitMQ (single instance)
- Profile:
prod - Database: AWS DynamoDB
- Authentication: Production Keycloak instance
- Caching: Redis Cluster
- Message Queue: RabbitMQ Cluster or AWS SQS
- Load Balancer: AWS ALB or production HAProxy
The services have dependencies and should start in the following order:
-
Infrastructure Services:
- PostgreSQL (for Keycloak)
- Redis
- DynamoDB Local
- Zookeeper
- Kafka
- RabbitMQ
-
Authentication Service:
- Keycloak
-
Backend Services:
- Write Layer Services
- Public API
- Coupon Service
-
Gateway and Frontend:
- HAProxy
- React Web App
# Environment
ENVIRONMENT=development
SPRING_PROFILES_ACTIVE=dev
# Database
DYNAMODB_ENDPOINT=http://dynamodb:8000
AWS_ACCESS_KEY_ID=dummy
AWS_SECRET_ACCESS_KEY=dummy
AWS_REGION=us-east-1
# Cache
REDIS_HOST=redis
REDIS_PORT=6379
# Message Queue
RABBITMQ_HOST=rabbitmq
RABBITMQ_PORT=5672
RABBITMQ_USERNAME=guest
RABBITMQ_PASSWORD=guest
# Authentication
KEYCLOAK_SERVER_URL=http://haproxy:8080
KEYCLOAK_REALM=event-systemEach service has its own configuration file:
- Spring Boot Services:
application.ymlorapplication.properties - React App: Environment variables and
config.json - HAProxy:
haproxy.cfg - Docker Services:
docker-compose.yml
- Admin Username: admin
- Admin Password: admin
- Realm: event-system
- Client ID: event-system-client
- Access Keycloak admin console: http://localhost:8080/auth/admin
- Login with admin/admin
- Create or import realm configuration
- Configure client settings
- Set up user roles and permissions
The system automatically creates the following tables:
- Users: User profile information
- Coupons: Coupon data and status
- Orders: Order information
- Events: Event sourcing store
Some services may require initial data setup:
# Create sample data (optional)
docker exec -it write-layer java -jar app.jar --setup-dataEach service provides health check endpoints:
| Service | Health Check URL | Expected Response |
|---|---|---|
| Write Layer | http://localhost:8081/actuator/health | {"status":"UP"} |
| Public API | http://localhost:8082/health | {"status":"healthy"} |
| Coupon Service | http://localhost:8087/actuator/health | {"status":"UP"} |
| Web App | http://localhost:3000/health | {"status":"ok"} |
#!/bin/bash
# Check all services
./scripts/health-check.sh
# Check specific service
./scripts/health-check.sh write-layerServices can be scaled by increasing replicas:
# docker-compose.yml
services:
write-layer:
# ... configuration
scale: 3 # Run 3 instancesHAProxy automatically distributes load across service instances:
# haproxy.cfg
backend write_services
balance roundrobin
server write1 write-layer-1:8081 check
server write2 write-layer-2:8081 check
server write3 write-layer-3:8081 check
Configure resource limits for containers:
services:
write-layer:
deploy:
resources:
limits:
memory: 1G
cpus: '0.5'
reservations:
memory: 512M
cpus: '0.25'For production deployments, consider:
- Kubernetes Horizontal Pod Autoscaler
- AWS ECS Service Auto Scaling
- Docker Swarm Auto Scaling
- Check port conflicts:
netstat -tulpn | grep <port> - Verify Docker daemon is running:
docker ps - Check service logs:
docker compose logs <service-name> - Ensure dependencies are healthy:
docker compose ps
- Verify Keycloak is running:
curl http://localhost:8080/auth - Check realm configuration
- Verify client credentials
- Check JWT token validation logs
- Test DynamoDB connection:
aws dynamodb list-tables --endpoint-url http://localhost:8000 - Check Redis connectivity:
redis-cli -h localhost ping - Verify network connectivity between services
- Check RabbitMQ management interface: http://localhost:15672
- Verify queue creation and message flow
- Check consumer connection status
- Monitor message processing logs
# View all service logs
docker compose logs -f
# View specific service logs
docker compose logs -f write-layer
# Search logs for errors
docker compose logs | grep ERRORServices use correlation IDs for distributed tracing:
# Find all logs for a specific request
docker compose logs | grep "correlation-id: 12345"- Response Times: API endpoint latency
- Throughput: Requests per second
- Error Rates: 4xx/5xx response codes
- Resource Usage: CPU, memory, disk I/O
- Queue Depth: Message queue backlog
- Application Metrics: Spring Boot Actuator endpoints
- System Metrics: Docker stats, system monitoring
- Custom Dashboards: Grafana dashboards (if configured)
# Create full system backup
./scripts/backup-system.sh
# Backup specific components
./scripts/backup-database.sh
./scripts/backup-configuration.sh# Restore from backup
./scripts/restore-system.sh /path/to/backup
# Restore specific service
./scripts/restore-service.sh write-layer /path/to/backup- Change default passwords
- Enable TLS/SSL certificates
- Configure firewall rules
- Set up VPN or private networks
- Enable audit logging
- Deploy across multiple availability zones
- Configure database replication
- Set up service redundancy
- Implement health checks and auto-recovery
- Configure connection pooling
- Enable caching strategies
- Optimize database queries
- Set appropriate timeout values
- Monitor and tune JVM settings