Skip to content

airelcamilo/rabbitmq-e-commerce-project

Repository files navigation

RabbitMQ E-commerce Order Management System

Welcome to the E-commerce Order Management System built using microservices! This system handles the core components of an e-commerce platform, such as order creation, payment processing, inventory management, and notification dispatch. The magic happens through RabbitMQ, which enables smooth asynchronous communication between the different services.

Microservices Overview

  1. Order Service

    • What it does: This service takes care of user registration, login, and order creation. Once an order is created, it sends messages to both the Payment Service and Inventory Service for further processing.
    • How it communicates: Publish order details to order.exchange with routing key order.created (for payment processing) and order.processed (for inventory update).
    • Language: Python
    • Packages: FastAPI (Framework), SQLAlchemy (ORM System), Alembic (Data Migration), Pika (RabbitMQ Python Client)

    API Endpoints: (for more info, please refer to the Postman collection file)

    • POST /register: Register a new user
      Form Data Content-Type: application/x-www-form-urlencoded:
      username=john@doe.com
      password=test123
      
    • POST /login: Log in as a user
      Form Data Content-Type: application/x-www-form-urlencoded:
      username=john@doe.com
      password=test123
      
    • POST /order: Create a new order
      Request:
      {
          "user_id": 1,
          "items": [
              {
              "name": "Item 1",
              "quantity": 2
              },
              {
              "name": "Item 2",
              "quantity": 1
              }
          ]
      }
      
  2. Payment Service

    • What it does: This service handles payment processing for orders. Once a payment is successful, it sends updates to both the Order Service and Notification Service.
    • How it communicates: Publish payment details to payment.exchange with routing key payment.processed to send order details to inventory service and send notifications.
    • Language: Go
    • Packages: Gorilla Mux (HTTP Router), Gorm (ORM System & Database Migration), amqp091 (RabbitMQ Go Client)

    API Endpoints: (for more info, please refer to the Postman collection file)

    • GET /payment?user_id={user_id}: Get payment for a user
    • POST /payment/{order_id}: Process a payment for a specific order
  3. Inventory Service

    • What it does: This service manages the inventory stock for orders. After processing an order, it updates stock levels and sends notifications.
    • How it communicates: Publish inventory details to inventory.exchange with routing key inventory.updated, to dispatch notifications about the inventory changes.
    • Language: Go
    • Packages: Gorilla Mux (HTTP Router), Gorm (ORM System & Database Migration), amqp091 (RabbitMQ Go Client)

    API Endpoints: (for more info, please refer to the Postman collection file)

    • GET /inventory?item_id={item_id}: Retrieve inventory stock for a specific item
  4. Notification Service

    • What it does: This service is responsible for sending notifications to users about their order status (e.g., payment processed, order packed).
    • Language: Python
    • Packages: FastAPI (Framework), SQLAlchemy (ORM System), Alembic (Data Migration), Pika (RabbitMQ Python Client)

    API Endpoints: (for more info, please refer to the Postman collection file)

    • GET /notification/{user_id}: Get notifications for a specific user

How It Works

This system operates asynchronously, meaning each service works independently and communicates with others through RabbitMQ queues. Here's a brief flow of how things happen:

  1. User places an order: Order Service takes the user's details and creates an order.
  2. Payment Processing: Order Service sends the order details to the Payment Service for processing. If successful, the payment is confirmed.
  3. Inventory Update: After payment is confirmed, the Inventory Service updates the stock.
  4. Notifications: After the payment and inventory update, the Notification Service sends out notifications to the user about the order status.

Below is the activity diagram that illustrates this flow: Activity Diagram E-commerce Order Management System

Getting Started

  1. Clone the repository.

  2. Run Docker and use the provided Docker Compose file to set up the services.

    To build and start the services, run:

    docker-compose up --build
    

    To stop the services and remove volumes, run:

    docker-compose down --volumes
    

Credit

Airel Camilo Khairan © 2025

About

A personal project designed to practice skills with RabbitMQ and microservices architecture. The project consists of two microservices built using Go and two using the Python FastAPI framework, with PostgreSQL as the database and Docker for containerization.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors