Skip to content

Instantly share code, notes, and snippets.

@abhi-io
Last active November 13, 2024 22:54
Show Gist options
  • Save abhi-io/7d6688dd14962e388014a3645eeeac3a to your computer and use it in GitHub Desktop.
Save abhi-io/7d6688dd14962e388014a3645eeeac3a to your computer and use it in GitHub Desktop.
del_test1
DevOps Exercise: Multi-Service Deployment with Docker Compose
Objective
Deploy a scalable, multi-service e-commerce setup using Docker Compose that includes a reverse proxy, product management service, caching, and a database. Your setup should be secure, resilient, and able to handle simulated load. This exercise tests container orchestration, secure configuration management, and performance monitoring.
Scenario
You're setting up the backend infrastructure for a product catalog in an e-commerce platform. The platform includes:
1.API Gateway (Nginx): A reverse proxy that routes requests to the Product Service and caches frequently accessed data.
2.Product Service (Python/Flask): Manages product listings, filters, and sorting.
3.Caching (Redis): A cache layer to store popular product data and improve response times.
4.Database (PostgreSQL): Stores product data persistently with regular automated backups.
Each service should run in a dedicated container, communicate securely with others, and allow independent scaling to handle heavy traffic.
Requirements
1. API Gateway
Set up Nginx as a reverse proxy to route requests to the Product Service.
Configure caching for frequently accessed endpoints to improve response times.
Secure Nginx with HTTPS (self-signed certificate is acceptable for the exercise).
2. Product Service
Use Python and Flask for a microservice that provides product listings with filtering options.
Query parameters should support filtering by category, price range, and availability.
Integrate Redis as a caching layer to reduce database load for frequently accessed products.
Configure the Product Service to fetch data from Redis first, and only hit the database if the data isn’t in the cache.
3. Database
Use PostgreSQL to store product information, persistently backing up to a Docker volume.
Implement secure connection settings, including SSL.
Use Docker secrets for securely managing database credentials.
4. Caching Layer (Redis)
Set up Redis as a caching service for the Product Service.
Configure a persistent volume to retain Redis configuration files.
5. Logging and Monitoring
Use Docker Compose to set up logging for each service, ensuring logs are accessible on the host and organized by service.
Configure a containerized monitoring solution (such as Prometheus and Grafana) to track CPU, memory usage, and cache hit rates.
6. Scaling
Configure Docker Compose to allow horizontal scaling of the API Gateway and Product Service independently.
Include a load testing script to simulate heavy traffic and verify that the system scales appropriately.
Challenge
1. Security
Securely store sensitive information, such as PostgreSQL passwords and Nginx SSL keys, using Docker secrets.
Ensure that each service only has access to the resources and secrets it requires.
2. Backup and Recovery
Write a script that backs up PostgreSQL data daily, saves it to a persistent volume, and simulates secure off-site storage.
Ensure the Redis cache can recover gracefully with minimal downtime.
3. Testing and Load Simulation
Create a docker-compose.test.yml file to simulate high-traffic load and test cache performance.
Test for failover recovery in case Redis or PostgreSQL goes down; the Product Service should be able to reconnect when these services come back online.
4. Documentation
Provide a README.md detailing the setup process, scaling instructions, and a troubleshooting guide.
Include instructions for setting up HTTPS, managing Docker secrets, and configuring the monitoring solution.
Submission Requirements
1.A working docker-compose.yml file, plus any supporting files (Dockerfiles, Nginx configuration, scripts) should be pushed to GITHUB.
2.A load testing script that simulates traffic and records response times.
3.Clear documentation (README.md) explaining the setup, backup, and monitoring procedures, with details on Docker secrets management.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment