Skip to content

Sierra-SDC/questions-answers

Repository files navigation

Issues MIT License LinkedIn


Logo

Atelier Questions and Answers API

Implementing a back-end infrastructure for client e-commerce react app.


Please reqest to view a demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Built With
  3. Getting Started
  4. Tests
  5. Contact

About The Project

Plan and implement an AWS architecture to serve ~10 Million products to the client React app. Goal was to be able to handle ~10,000 requests per second.

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

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 for wich answers are needed

QueryParameters

Parameter Type Description
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

Add a Question

Adds a question for the given product

POST /qa/questions

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
product_id integer Required ID of the Product for which the question is posted

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

Built With

Getting Started

Docker

Dockerfile can be found within the repo.

  • docker run
    sudo docker run -it -d -p 80:3000 --name api-server docker-api-server:latest

Manual Server API Installation (AWS EC2 T2 Micro)

  1. Clone the repo
    git clone https://github.com/Sierra-SDC/questions-answers
  2. Install NPM packages
    npm install

Usage

Here is a copy of the react front-end proejct. https://github.com/lerisse/project-catwalk

Tests

Initial Postgres query: /qa/questions/:product_id

Seq Scan on questions  (cost=0.00..8169534.57 rows=9 width=116) (actual time=735.729..3163.416 rows=4 loops=1)
  Filter: ((product_id = 11008) AND (reported = 0))
  Rows Removed by Filter: 3518963
  SubPlan 2
    ->  Aggregate  (cost=894934.45..894934.46 rows=1 width=32) (actual time=686.701..686.701 rows=1 loops=4)
          ->  Seq Scan on answers  (cost=0.00..207166.85 rows=10 width=80) (actual time=166.982..424.105 rows=2 loops=4)
                Filter: (questions.id = question_id)
                Rows Removed by Filter: 6879304
          SubPlan 1
            ->  Aggregate  (cost=68776.75..68776.76 rows=1 width=32) (actual time=131.268..131.268 rows=1 loops=8)
                  ->  Seq Scan on photos  (cost=0.00..68776.74 rows=1 width=132) (actual time=81.244..131.254 rows=0 loops=8)
                        Filter: (answers.id = answer_id)
                        Rows Removed by Filter: 2063759
Planning Time: 0.294 ms
JIT:
  Functions: 18
  Options: Inlining true, Optimization true, Expressions true, Deforming true
  Timing: Generation 1.239 ms, Inlining 48.318 ms, Optimization 71.709 ms, Emission 45.062 ms, Total 166.328 ms
Execution Time: 3199.905 ms

After Indexing

Index Scan using questions_index on questions  (cost=0.43..848.28 rows=9 width=116) (actual time=0.061..0.121 rows=4 loops=1)
  Index Cond: (product_id = 11008)
  Filter: (reported = 0)
  SubPlan 2
    ->  Aggregate  (cost=93.28..93.30 rows=1 width=32) (actual time=0.024..0.024 rows=1 loops=4)
          ->  Index Scan using answers_index on answers  (cost=0.43..8.61 rows=10 width=80) (actual time=0.003..0.004 rows=2 loops=4)
                Index Cond: (question_id = questions.id)
          SubPlan 1
            ->  Aggregate  (cost=8.45..8.46 rows=1 width=32) (actual time=0.004..0.004 rows=1 loops=8)
                  ->  Index Scan using photos_index on photos  (cost=0.43..8.45 rows=1 width=132) (actual time=0.001..0.002 rows=0 loops=8)
                        Index Cond: (answer_id = answers.id)
Planning Time: 0.123 ms
Execution Time: 0.148 ms

Loader.io results

Structure:

  • 2 API Servers : AWS EC2 T1 Micro runing Ubuntu Linux with docker
  • 1 Nginx Server: AWS EC2 T1 Micro
  • 1 Postgres DB Server: AWS EC2 T1 Micro
  • 1 Redis DB Server: AWS EC2 T1 Micro

Loader.io Test

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Tristan Lerisse - tristanlerisse@gmail.com

Project Link: https://github.com/Sierra-SDC/questions-answers

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published