Skip to content

Ujjwaljain16/E-commerce-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

64 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

WORK IN PROGRESS

E-Commerce Microservices Platform

A production-grade, distributed e-commerce backend system built with Go, gRPC, Kafka, GraphQL, and Kubernetes.

πŸš€ Overview

This project demonstrates a complete microservices architecture for an e-commerce platform, featuring:

  • Microservices Architecture: 5 independently deployable services
  • Event-Driven Design: Asynchronous communication via Kafka
  • API Gateway: Unified GraphQL interface
  • Authentication: JWT-based auth with role-based access control
  • Caching: Redis for performance optimization
  • Observability: Prometheus + Grafana monitoring, ELK logging
  • Container Orchestration: Docker Compose + Kubernetes
  • CI/CD: Automated testing and deployment pipelines

πŸ“ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    GraphQL Gateway                          β”‚
β”‚              (Unified API + Authentication)                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚ gRPC
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚          β”‚          β”‚          β”‚          β”‚
   β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β” β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β” β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β” β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   β”‚Account β”‚ β”‚Catalog β”‚ β”‚ Order  β”‚ β”‚Payment  β”‚ β”‚Notificationβ”‚
   β”‚Service β”‚ β”‚Service β”‚ β”‚Service β”‚ β”‚Service  β”‚ β”‚  Service   β”‚
   β””β”€β”€β”€β”€β”¬β”€β”€β”€β”˜ β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”¬β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚         β”‚          β”‚          β”‚          β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
                     Kafka Event Bus
                          β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚                 β”‚                 β”‚
   PostgreSQL          Redis          Elasticsearch

🎯 Services

1. Account Service

  • User registration and authentication
  • JWT token generation and validation
  • Role-based access control (USER/ADMIN)
  • Password hashing with bcrypt

Tech Stack: Go, gRPC, PostgreSQL, JWT

2. Catalog Service

  • Product CRUD operations
  • Full-text search with Elasticsearch
  • Redis caching for performance
  • Inventory management

Tech Stack: Go, gRPC, Elasticsearch, Redis

3. Order Service

  • Order creation and management
  • Order status tracking
  • Integration with Account & Catalog services
  • Event publishing to Kafka

Tech Stack: Go, gRPC, PostgreSQL, Kafka

4. Payment Service

  • Payment processing (Stripe mock integration)
  • Idempotency key support
  • Transaction management
  • Event-driven status updates

Tech Stack: Go, gRPC, PostgreSQL, Kafka, Redis

5. Notification Service

  • Email notifications (SMTP mock)
  • Event-driven notifications
  • Template-based messaging
  • Notification history

Tech Stack: Go, Kafka

6. GraphQL Gateway

  • Unified API for all services
  • Authentication middleware
  • Rate limiting
  • Query complexity analysis

Tech Stack: Go, gqlgen, gRPC clients

πŸ› οΈ Tech Stack

Languages & Frameworks:

  • Go 1.21+
  • gRPC & Protocol Buffers
  • GraphQL (gqlgen)

Databases:

  • PostgreSQL 15
  • Elasticsearch 8
  • Redis 7

Message Queue:

  • Apache Kafka

Observability:

  • Prometheus (metrics)
  • Grafana (dashboards)
  • ELK Stack (logging)

DevOps:

  • Docker & Docker Compose
  • Kubernetes
  • GitHub Actions (CI/CD)

Testing:

  • Go testing framework
  • Testcontainers (integration tests)
  • k6 (load testing)

🚦 Getting Started

Prerequisites

  • Go 1.21 or higher
  • Docker & Docker Compose
  • Protocol Buffers compiler (protoc)
  • kubectl (for Kubernetes deployment)

Installation

  1. Clone the repository
git clone https://github.com/Ujjwaljain16/E-commerce-Backend.git
cd E-commerce-Backend
  1. Install dependencies
go mod download
  1. Generate Protocol Buffer code
make proto-gen
  1. Start infrastructure services
docker-compose up -d
  1. Run database migrations
make migrate-up
  1. Start all services
# Terminal 1: Account Service
cd account/cmd/account && go run main.go

# Terminal 2: Catalog Service
cd catalog/cmd/catalog && go run main.go

# Terminal 3: Order Service
cd order/cmd/order && go run main.go

# Terminal 4: Payment Service
cd payment/cmd/payment && go run main.go

# Terminal 5: Notification Service
cd notification/cmd/notification && go run main.go

# Terminal 6: GraphQL Gateway
cd graphql && go run main.go
  1. Access the GraphQL Playground
http://localhost:8000/playground

πŸ“Š Example GraphQL Queries

Register User

mutation {
  register(input: {
    name: "John Doe"
    email: "john@example.com"
    password: "SecurePass123!"
  }) {
    account {
      id
      name
      email
    }
    accessToken
  }
}

Create Product

mutation {
  createProduct(input: {
    name: "Laptop"
    description: "High-performance laptop"
    price: 999.99
  }) {
    id
    name
    price
  }
}

Create Order

mutation {
  createOrder(input: {
    accountId: "acc_123"
    products: [
      { id: "prod_456", quantity: 2 }
    ]
  }) {
    id
    totalPrice
    status
  }
}

πŸ§ͺ Testing

Run unit tests

make test

Run integration tests

make integration-test

Run with coverage

make coverage

Load testing

make load-test

πŸ“ˆ Monitoring

Prometheus Metrics

  • URL: http://localhost:9090
  • Service-level metrics (RED: Rate, Errors, Duration)
  • Business metrics (orders/sec, revenue)

Grafana Dashboards

Logs (Kibana)

πŸš€ Deployment

Docker Compose (Local Development)

docker-compose up --build

Kubernetes (Production)

# Deploy to Kubernetes
kubectl apply -f k8s/

# Check deployment status
kubectl get pods -n ecommerce

# Access services
kubectl port-forward svc/graphql-gateway 8000:8080

πŸ“‚ Project Structure

ecommerce-microservices/
β”œβ”€β”€ account/              # Account service
β”‚   β”œβ”€β”€ pb/              # Generated protobuf code
β”‚   β”œβ”€β”€ cmd/account/     # Service entrypoint
β”‚   β”œβ”€β”€ migrations/      # Database migrations
β”‚   └── *.go             # Service implementation
β”œβ”€β”€ catalog/             # Catalog service
β”œβ”€β”€ order/               # Order service
β”œβ”€β”€ payment/             # Payment service
β”œβ”€β”€ notification/        # Notification service
β”œβ”€β”€ graphql/             # GraphQL gateway
β”œβ”€β”€ pkg/                 # Shared packages
β”‚   β”œβ”€β”€ auth/           # JWT utilities
β”‚   β”œβ”€β”€ kafka/          # Kafka producer/consumer
β”‚   β”œβ”€β”€ cache/          # Redis client
β”‚   β”œβ”€β”€ logger/         # Structured logging
β”‚   └── metrics/        # Prometheus metrics
β”œβ”€β”€ k8s/                 # Kubernetes manifests
β”œβ”€β”€ monitoring/          # Prometheus, Grafana configs
β”œβ”€β”€ tests/               # Integration & load tests
β”œβ”€β”€ docker-compose.yaml
└── Makefile

🀝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

Ujjwal Jain

πŸ™ Acknowledgments

  • Inspired by microservices architectures at Amazon, Netflix, and Uber
  • Built as a learning project to demonstrate production-grade backend engineering

πŸ“Š Performance Benchmarks

  • Order Creation: 800+ req/sec
  • Product Search: 1200+ req/sec
  • Authentication: 500+ req/sec
  • P95 Latency: < 100ms for all endpoints

πŸ”’ Security

  • JWT-based authentication
  • Password hashing with bcrypt
  • Input validation on all endpoints
  • SQL injection prevention
  • Rate limiting
  • CORS configuration

⭐ If you find this project useful, please consider giving it a star!

About

A distributed e-commerce backend platform implementing a real-world microservices architecture using Go, gRPC, Kafka, GraphQL, and Kubernetes. Includes authentication, catalog, order, payment, and notification services with observability, caching, CI/CD, and event-driven workflows.

Resources

License

Stars

Watchers

Forks

Contributors