Skip to content

About

Microservices e-commerce backend featuring independent Node.js services, MongoDB, PostgreSQL databases, and containerized deployment with Docker and K8s

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

E-commerce Microservices with Kubernetes - v1

Designed and deployed a containerized microservices-based e-commerce backend with independent scaling, service isolation, and Kubernetes orchestration to simulate production-grade distributed systems.

I made this project to understand how scalable and large-scale software systems are designed, deployed, scaled, and managed in real-world environments. Instead of building a monolithic application, this project follows a microservices architecture similar to what is used in production-grade e-commerce platforms.

The application is split into independent services such as User Service, Product Service, Order Service, and supporting infrastructure components. Each service is developed, containerized, and deployed independently locally using minikube, allowing the system to scale specific services based on demand rather than scaling the entire application.

Tech Stack:

NodeJS Express.js TypeScript AWS MongoDB Postgres Docker Kubernetes Postman Redis Drizzle

Folder Structure

ecommerce-microservices/
│
├── amazon-data.json
├── README.md
│
├── api-gateway/
│   ├── src/
│   │   └── index.ts
│   ├── Dockerfile
│   ├── deployment.yaml
│   ├── service.yaml
│   ├── compose.yaml
│   └── package.json
│
├── user-service/
│   ├── src/
│   │   ├── controllers/
│   │   ├── routes/
│   │   ├── schema.ts
│   │   ├── db.ts
│   │   └── index.ts
│   ├── Dockerfile
│   ├── deployment.yaml
│   ├── service.yaml
│   ├── compose.yaml
│   └── package.json
│
├── product-service/
│   ├── src/
│   │   ├── controllers/
│   │   ├── models/
│   │   ├── routes/
│   │   ├── utils/
│   │   ├── db.ts
│   │   └── index.ts
│   ├── Dockerfile
│   ├── deployment.yaml
│   ├── service.yaml
│   ├── compose.yaml
│   └── package.json
│
└── order-service/
    ├── src/
    │   ├── controllers/
    │   ├── routes/
    │   ├── schema.ts
    │   ├── db.ts
    │   └── index.ts
    ├── Dockerfile
    ├── deployment.yaml
    ├── service.yaml
    ├── compose.yaml
    └── package.json

System Architecture

ecommerce microservice diagram DFD

1. Product Service

In the Product Microservice, I implemented:

  1. Pagination of products to improve the API performance, reducing memory storage, and lowering the server load.
  2. Storage for the Product Images in AWS S3 Bucket
  3. Database being MongoDB, it was chosen as the database due to its suitability for scenarios with a high View-to-Update ratio (approximately 3%), indicating significantly more read operations compared to write operations.
  4. Implemented Cache Key based Caching using redis(in-memory key-value based db) for fetching product details with low latency and also implemented removal of cached data whenever operations such as creation, updation, or deletion happens in the database to keep data consistency. Latency decreased by 90.4%

2. User Service

In the User Microservice, I Implemented:

  1. Database being PostgreSQL, for relational and transactional operations

ER Diagram

3. Order Service

In the Order Microservice , Implemented:

  1. Database being PostgreSQL, for relational and transactional operations
  2. Synchronous Sevice-to-Service Communication between this service and user & product service - when creating an order multiple transactional operations where this service sends a request to the product-service or user-service and await for response.

ER Diagrams

Challenges Faced & Learnings

  1. Managing inter-service communication failures
  2. Handling environment variable configuration across services
  3. Understanding difference between ClusterIP and NodePort Debugging networking issues in Kubernetes
  4. Understanding good API development practices like pagination, soft deleting etc.
  5. Understanding failures due to version controlling in code, docker images and pod deployments
  6. Understood about logging, api-gateway practices, and server debugging.

Future Improvements

  1. Asynchronous communication using Kafka or RabbitMQ (Message Queues)
  2. Redis caching layer
  3. CI/CD pipeline using GitHub Actions
  4. Centralized config management
  5. Distributed Authentication and Authorization
  6. Language Agnostic Services (using Java, or Golang for concurrency or python for a basic recommender service using user purchase history)
  7. Use RDS for databases and EKS for Kubernetes in cloud (optional)

References:

Advantages of having Mircoservice Architecture (these are what I observed):

  1. Isolated Scaling, Deployment and Monitoring
  2. It's modular, multiple devs can work independently on different modules
  3. If any error occurs in one module, no need to stop all the services
  4. Multiple languages can be used (Go, Java, JS, Python etc) each can be used for its features and advantages, like python can be used for ML-related services, Go and Java can be used for concurrency and robust services, node.js can be used for lightweight services (rapid development).

Disadvantages of having Mircoservice Architecture (these are what I observed):

  1. Too complex to implement for simple backend systems, imagine having to track multiple services' deployments, monitoring and maintainance
  2. Communication and Data Transfer complexity is too much and can raise issues.
  3. Data Management Challenges, handling multiple DBs hence handing data between Relational and Non-relational Dbs is challenging.
  4. Testing Overhead, too many things to test

Get Started:

I have added the documentation to start and run each service in its designated service folder.

For Redis Deployment, run kubectl apply -f k8s/redis-deployment.yaml & kubectl apply -f k8s/redis-service.yaml

Screenshot(s)

minikube dashboard

About

Microservices e-commerce backend featuring independent Node.js services, MongoDB, PostgreSQL databases, and containerized deployment with Docker and K8s

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages