A microservices-based application using Docker Compose, implementing service discovery and load balancing.
- Containerized microservices
- Service discovery
- Load balancing with Nginx
- Redis caching
- MongoDB database
- API Gateway
- Centralized logging
- Health monitoring
│
▼
[Nginx]
│
┌──────────────┴──────────────┐
▼ ▼
[API Gateway] [Web Client]
│
┌───────────┼───────────┐
▼ ▼ ▼
[Service A] [Service B] [Service C]
│ │ │
└─────┐ ┌───┴───┐ ┌────┘
▼ ▼ ▼ ▼
[Redis] [MongoDB]
- Docker
- Docker Compose
- Node.js (for local development)
- MongoDB Compass (optional)
microservices/
├── docker-compose.yml # Main compose file
├── nginx/ # Nginx configuration
│ ├── Dockerfile
│ └── nginx.conf
├── api-gateway/ # API Gateway service
│ ├── Dockerfile
│ └── src/
├── service-a/ # Microservice A
│ ├── Dockerfile
│ └── src/
├── service-b/ # Microservice B
│ ├── Dockerfile
│ └── src/
├── service-c/ # Microservice C
│ ├── Dockerfile
│ └── src/
└── config/ # Configuration files
├── redis.conf
└── mongo.conf
For detailed setup instructions, please refer to our Setup Guide.
- Clone the repository:
git clone https://github.com/nived2/microservices.git
cd microservices
- Start the services:
docker-compose up -d
- Check service status:
docker-compose ps
- Routes requests to appropriate services
- Handles authentication
- Rate limiting
- Request/Response transformation
- Core business logic
- REST API endpoints
- MongoDB interaction
- Redis caching
- Secondary business logic
- Async processing
- Event handling
- Data aggregation
- Auxiliary services
- Reporting
- Analytics
- Background jobs
upstream api {
server api-gateway:3000;
}
server {
listen 80;
location / {
proxy_pass http://api;
}
}
version: '3.8'
services:
nginx:
build: ./nginx
ports:
- "80:80"
api-gateway:
build: ./api-gateway
environment:
- NODE_ENV=production
mongodb:
image: mongo:latest
volumes:
- mongodb_data:/data/db
redis:
image: redis:alpine
volumes:
- redis_data:/data
volumes:
mongodb_data:
redis_data:
To scale services:
docker-compose up -d --scale service-a=3
- Health check endpoints
- Docker stats monitoring
- Redis monitoring
- MongoDB monitoring
- Nginx access logs
- API Gateway authentication
- Service-to-service authentication
- Network isolation
- Rate limiting
- CORS configuration
- Install dependencies:
npm install
- Run services locally:
docker-compose up -d mongodb redis
npm run dev
# Run unit tests
npm test
# Run integration tests
npm run test:integration
# Run all tests
npm run test:all
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
For issues and support:
- Create an issue on GitHub
- Contact: [email protected]
MIT License - feel free to use this project for your own portfolio