Case Study: Kettl-Commerce Microservices Architecture

#microservice

#nest.js

#docker

#mongo

#mariadb

#typescript

#jest

#monorepo

Project Name:

Kettl Commerce

Overview:

Kettl-Commerce is a scalable and modular e-commerce platform designed using a microservices architecture. The platform is divided into several independently deployable services, each responsible for a specific domain of the e-commerce system. This architecture allows for flexibility, scalability, and ease of maintenance, making it easier to update, scale, or replace services as the system evolves.

Key Components

    1. Product Service

    • Description: Manages the catalog of products available in the e-commerce store. This includes CRUD operations on products, handling of categories, tags, brands, and product variations such as size and color. It also includes the Cart Module. Users can manage their cart items, add to cart, remove items from cart.
    • Documentation: http://127.0.0.1:3001/product-service-docs
    • Technologies:
      • Nest.js: Core framework for building the service.
      • MongoDB: Database for storing product information.
      • Redis: Integrated for caching product data to improve performance.
      • Swagger: Documentation for all API endpoints.
    • Key Features:
      • Product creation, updating, and deletion.
      • Product listing with pagination and filtering.
      • Product caching using Redis.
      • Swagger documentation for API endpoints.
      • Event-driven updates to the Notification Service when products are created or updated.
      • Cart creation and management.

    2. Order Service

    • Description: Manages customer orders, including order creation, payment processing, and order status tracking. The wishlist module has been added to the service, users can manage their wishlist items, add to their wishlist, and easily remove from their wishlist.
    • Documentation: http://127.0.0.1:3005/order-service-docs
    • Technologies:
      • Nest.js: Core framework for building the service.
      • MariaDB: Database for storing order-related data.
      • Redis: Used for caching frequent order queries.
      • Swagger: Documentation for all API endpoints.
    • Key Features:
      • Order creation and management.
      • Order status tracking and updates.
      • Caching of order data using Redis.
      • Event-driven communication with the Notification Service to inform customers of order status changes.
      • Wishlist creation and management.

    3. Notification Service

    • Description: Handles the dispatch of notifications to users based on events from other services (e.g., order status updates, product availability notifications).
    • Technologies:
      • Nest.js: Core framework for building the service.
      • Redis: Used for queuing notifications.
    • Key Features:
      • Event-driven architecture using the Nest.js Event Pattern.
      • Sending notifications via email

    4. Users & Auth Service

    • Description: Manages user authentication, authorization, and profile management.
    • Documentation: http://127.0.0.1:3002/auth-service-docs
    • Technologies:
      • Nest.js: Core framework for building the service.
      • MongoDB: Database for storing user data.
      • Swagger: Documentation for all API endpoints.
    • Key Features:
      • User registration, login, and profile management.
      • Forgot-password flow full integration with email notification
      • Cookie-based authentication.
      • Swagger documentation for API endpoints.

Technical Details

  • Microservices Management:
    • Each microservice is managed via Docker Compose, allowing for easy orchestration of the entire system, including dependencies like Redis, Elasticsearch, Filebeat, Kibana, MariaDB, and MongoDB.
    • Docker Compose files ensure that the entire system can be brought up with a single command, maintaining consistency across development, staging, and production environments.
  • Communication Between Services:
    • The microservices communicate with each other using an event-driven architecture facilitated by Nest.js Event Patterns.
    • The Notification Service subscribes to events from the Product Service, Order Service, and Users & Auth Service, allowing it to send timely notifications to users.
  • Logging & Monitoring:
    • Logging and monitoring are implemented for each service, ensuring easy monitoring on the application behavior.
    • Integrated ELK stack (Elasticsearch, Logstash, Kibana) and filebeat for log aggregation, monitoring, and visualization.
  • Testing:
    • Unit tests are implemented for services and modules, ensuring the reliability and stability of the codebase.
    • Each service has its own suite of tests, which can be run independently to validate functionality before deployment.
  • Monorepo Architecture:
    • The entire system is built using the Nest.js monorepo feature, which allows for the management of multiple services within a single repository.
    • This structure makes it easier to share common code, such as utility functions, configuration, and middleware, across services.
  • API Documentation:
    • Swagger is used to document all API endpoints across the microservices.
    • This documentation is automatically generated and kept up-to-date with the codebase, providing developers and external users with a comprehensive overview of the available APIs and how to interact with them.

Conclusion

Kettl-Commerce is designed to be a robust, scalable, and modular e-commerce platform. By leveraging microservices, Docker Compose, and an event-driven architecture, the system is well-equipped to handle high traffic, facilitate easy updates, and provide a seamless user experience. The use of Redis for caching, unit testing for reliability, and comprehensive API documentation ensures that the platform is both performant and developer-friendly.