A production-ready, scalable microservices architecture for an e-commerce platform built with Go, gRPC, PostgreSQL, Redis, and Docker.
This project is successfully deployed on AWS Free Tier with complete microservices architecture.
# API Gateway
089615628539.dkr.ecr.us-east-1.amazonaws.com/api-gateway
# User Service
089615628539.dkr.ecr.us-east-1.amazonaws.com/user-service
# Product Service (with Redis caching)
089615628539.dkr.ecr.us-east-1.amazonaws.com/product-service
# Order Service
089615628539.dkr.ecr.us-east-1.amazonaws.com/order-service
# Notification Service
089615628539.dkr.ecr.us-east-1.amazonaws.com/notification-service- β ECR (Elastic Container Registry) - 5 repositories created
- π RDS (PostgreSQL) - 3 databases (Phase 2)
- π ElastiCache (Redis) - Cache layer (Phase 3)
- β³ ECS Fargate - Service orchestration (Phase 4-5)
- β³ ALB - Load balancing (Phase 7)
- β³ CloudWatch - Monitoring & logs (Phase 6)
This project implements a comprehensive microservices architecture with the following components:
-
API Gateway (Port 8080)
- Entry point for all HTTP requests
- Routes requests to appropriate microservices
- Handles REST to gRPC translation
- Manages cross-service communication
-
User Service (Port 50051)
- User authentication and authorization
- User registration and login
- JWT token generation and validation
- User profile management
- Database: PostgreSQL (user_db)
-
Product Service (Port 50052)
- Product catalog management
- Inventory tracking
- Product listing and search
- Redis caching for frequently accessed products
- Database: PostgreSQL (product_db)
- Cache: Redis
-
Order Service (Port 50053)
- Order creation and management
- Order status tracking
- Payment status management
- Integration with User and Product services
- Database: PostgreSQL (order_db)
-
Notification Service (Port 50054)
- Event-driven notifications
- Email sending capabilities
- Order event handling
- Notification history tracking
-
PostgreSQL: Three separate databases (one per service)
- user_db: User authentication and profile data
- product_db: Product and inventory data
- order_db: Order and payment data
-
Redis: Distributed caching
- Product caching
- Session caching
- Rate limiting support
-
Docker & Docker Compose: Containerization and orchestration
- Multi-stage builds for optimal image sizes
- Service dependency management
- Network isolation
- Docker and Docker Compose
- Go 1.21+ (for local development)
- Protocol Buffers compiler (
protoc) - Make
- Clone the repository
git clone https://github.com/DevPatel-11/microservices-ecommerce.git
cd microservices-ecommerce- Start all services
docker-compose up -d- Verify services are running
curl http://localhost:8080/healthPOST /api/users/register- Register new userPOST /api/users/login- User login
GET /api/products- List all productsGET /api/products/{id}- Get product details
POST /api/orders- Create new orderGET /api/orders- List user orders
- Language: Go 1.21
- RPC Framework: gRPC
- Serialization: Protocol Buffers (protobuf)
- Databases: PostgreSQL 16
- Caching: Redis 7
- Containerization: Docker & Docker Compose
- API Gateway Pattern: REST to gRPC Translation
microservices-ecommerce/
βββ proto/
β βββ user/
β β βββ user.proto
β βββ product/
β β βββ product.proto
β βββ order/
β β βββ order.proto
β βββ notification/
β βββ notification.proto
β
βββ services/
β βββ user-service/
β β βββ main.go
β β βββ go.mod
β β βββ Dockerfile
β βββ product-service/
β β βββ main.go
β β βββ go.mod
β β βββ Dockerfile
β βββ order-service/
β β βββ main.go
β β βββ go.mod
β β βββ Dockerfile
β βββ notification-service/
β β βββ main.go
β β βββ go.mod
β β βββ Dockerfile
β βββ api-gateway/
β βββ main.go
β βββ go.mod
β βββ Dockerfile
β
βββ docker-compose.yml
βββ Makefile
βββ .env.example
βββ README.md
-
gRPC: Used for synchronous service-to-service communication
- User Service β Order Service
- Product Service β Order Service
- Order Service β Notification Service
-
Database per Service Pattern: Each service has its own database
- Ensures loose coupling
- Enables independent scaling
- Supports different data models
- users table: id, email, username, password_hash, first_name, last_name, created_at, updated_at
- products table: id, name, description, price, category, created_at, updated_at
- inventory table: id, product_id, quantity, updated_at
- orders table: id, user_id, total_amount, status, payment_status, created_at, updated_at
- order_items table: id, order_id, product_id, quantity, price
- payments table: id, order_id, amount, status, gateway, created_at
- postgres_user: PostgreSQL instance for user service (port 5432)
- postgres_product: PostgreSQL instance for product service (port 5433)
- postgres_order: PostgreSQL instance for order service (port 5434)
- redis: Redis instance for caching (port 6379)
- user-service: User microservice (gRPC port 50051)
- product-service: Product microservice (gRPC port 50052)
- order-service: Order microservice (gRPC port 50053)
- notification-service: Notification microservice (gRPC port 50054)
- api-gateway: API Gateway (HTTP port 8080)
Clients
|
v
API Gateway (8080)
|
+---> User Service (50051) --> PostgreSQL
|
+---> Product Service (50052) --> PostgreSQL + Redis
|
+---> Order Service (50053) --> PostgreSQL
|
+---> User Service
|
+---> Product Service
|
v
Notification Service (50054)
make protomake buildmake runmake stopmake logs
make logs-user
make logs-product
make logs-order
make logs-gateway- Horizontal Scaling: Each service can be scaled independently
- Load Balancing: Ready for Kubernetes deployment
- Database Sharding: Support for data partitioning
- Caching Strategy: Redis caching reduces database load
- Circuit Breaker Pattern: Prevents cascading failures
- Service Discovery: Container networking enables automatic discovery
- JWT Authentication: Token-based user authentication
- Service-to-Service Auth: gRPC interceptors for service validation
- Database Credentials: Environment variable based configuration
- TLS Support: Ready for encrypted inter-service communication
curl -X POST http://localhost:8080/api/users/register \
-H "Content-Type: application/json" \
-d '{
"email": "user@example.com",
"username": "john_doe",
"password": "secure_password",
"first_name": "John",
"last_name": "Doe"
}'curl http://localhost:8080/api/productscurl -X POST http://localhost:8080/api/orders \
-H "Content-Type: application/json" \
-d '{
"user_id": "user-123",
"items": [
{"product_id": "p1", "quantity": 2, "price": 99.99}
]
}'go test ./...ab -n 1000 -c 100 http://localhost:8080/api/products- Event-Driven Architecture: Implement message queues (RabbitMQ/Kafka)
- Distributed Tracing: Add OpenTelemetry integration
- Metrics Collection: Prometheus and Grafana monitoring
- GraphQL Gateway: Alternative API layer
- Search Service: Elasticsearch integration
- Analytics Service: Event logging and analytics
- Payment Gateway Integration: Real payment processing
- Machine Learning: Recommendation engine