Solution to the take-home assignment of an interview process I took part in 2022. Description of the assignment can be found here.
All the work has been done on a 2021 16" Apple Macbook Pro with the following specs:
- M1 Pro processor (10-core CPU and 16-core GPU)
- 32 GB of RAM
- 1 TB SSD
- Go 1.18.3 (with chi 5.0.7)
- macOS Monterey 12.4
Before developing the server, some algorithms were developed and benchmarked. A compromise between speed, efficiency, and readability led to the choice of the algorithm used in the server.
Algorithms and benchmarks can be found under cmd/cli.
The algorithm chosen is sliceDiff
.
As far as I understood, sorting the list of flights was a suggestion, not a requirement. All the algorithms implemented don't sort the flights: they look for non-duplicated elements.
Track()
contains the algorithm used by the server.
The API has two endpoints:
Basic health check to detect if the application is responding. It answers to GET
requests only.
curl -i http://localhost:8080
HTTP/1.1 200 OK
Date: Sat, 09 Jul 2022 17:51:45 GMT
Content-Length: 0
It returns the starting airport and the final airport from a list of unordered flights.
It answers to POST
requests only. The list of flights should be fed via .json
.
[
{
"start": "SFO",
"end": "ATL"
},
{
"start": "ATL",
"end": "GSO"
}
]
More examples can be found under testdata.
curl -i \
-X \
POST \
-d \
@testdata/long.json \
http://localhost:8080/track
HTTP/1.1 200 OK
Content-Type: application/json
Date: Sat, 09 Jul 2022 18:01:21 GMT
Content-Length: 36
{
"start": "BGY",
"end": "AKL"
}
Prerequisite: you need either Golang or Docker installed on your machine.
The server runs on port 8080
.
Before running the server you might want to execute go mod tidy
to download potentially missing dependencies.
make http
runs the server on your machine
The docker-compose can be found here. The docker-compose builds the Docker image corresponding to this Dockerfile and starts the server.
make dev
runs the docker-compose in the backgroundmake logs
follows the docker-compose logsmake nodev
stops and removes the containermake devrebuild
rebuilds the image and runs the container in the background
The Makefile also contains commands to execute HTTP requests to the server's endpoints.
make health
performs aGET
request to the/health
endpointmake track
performs aPOST
request to the/track
endpoint. It uses the file long.json. You can change the input file by feeding the variableDATA
to the command. Example:
DATA=testdata/short.json make track
You can run the benchmarks on your machine (you need Golang installed) with the command: make bench
.
- trivy was used to identify vulnerabilities in the Dockerfile
- hadolint was used to lint the Dockerfile
- golangci-lint was used to lint the Go code
The following are ideas that haven't been implemented due to lack of time.
- input data validation: output can be unpredictable if the list of flights is not valid
- config file: it comes handy having the HTTP port configurable. go-yaml is a good library for
.yaml
config files - logger: logging has been implemented with the standard library's
log
package. A better alternative would be logrus - data generator: the idea was to create a function able to generate a list with hundres/thousands of flights, to better understand which algorithm scales better
- live reload: reflex is a great tool to test code changes without having to restart the server
- unit tests: self-explanatory