GithubHelp home page GithubHelp logo

angelproj's Introduction

AngelProj

API Spec

/addToCart

Method: POST

Content Type: application/json

Request Payload

{
  "clientID": "string",
  "productID": "string",
  "quantity": "integer"
}

Response

{
    "status": "string",
    "error": "string"
}

/checkOutCart

Method: POST

Content Type: application/json

Request Payload

{
  "clientID": "string"
}

Response

{
    "status": "string",
    "error": "string"
}

DB Tables

client_cart

+------------+--------------+------+-----+---------+-------+
| Field      | Type         | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| client_id  | varchar(100) | YES  |     | NULL    |       |
| product_id | varchar(100) | YES  |     | NULL    |       |
| quantity   | int          | YES  |     | NULL    |       |
+------------+--------------+------+-----+---------+-------+

product_details

+--------------+--------------+------+-----+---------+-------+
| Field        | Type         | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| product_id   | varchar(100) | YES  |     | NULL    |       |
| product_name | varchar(100) | YES  |     | NULL    |       |
| quantity     | int          | YES  |     | NULL    |       |
+--------------+--------------+------+-----+---------+-------+

reserve_purchase

+------------+--------------+------+-----+---------+-------+
| Field      | Type         | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| reserve_id | varchar(100) | YES  |     | NULL    |       |
| product_id | varchar(100) | YES  |     | NULL    |       |
| quantity   | int          | YES  |     | NULL    |       |
+------------+--------------+------+-----+---------+-------+

MicroServices

The project has 4 micro-services:

API GateWay:

Developed in NodeJS. It is exposed at port 5003 and has two endpoints:

/addToCart
/checkOutCart

The swagger documentation has the specification. Accessed using http://localhost:5003/documentation (need to start up the containers first)

Cart Manager:

Developed in Golang. It is a worker solely responsible to talk to CartDB.

The worker gets job from RMQ channel and performas follwoing categories of task:

  • Add Item To Cart: Adds an item to cart and responds to the API with the status

  • Checkout Cart: Checks out all the items in a cart and moves to payment gateway

Inventory Manager:

Developed in Golang and exposed as a gRPC service. It is solely responsible to talk to InventoryDB.

It performs a series of important operations:

  • Checks Item Quantity in Inventory

  • Reserves Items for Check out

  • Commits Reserved Items after successful Checkout: This operation depicts the following taks in order -

    1. Update the Inventory Table to reduce the available quantity
    2. Remove the reserved token from the reservation table
  • Rollback Reserved Items after unsuccessfuk CheckOut

CheckOut Manager:

Developed in Golang. It is a worker which gets the job pushed by only Cart manager.

On getting a job to check out the list of items,it performs the following taks:

  1. Asks Invenory Manager to Reseve the items
  2. Starts payment processing
  3. If successful asks Inventory Manager to commit the reservations
  4. If failed asks Inventory Manager to rollback the reservations

Components

  1. Microservices - Mentoioned above
  2. RabbitMQ - Queuing mechanisms for the workers so that they can scale easily
  3. MySQL - Backend DB to hold the data

architecture1

Check Out Sequence

sequence_diagram

Setting Up

  1. Install Docker and Docker-Compose in the system
  2. Make sure you have bash shell
  3. Run setup.sh
  4. Certain workers can still fail after starting. Need to get them separately. Pitfalls discussed below.

What's missing and concerns

  • Limited testing done. So bugs are expected.
  • No Unit tests available because of limited time.
  • Docker containers need to be set properly with some time out to get RMQ up first.
  • No Redis setup to improve the performance of the system using caching.
  • No Load balancer added to scale up the API or the gRPC service.
  • RMQ channels can be better named and typed.

angelproj's People

Contributors

kalroy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.