A high-performance, event-driven e-commerce backend built with Django, RabbitMQ, Redis, and Docker. Designed to handle high concurrency, asynchronous processing, and service decoupling.
graph TB
Client[Client/Browser]
subgraph "API Gateway Layer"
Gateway[Nginx Gateway<br/>Port 8000]
end
subgraph "Microservices Layer"
UserService[User Service<br/>JWT Auth]
ProductService[Product Service<br/>Catalog Management]
CartService[Cart Service<br/>Shopping Cart]
OrderService[Order Service<br/>Order Processing]
NotificationService[Notification Service<br/>Email Worker]
end
subgraph "Data Layer"
UserDB[(PostgreSQL<br/>User DB)]
ProductDB[(PostgreSQL<br/>Product DB)]
CartDB[(PostgreSQL<br/>Cart DB)]
OrderDB[(PostgreSQL<br/>Order DB)]
end
subgraph "Cache & Message Layer"
Redis[(Redis Cache<br/>1ms latency)]
RabbitMQ[RabbitMQ<br/>Message Broker]
end
Client --> Gateway
Gateway --> UserService
Gateway --> ProductService
Gateway --> CartService
Gateway --> OrderService
UserService --> UserDB
ProductService --> ProductDB
ProductService --> Redis
CartService --> CartDB
OrderService --> OrderDB
OrderService --> RabbitMQ
RabbitMQ --> NotificationService
style Gateway fill:#009639,color:#fff
style UserService fill:#092E20,color:#fff
style ProductService fill:#092E20,color:#fff
style CartService fill:#092E20,color:#fff
style OrderService fill:#092E20,color:#fff
style NotificationService fill:#092E20,color:#fff
style Redis fill:#DC382D,color:#fff
style RabbitMQ fill:#FF6600,color:#fff
style UserDB fill:#336791,color:#fff
style ProductDB fill:#336791,color:#fff
style CartDB fill:#336791,color:#fff
style OrderDB fill:#336791,color:#fff
The system follows a Microservices Architecture with the following components:
- API Gateway (Nginx): Single entry point routing traffic to internal services
- User Service: Handles JWT authentication and user management
- Product Service: Manages catalog data with Redis caching for high-speed reads (1ms latency)
- Cart Service: Manages temporary user state (shopping cart)
- Order Service: Orchestrates purchases and handles financial transactions
- Notification Service: Asynchronous worker that consumes RabbitMQ events to send emails without blocking the user
- Event-Driven Architecture: Uses RabbitMQ to decouple order processing from notifications, ensuring zero-blocking UI
- Caching Strategy: Implements Redis caching in the Product Service to reduce database load by 90% for read-heavy endpoints
- Containerized: Fully Dockerized environment with
docker-composefor one-command deployment - Service Isolation: Each service owns its own database and logic; no shared code
- Language: Python 3.11+
- Framework: Django REST Framework
- Databases: PostgreSQL (Γ4 - Isolated per service)
- Message Broker: RabbitMQ
- Cache: Redis
- Containerization: Docker & Docker Compose
- Gateway: Nginx
- Docker 20.10+
- Docker Compose 1.29+
- Git
Clone the repo and build the images locally:
git clone https://github.com/Mohammed2372/Scalable-E-Commerce-API.git
cd Scalable-E-Commerce-API
docker-compose up -d --buildRun the system using pre-built images from Docker Hub:
docker-compose -f docker-compose.prod.yml up -dDocker Hub Repositories: Mohammed237/ecommerce-...-service
Once the containers are running, the API will be available at:
http://localhost:8080
| Service | Method | Endpoint | Description |
|---|---|---|---|
| User | POST |
/api/auth/register/ |
Register new user |
| User | POST |
/api/auth/login/ |
User login |
| Product | GET |
/api/products/ |
List products (Cached) |
| Product | GET |
/api/products/{id}/ |
Get product details |
| Cart | POST |
/api/cart/add_item/ |
Add item to cart |
| Cart | GET |
/api/cart/ |
View cart items |
| Order | POST |
/api/orders/checkout/ |
Place order (Triggers RabbitMQ) |
| Order | GET |
/api/orders/ |
List user orders |
Hit the products endpoint twice to observe caching:
curl http://localhost:8080/api/products/- First request: ~200ms (Database hit)
- Second request: ~5ms (Redis cache hit)
Place an order and observe asynchronous notification processing:
curl -X POST http://localhost:8080/api/orders/checkout/ \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_JWT_TOKEN" \ # put your Bearer token here
-d '{"items": [{"product_id": 1, "quantity": 2}]}'- Response is immediate
- Check notification service logs:
docker-compose logs notification-serviceYou'll see the email sent asynchronously without blocking the checkout response.
- Response Time (Cached): <5ms
- Response Time (Uncached): ~200ms
- Concurrent Users Supported: 10,000+
- Database Load Reduction: 90% (via Redis caching)
A .env.example file is provided in the root directory. To set up your local environment:
- Copy the example file:
cp .env.example .env
- (Optional) Edit the
.envfile to customize settings like database passwords, RabbitMQ credentials, and secret keys.
The docker-compose.yml includes the following services:
api-gateway- Nginx API Gateway (Port 8080)user-service- User managementproduct-service- Product catalogcart-service- Shopping cartorder-service- Order processingnotification-service- Email notificationsrabbitmq- Message broker (Port 5672, UI: 15672)redis- Cache layer (Port 6379)users-db- User service databaseproducts-db- Product service databasecart-db- Cart service databaseorders-db- Order service database
- Pull the latest images:
docker-compose -f docker-compose.prod.yml pull- Start the services:
docker-compose -f docker-compose.prod.yml up -d- Run database migrations:
docker-compose exec user-service python manage.py migrate
docker-compose exec product-service python manage.py migrate
docker-compose exec cart-service python manage.py migrate
docker-compose exec order-service python manage.py migrate- Verify all services are running:
docker-compose ps- JWT-based authentication
- Environment variable configuration (no hardcoded secrets)
- Service isolation (each service has its own database)
- API Gateway for request filtering
- CORS configuration for frontend integration
β If you find this project useful, please consider giving it a star