Coder Social home page Coder Social logo

atelier-system-design-qna-service's Introduction

Atelier Q&A | Back-end services for e-commerce site

I worked with other two software engineers to rebuild the back-end API service from a monolithic to service-oriented microservices to support our existing e-commerce application in this project. The service I built was scaled to meet the demands of production traffic, which is 5000rps with < 1s response time with a 0% error rate.

Technologies used

Backend Development: Node.js, Express, Postgres, NGINX
Deployment: AWS EC2, AWS Images
Testing: Jest, SuperTest, K6, Loader.io, New Relic

Table of Contents

System Design

Database Design

Phase 1 - SQL schema updated after realdata

Architecture

Screenshot 2022-11-11 at 2 58 30 PM

Stress Test Results via Loader.io

image

image (1)

Usage

List Questions

GET /qa/questions Retrieves a list of questions for a particular product. This list does not include any reported questions.

Parameters

Parameter Type Description
product_id integer Specifies the product for which to retrieve questions.
page integer Selects the page of results to return. Default 1.
count integer Specifies how many results per page to return. Default 5.

Response

Status: 200 OK

{
  "product_id": "5",
  "results": [{
        "question_id": 37,
        "question_body": "Why is this product cheaper here than other sites?",
        "question_date": "2018-10-18T00:00:00.000Z",
        "asker_name": "williamsmith",
        "question_helpfulness": 4,
        "reported": 0,
        "answers": {
          "68": {
            "id": 68,
            "body": "We are selling it here without any markup from the middleman!",
            "date": "2018-08-18T00:00:00.000Z",
            "answerer_name": "Seller",
            "helpfulness": 4,
            "photos": []
            // ...
          }
        }
      },
      {
        "question_id": 38,
        "question_body": "How long does it last?",
        "question_date": "2019-06-28T00:00:00.000Z",
        "asker_name": "funnygirl",
        "question_helpfulness": 2,
        "reported": 0,
        "answers": {
          "70": {
            "id": 70,
            "body": "Some of the seams started splitting the first time I wore it!",
            "date": "2019-11-28T00:00:00.000Z",
            "answerer_name": "sillyguy",
            "helpfulness": 6,
            "photos": [],
          },
          "78": {
            "id": 78,
            "body": "9 lives",
            "date": "2019-11-12T00:00:00.000Z",
            "answerer_name": "iluvdogz",
            "helpfulness": 31,
            "photos": [],
          }
        }
      },
      // ...
  ]
}

Answers List

Returns answers for a given question. This list does not include any reported answers.

GET /qa/questions/:question_id/answers

Parameters

Parameter Type Description
question_id integer Required ID of the Question requested
page integer Selects the page of results to return. Default 1.
count integer Specifies how many results per page to return. Default 5.

Response

Status: 200 OK

{
  "question": "1",
  "page": 0,
  "count": 5,
  "results": [
    {
      "answer_id": 8,
      "body": "What a great question!",
      "date": "2018-01-04T00:00:00.000Z",
      "answerer_name": "metslover",
      "helpfulness": 8,
      "photos": [],
    },
    {
      "answer_id": 5,
      "body": "Something pretty durable but I can't be sure",
      "date": "2018-01-04T00:00:00.000Z",
      "answerer_name": "metslover",
      "helpfulness": 5,
      "photos": [{
          "id": 1,
          "url": "urlplaceholder/answer_5_photo_number_1.jpg"
        },
        {
          "id": 2,
          "url": "urlplaceholder/answer_5_photo_number_2.jpg"
        },
        // ...
      ]
    },
    // ...
  ]
}

Add a Question

Adds a question for the given product

POST /qa/questions

Parameters

Parameter Type Description
product_id integer Required ID of the Product to post the question for

Body Parameters

Parameter Type Description
body text Text of question being asked
name text Username for question asker
email text Email address for question asker

Response

Status: 201 CREATED

Add an Answer

Adds an answer for the given question

POST /qa/questions/:question_id/answers

Parameters

Parameter Type Description
question_id integer Required ID of the question to post the answer for

Body Parameters

Parameter Type Description
body text Text of question being asked
name text Username for question asker
email text Email address for question asker
photos [text] An array of urls corresponding to images to display

Response

Status: 201 CREATED

Mark Question as Helpful

Updates a question to show it was found helpful.

PUT /qa/questions/:question_id/helpful

Parameters

Parameter Type Description
question_id integer Required ID of the question to update

Response

Status: 204 NO CONTENT

Report Question

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

PUT /qa/questions/:question_id/report

Parameters

Parameter Type Description
question_id integer Required ID of the question to update

Response

Status: 204 NO CONTENT

Mark Answer as Helpful

Updates an answer to show it was found helpful.

PUT /qa/answers/:answer_id/helpful

Parameters

Parameter Type Description
answer_id integer Required ID of the answer to update

Response

Status: 204 NO CONTENT

Report Answer

Updates an answer to show it has been reported. Note, this action does not delete the answer, but the answer will not be returned in the above GET request.

PUT /qa/answers/:answer_id/report

Parameters

Parameter Type Description
answer_id integer Required ID of the answer to update

Response

Status: 204 NO CONTENT

Installation

  1. Fork the project and clone to your local repository
  2. To start server, run npm run start
  3. Test by typing http://localhost:3000/qa/questions in the Postman to see the response
  4. To run tests, run npm run test

atelier-system-design-qna-service's People

Contributors

shiweicc avatar gyhcy avatar cbaharian 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.