Skip to content

DevPatel-11/microservices-ecommerce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Microservices E-Commerce Platform

A production-ready, scalable microservices architecture for an e-commerce platform built with Go, gRPC, PostgreSQL, Redis, and Docker.

πŸš€ Live Deployment & Infrastructure

This project is successfully deployed on AWS Free Tier with complete microservices architecture.

πŸ“¦ Docker Image Registry (ECR)

# 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

🎯 AWS Services Deployed

  • βœ… 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)

πŸ“‹ Architecture Overview

This project implements a comprehensive microservices architecture with the following components:

Services

  1. API Gateway (Port 8080)

    • Entry point for all HTTP requests
    • Routes requests to appropriate microservices
    • Handles REST to gRPC translation
    • Manages cross-service communication
  2. User Service (Port 50051)

    • User authentication and authorization
    • User registration and login
    • JWT token generation and validation
    • User profile management
    • Database: PostgreSQL (user_db)
  3. 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
  4. Order Service (Port 50053)

    • Order creation and management
    • Order status tracking
    • Payment status management
    • Integration with User and Product services
    • Database: PostgreSQL (order_db)
  5. Notification Service (Port 50054)

    • Event-driven notifications
    • Email sending capabilities
    • Order event handling
    • Notification history tracking

Infrastructure

  • 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

πŸš€ Quick Start

Prerequisites

  • Docker and Docker Compose
  • Go 1.21+ (for local development)
  • Protocol Buffers compiler (protoc)
  • Make

Installation

  1. Clone the repository
git clone https://github.com/DevPatel-11/microservices-ecommerce.git
cd microservices-ecommerce
  1. Start all services
docker-compose up -d
  1. Verify services are running
curl http://localhost:8080/health

API Endpoints

User Service

  • POST /api/users/register - Register new user
  • POST /api/users/login - User login

Product Service

  • GET /api/products - List all products
  • GET /api/products/{id} - Get product details

Order Service

  • POST /api/orders - Create new order
  • GET /api/orders - List user orders

πŸ—οΈ Tech Stack

  • 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

πŸ“ Project Structure

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               

πŸ”„ Inter-Service Communication

  • 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

πŸ—„οΈ Database Schema

User Service (user_db)

  • users table: id, email, username, password_hash, first_name, last_name, created_at, updated_at

Product Service (product_db)

  • products table: id, name, description, price, category, created_at, updated_at
  • inventory table: id, product_id, quantity, updated_at

Order Service (order_db)

  • 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

🐳 Docker Compose Services

  • 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)

οΏ½οΏ½ Service Dependencies

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)

πŸ› οΈ Development

Generate Protocol Buffer Code

make proto

Build All Services

make build

Run Services Locally

make run

Stop Services

make stop

View Logs

make logs
make logs-user
make logs-product
make logs-order
make logs-gateway

πŸ“ˆ Scalability Features

  1. Horizontal Scaling: Each service can be scaled independently
  2. Load Balancing: Ready for Kubernetes deployment
  3. Database Sharding: Support for data partitioning
  4. Caching Strategy: Redis caching reduces database load
  5. Circuit Breaker Pattern: Prevents cascading failures
  6. Service Discovery: Container networking enables automatic discovery

πŸ” Security Considerations

  1. JWT Authentication: Token-based user authentication
  2. Service-to-Service Auth: gRPC interceptors for service validation
  3. Database Credentials: Environment variable based configuration
  4. TLS Support: Ready for encrypted inter-service communication

πŸ”— API Examples

User Registration

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"
  }'

List Products

curl http://localhost:8080/api/products

Create Order

curl -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}
    ]
  }'

πŸ§ͺ Testing

Run Tests

go test ./...

Load Testing

ab -n 1000 -c 100 http://localhost:8080/api/products

🚧 Future Enhancements

  1. Event-Driven Architecture: Implement message queues (RabbitMQ/Kafka)
  2. Distributed Tracing: Add OpenTelemetry integration
  3. Metrics Collection: Prometheus and Grafana monitoring
  4. GraphQL Gateway: Alternative API layer
  5. Search Service: Elasticsearch integration
  6. Analytics Service: Event logging and analytics
  7. Payment Gateway Integration: Real payment processing
  8. Machine Learning: Recommendation engine

About

Production-ready microservices e-commerce platform with Go, gRPC, PostgreSQL, and Redis

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors