Skip to content

TheChimeraBros/Reviews-API-Service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reviews-API-Service

The Reviews API has been refractored as a microservice from the existing monolithic API for the e-commerce website, Atelier. It responds to several RESTful endpoints and has been optimized to handle web-scale traffic.

Optimizations:

  • Implemented an ETL process to migrate over 5GB/13M+ entries into a redesigned postgreSQL database.
  • Scaled horizontally to a micro-service architecture with 3 AWS EC2 instances.
  • Installed an NGINX load balancer to distribute traffic across servers and utilize proxy_caching.

Stress Testing

Randomized selection from bottom 10% of 13M+ entry dataset @1000RPS

Optimization Requests Per Sec Avg. Response Time Error %
EC2 Express Server W/PostgreSQL on AWS 1000 4423 ms 34.3
EC2 Ecpress Server W/NGINX Load Balancer 1000 Fail Fail
2 EC2 Express Server W/NGNIX Load Balancer 1000 362ms 13.1
2 EC2 Express Server W/NGNIX Load Balancer W/ Proxy Cache 1000 43ms 0
3 EC2 Express Server W/NGNIX Load Balancer W/ Proxy Cache 2500 211ms 4.2

Getting Started

1. Clone the Repository

git clone https://github.com/TheChimeraBros/Reviews-API-Service.git

2. Install Dependencies

npm install

3. Follow the instructions in the README file located in the server folder to set up the database.

4. Configure Environment Variables

Create a .env file based on the example.env file.

5. Start the Server

To run the tests

npm run test

API Endpoints

GET/reviews/

Query Parameters

Parameters should be query strings.

Parameter Type Description
page integer Product for which to retrieve questions.
count integer Specifies how many results per page to return. Default 5
sort text Changes the sort order of reviews to be based on "newest", "helpful", or "relevant"
product_id integer Specifies the product for which to retrieve reviews.

Response status: 200 OK


  {
  "product": "2",
  "page": 0,
  "count": 5,
  "results": [
    {
      "review_id": 5,
      "rating": 3,
      "summary": "I'm enjoying wearing these shades",
      "recommend": false,
      "response": null,
      "body": "Comfortable and practical.",
      "date": "2019-04-14T00:00:00.000Z",
      "reviewer_name": "shortandsweeet",
      "helpfulness": 5,
      "photos": [{
          "id": 1,
          "url": "urlplaceholder/review_5_photo_number_1.jpg"
        },
        {
          "id": 2,
          "url": "urlplaceholder/review_5_photo_number_2.jpg"
        },
        // ...
      ]
    },
    {
      "review_id": 3,
      "rating": 4,
      "summary": "I am liking these glasses",
      "recommend": false,
      "response": "Glad you're enjoying the product!",
      "body": "They are very dark. But that's good because I'm in very sunny spots",
      "date": "2019-06-23T00:00:00.000Z",
      "reviewer_name": "bigbrotherbenjamin",
      "helpfulness": 5,
      "photos": [],
    },
    // ...
  ]
}

GET/reviews/meta/

Parameters

Parameter Type Description
product_id integer Specifies the product for which to retrieve reviews.

Response status: 200 OK


  {
  "product_id": "2",
  "ratings": {
    2: 1,
    3: 1,
    4: 2,
    // ...
  },
  "recommended": {
    0: 5
    // ...
  },
  "characteristics": {
    "Size": {
      "id": 14,
      "value": "4.0000"
    },
    "Width": {
      "id": 15,
      "value": "3.5000"
    },
    "Comfort": {
      "id": 16,
      "value": "4.0000"
    },
    // ...
}

Add a Review

Adds a review for the given product

POST /reviews

Parameter Type Description
product_id integer Specifies the product for which to retrieve reviews.
rating int Integer (1-5) indicating the review rating
summary text Summary text of the review
body text Continued or full text of the review
recommend bool Value indicating if the reviewer recommends the product
name text Username for question asker
email text Email address for question asker
photos [text] Array of text urls that link to images to be shown
characteristics object Object of keys representing characteristic_id and values representing the review value for that characteristic. { "14": 5, "15": 5 //...}

Response status: 201 CREATED

Mark Review as Helpful

Updates a review to show it was found helfpul

PUT/reviews/:review_id/helpful/

Parameters

Parameter Type Description
review_id integer Required ID of the review to update

Response

Response status: 204 NO CONTENT

Report Review

Updates a review to show it was reported. Note, this action deos not delete the review, but the review will not be returned in the above GET request

PUT/reviews/:review_id/reportl/

Parameters

Parameter Type Description
review_id integer Required ID of the review to update

Response

Response status: 204 NO CONTENT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published