Implementing a back-end infrastructure for client e-commerce react app.
Please reqest to view a demo
·
Report Bug
·
Request Feature
Table of Contents
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.
GET /qa/questions
Retrieves a list of questions for a particular product. This list does not include any reported questions.
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. |
Status: 200 OK
Returns answers for a given question. This list does not include any reported answers.
GET /qa/questions/:question_id/answers
Parameter | Type | Description |
---|---|---|
question_id | integer | Required ID of the question for wich answers are needed |
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. |
Status: 200 OK
Adds a question for the given product
POST /qa/questions
Parameter | Type | Description |
---|---|---|
body | text | Text of question being asked |
name | text | Username for question asker |
text | Email address for question asker | |
product_id | integer | Required ID of the Product for which the question is posted |
Status: 201 CREATED
Adds an answer for the given question
POST /qa/questions/:question_id/answers
Parameter | Type | Description |
---|---|---|
question_id | integer | Required ID of the question to post the answer for |
Parameter | Type | Description |
---|---|---|
body | text | Text of question being asked |
name | text | Username for question asker |
text | Email address for question asker | |
photos | [text] | An array of urls corresponding to images to display |
Status: 201 CREATED
Updates a question to show it was found helpful.
PUT /qa/questions/:question_id/helpful
Parameter | Type | Description |
---|---|---|
question_id | integer | Required ID of the question to update |
Status: 204 NO CONTENT
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
Parameter | Type | Description |
---|---|---|
question_id | integer | Required ID of the question to update |
Status: 204 NO CONTENT
Updates an answer to show it was found helpful.
PUT /qa/answers/:answer_id/helpful
Parameter | Type | Description |
---|---|---|
answer_id | integer | Required ID of the answer to update |
Status: 204 NO CONTENT
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
Parameter | Type | Description |
---|---|---|
answer_id | integer | Required ID of the answer to update |
Status: 204 NO CONTENT
Dockerfile can be found within the repo.
- docker run
sudo docker run -it -d -p 80:3000 --name api-server docker-api-server:latest
- Clone the repo
git clone https://github.com/Sierra-SDC/questions-answers
- Install NPM packages
npm install
Here is a copy of the react front-end proejct. https://github.com/lerisse/project-catwalk
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
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
- 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
Distributed under the MIT License. See LICENSE
for more information.
Tristan Lerisse - tristanlerisse@gmail.com
Project Link: https://github.com/Sierra-SDC/questions-answers