Table of Contents
Cory Ellerbroek - [email protected]
I was tasked to develop a RESTful API service for a mock online clothing store's "Questions and Answers" section. I was provided three csv files with millions of data points for consideration. The tech stack was completely up to me to decide and the biggest decision I had to make was which DBMS to use. I chose the PostgreSQL relational database because it would provide an ideal data structure for the imported data and I knew the queries could be tuned to respond quickly.
I encountered a challenge while importing the data into the database due to a 13 digit Unix timestamp, which Postgres did not natively accept. I solved this by transforming the Unix timestamp into a Postgres readable timestamp during the ETL process.
Server-side caching was implemented with Redis and brought the average response time from 50-80 ms down to 5-15 ms per request.
Once the server and database were fully functioning with the front end client, I deployed the server and database on separate AWS EC2 instances. Extensive integration, unit, and stress testing was developed locally and performed after deploying to ensure optimal functioning. The single server could handle over 1000 requests per second without error, but the response time began to significantly increase between 700 and 800 requests per second. This is where my time on this projected ended, but my next step would have been to implement multiple server instances and a load balancer.
HTTP Server
Database Management System
Testing & Monitoring
GET Endpoint: /qa/:product_id
Retrieves a list of questions for a particular product. This list does not include any reported questions.
Parameters | Type | Description |
---|---|---|
product_id | integer | Specifies the product for which to retrieve questions. |
Parameters | 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
Returns answers for a given question. This list does not include any reported answers.
GET Endpoint: /qa/questions/:question_id/answers
Parameters | Type | Description |
---|---|---|
question_id | integer | Required ID of the question for which answers are needed. |
Parameters | 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
Adds a question for the given product.
POST Endpoint: /qa
Parameters | 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. |
Response Status: 201 CREATED
Adds an answer for the given question.
POST Endpoint: /qa/:question_id/answers
Parameters | Type | Description |
---|---|---|
question_id | integer | Required ID of the question being answered. |
Parameters | Type | Description |
---|---|---|
body | text | Text of answer. |
name | text | Username for answerer. |
text | Email address for answerer. | |
photos | [text] | An array of urls corresponding to images to display. |
Response Status: 201 CREATED
Updates a question to show it was found helpful.
PUT Endpoint: /qa/questions/:question_id/helpful
Parameters | Type | Description |
---|---|---|
question_id | integer | Required ID of the question to update. |
Response 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 Endpoint: /qa/questions/:question_id/report
Parameters | Type | Description |
---|---|---|
question_id | integer | Required ID of the question to update. |
Response Status: 204 NO CONTENT
Updates an answer to show it was found helpful.
PUT Endpoint: /qa/answers/:answer_id/helpful
Parameters | Type | Description |
---|---|---|
answer_id | integer | Required ID of the answer to update. |
Response 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 Endpoint: /qa/answers/:answer_id/report
Parameters | Type | Description |
---|---|---|
answer_id | integer | Required ID of the answer to update. |
Response Status: 204 NO CONTENT