Inga 🏳🌈
302af9b5f9
|
1 year ago | |
---|---|---|
src | 1 year ago | |
test | 1 year ago | |
.eslintrc.js | 1 year ago | |
.gitignore | 1 year ago | |
.prettierrc | 1 year ago | |
README.md | 1 year ago | |
nest-cli.json | 1 year ago | |
package-lock.json | 1 year ago | |
package.json | 1 year ago | |
tsconfig.build.json | 1 year ago | |
tsconfig.json | 1 year ago |
README.md
Assignment
👉 Our Expectations
We greatly appreciate your commitment to this process.
The main goal of this task is to:
- Get to know how you work
- Assess your general understanding and expertise in relevant aspects of backend development
- Ultimately, have a conversation with you to discuss the actions you performed, results, and any issues encountered.
We do not want to create a stressful situation for you or interfere with your daily activities. Therefore, you should not invest more than a few hours in executing this task.
Please feel free to contact us at any time if you have any questions.
We are confident that you will do your best, and we are looking forward to reviewing the output with you. 😊
💡 Track and Trace API
The Track and Trace page enables end users (receiver of a shipment) to monitor the status of their shipment.
Your task is to create a backend API that serves shipment data and provides users with current weather conditions at their location.
Guideline
You have been provided with a CSV file (below) containing sample shipment and article data to seed your data structures. Your task is to create an API application that performs the following:
- Provides a RESTful or GraphQL Endpoint that exposes shipment and article information along with corresponding weather information.
- Allows consumers to lookup shipments via tracking number and carrier.
Hints:
- Integrate a suitable weather API: Choose a weather API (e.g., OpenWeatherMap, Weatherbit, or any other free API) and fetch the weather information for the respective locations.
- Limit weather data retrieval: Ensure that weather information for the same location (zip code) is fetched at most every 2 hours to minimize API calls.
- You can use any framework or library that you feel comfortable with.
Nice to have:
- Provide unit tests and/or integration tests for the application.
- OpenAPI docs
- Implement the API using an well-known backend framework.
Solution
Deliverables:
- Application code, tests, and documentation needed to run the code.
Evaluation Criteria:
- Code quality and organization
- Functional correctness
- Efficiency, robustness, and adequate design choices
Discussion Points:
- What were the important design choices and trade-offs you made?
- What would be required to deploy this application to production?
- What would be required to scale this application to handle 1000 requests per second?
Seed Data
NB: you don’t need to write an import, if that is too time consuming, you can just setup one or two sample items in the DB via any mechanism you like.
tracking_number,carrier,sender_address,receiver_address,article_name,article_quantity,article_price,SKU,status
TN12345678,DHL,"Street 1, 10115 Berlin, Germany","Street 10, 75001 Paris, France",Laptop,1,800,LP123,in-transit
TN12345678,DHL,"Street 1, 10115 Berlin, Germany","Street 10, 75001 Paris, France",Mouse,1,25,MO456,in-transit
TN12345679,UPS,"Street 2, 20144 Hamburg, Germany","Street 20, 1000 Brussels, Belgium",Monitor,2,200,MT789,inbound-scan
TN12345680,DPD,"Street 3, 80331 Munich, Germany","Street 5, 28013 Madrid, Spain",Keyboard,1,50,KB012,delivery
TN12345680,DPD,"Street 3, 80331 Munich, Germany","Street 5, 28013 Madrid, Spain",Mouse,1,25,MO456,delivery
TN12345681,FedEx,"Street 4, 50667 Cologne, Germany","Street 9, 1016 Amsterdam, Netherlands",Laptop,1,900,LP345,transit
TN12345681,FedEx,"Street 4, 50667 Cologne, Germany","Street 9, 1016 Amsterdam, Netherlands",Headphones,1,100,HP678,transit
TN12345682,GLS,"Street 5, 70173 Stuttgart, Germany","Street 15, 1050 Copenhagen, Denmark",Smartphone,1,500,SP901,scanned
TN12345682,GLS,"Street 5, 70173 Stuttgart, Germany","Street 15, 1050 Copenhagen, Denmark",Charger,1,20,CH234,scanned
That is it - everything else is up to you! Happy coding!
Solution
Performance
What would be required to scale this application to handle 1000 requests per second?
This application already handles over 3000 requests per second with ease, even with an artificial 20ms cache access latency.
Granted this is all for the same URL, and it can be slower if we will be requesting different URLs.
❯ ab -c 500 -n 100000 http://127.0.0.1:3000/packages/UPS/TN12345679
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 127.0.0.1 (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests
Server Software:
Server Hostname: 127.0.0.1
Server Port: 3000
Document Path: /packages/UPS/TN12345679
Document Length: 394 bytes
Concurrency Level: 500
Time taken for tests: 29.422 seconds
Complete requests: 100000
Failed requests: 0
Total transferred: 60300000 bytes
HTML transferred: 39400000 bytes
Requests per second: 3398.84 [#/sec] (mean)
Time per request: 147.109 [ms] (mean)
Time per request: 0.294 [ms] (mean, across all concurrent requests)
Transfer rate: 2001.47 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 7 3.5 7 19
Processing: 98 139 11.0 137 251
Waiting: 89 115 12.7 114 222
Total: 103 146 10.7 144 259
Percentage of the requests served within a certain time (ms)
50% 144
66% 146
75% 149
80% 151
90% 159
95% 166
98% 170
99% 172
100% 259 (longest request)
Nest project readme
Description
Nest framework TypeScript starter repository.
Installation
$ npm install
Running the app
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
Test
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
Support
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
Stay in touch
- Author - Kamil Myśliwiec
- Website - https://nestjs.com
- Twitter - @nestframework
License
Nest is MIT licensed.