A production-grade e-commerce platform built with FastAPI microservices and Kubernetes orchestration. Features comprehensive observability, resilience patterns, and event-driven architecture.
- API Gateway - Smart routing, authentication, rate limiting, caching, circuit breaker, load balancing
- User Service - User management, authentication, JWT token generation
- Product Service - Product catalog, inventory management, gRPC API
- Order Service - Order orchestration, coordinates product and payment services
- Payment Service - Payment processing, transaction management
- Notification Service - Event-driven notifications via Kafka consumers
| Component | Technology |
|---|---|
| Backend | FastAPI, Python 3.x |
| Databases | PostgreSQL (per service) |
| Caching | Redis |
| Message Queue | Apache Kafka + Zookeeper |
| Communication | REST, gRPC |
| Monitoring | Prometheus, Grafana, ELK Stack (Elasticsearch, Logstash, Kibana, Fluent Bit) |
| Orchestration | Kubernetes, Docker Compose |
| Load Testing | Locust |
- Authentication & Authorization - JWT-based security
- Rate Limiting - Token bucket algorithm
- Response Caching - Redis-backed with intelligent cache keys
- Circuit Breaker - Prevents cascade failures
- Load Balancing - Round-robin with health checks
- Service Discovery - Dynamic service registry
- Request Metrics - Prometheus instrumentation
- Event-driven architecture with Kafka
- Inter-service communication via REST and gRPC
- Database per service pattern
- Health checks and graceful degradation
- Distributed tracing and logging
- Metrics: Prometheus scraping all services
- Visualization: Grafana dashboards
- Logging: Centralized logs with ELK stack
- Tracing: Request/response logging
ecom-app/
βββ api-gateway/ # API Gateway with advanced patterns
βββ user-service/ # User management & auth
βββ product-service/ # Product catalog + gRPC
βββ order-service/ # Order orchestration
βββ payment-service/ # Payment processing
βββ notification-service/ # Kafka-based notifications
βββ k8s/ # Kubernetes manifests
βββ monitoring/ # Prometheus, Grafana, ELK configs
βββ locust/ # Load testing scripts
βββ data/ # Persistent data volumes
βββ docker-compose.yml # Local development setup
- Docker & Docker Compose
- Python 3.9+
- Kubernetes cluster (for K8s deployment)
-
Clone the repository
git clone <repository-url> cd ecom-app
-
Start all services
docker-compose up -d
-
Verify services are running
docker-compose ps
| Service | Port | URL |
|---|---|---|
| API Gateway | 8000 | http://localhost:8000 |
| User Service | 8001 | http://localhost:8001 |
| Product Service | 8002 | http://localhost:8002 |
| Payment Service | 8003 | http://localhost:8003 |
| Order Service | 8004 | http://localhost:8004 |
| Notification Service | 8005 | http://localhost:8005 |
| Prometheus | 9090 | http://localhost:9090 |
| Grafana | 3000 | http://localhost:3000 |
| Kafka UI | 8080 | http://localhost:8080 |
| Kibana | 5601 | http://localhost:5601 |
Each service exposes interactive API docs:
- API Gateway: http://localhost:8000/docs
- User Service: http://localhost:8001/docs
- Product Service: http://localhost:8002/docs
- Payment Service: http://localhost:8003/docs
- Order Service: http://localhost:8004/docs
- Notification Service: http://localhost:8005/docs
curl -X POST "http://localhost:8000/api/users/register" \
-H "Content-Type: application/json" \
-d '{
"username": "john_doe",
"email": "john@example.com",
"password": "SecurePass123",
"full_name": "John Doe"
}'curl -X POST "http://localhost:8000/api/users/login" \
-H "Content-Type: application/json" \
-d '{
"username": "john_doe",
"password": "SecurePass123"
}'curl -X POST "http://localhost:8000/api/products/" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"name": "Laptop",
"description": "High-performance laptop",
"price": 999.99,
"stock_quantity": 50,
"sku": "LAPTOP-001"
}'curl -X POST "http://localhost:8000/api/orders/" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"items": [
{
"product_id": 1,
"quantity": 2,
"price": 999.99
}
],
"payment_method": "credit_card"
}'# Apply all manifests
kubectl apply -f k8s/
# Check deployment status
kubectl get pods
kubectl get services
kubectl get ingressConfigure your DNS or /etc/hosts to point to your cluster IP:
<cluster-ip> ecom.local
Access: http://ecom.local
- Access: http://localhost:9090
- Metrics from all services automatically scraped
- Custom business metrics (orders, payments, etc.)
- Access: http://localhost:3000
- Default credentials: admin/admin
- Pre-configured dashboards for each service
- Elasticsearch: http://localhost:9200
- Centralized logging from all services
- Search and analyze logs via Elasticsearch queries
- Access: http://localhost:8080
- Monitor Kafka topics, messages, and consumer groups
- View order and notification events in real-time
Run load tests with Locust:
cd locust
pip install -r requirements.txt
locust -f locustfile.py --host=http://localhost:8000Access Locust UI: http://localhost:8089
cd <service-name>
pip install -r requirements.txt
uvicorn main:app --reload --port <port>cd frontend
npm install
npm run devEach service can be configured via environment variables. Check config.py in each service for available options.
Key variables:
DATABASE_URL- PostgreSQL connection stringREDIS_URL- Redis connection stringKAFKA_BOOTSTRAP_SERVERS- Kafka brokersJWT_SECRET- Secret key for JWT tokens
- Circuit Breaker: Prevents cascading failures
- Rate Limiting: Protects services from overload
- Health Checks: Automatic service monitoring
- Retry Logic: Automatic retry with exponential backoff
- Database per Service: Isolated data stores
- Event Sourcing: Kafka for event streaming
- Caching: Redis for frequently accessed data
- API Gateway: Single entry point
- Service Registry: Dynamic service discovery
- gRPC: High-performance inter-service calls
- Event-Driven: Asynchronous processing via Kafka
POST /register- Register new userPOST /login- User loginGET /users/me- Get current userPUT /users/{id}- Update user
POST /products/- Create productGET /products/- List productsGET /products/{id}- Get productPUT /products/{id}- Update productDELETE /products/{id}- Delete productPOST /products/{id}/stock- Update stock
POST /orders/- Create orderGET /orders/- List ordersGET /orders/{id}- Get orderPUT /orders/{id}/cancel- Cancel order
POST /payments/- Create paymentGET /payments/{id}- Get paymentPUT /payments/{id}/status- Update payment status
- JWT-based authentication
- Password hashing with bcrypt
- CORS configuration
- Rate limiting per endpoint
- Input validation with Pydantic
- SQL injection prevention via ORM
- Redis caching reduces database load
- gRPC for fast inter-service communication
- Connection pooling for databases
- Async/await for non-blocking I/O
- Load balancing across service instances
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License.
For issues and questions:
- Create an issue in the repository
- Check existing documentation in each service
- Review API docs at
/docsendpoints
Built with β€οΈ using FastAPI, and Kubernetes