Written in Hexagonal Architecture
This is a small API that provides basic REST endpoints to shorten a URL, get information about the URL, update the URL, and get statistics on most accessed URLs.
The technology behind it:
- Requests can come from many types of devices.
- Cloud Run is a fully managed serverless platform which already has an integrated load balance. See the doc here
- Cloud Run will automatically scale to the number of container instances needed to handle all incoming requests. See the doc here
- All request to get a URL will be checked in the cache first and any new URL that is generated will cached with a configurable TTL.
- All request to get a URL that is not found in the cache will be queried on the NoSQL and any new URL that is generated will be stored on the NoSQL.
- For eache redirect request, a message will be sent to a pubsub topic to record that we had one more access.
- Here, we have an Apache Beam pipeline running in Dataflow, to group all messages by Id in a fixed time window, that will update the NoSQL database. This is a separate project, see here
In the terminal run the following command:
docker-compose up
After starting the app you can access the documentation and test using the Try it on
option.
http://localhost:8090/doc/index.html
In the terminal run the following command:
go test -coverprofile=coverage.out -v ./...
Show the coverage report on terminal:
go tool cover -func=coverage.out
Open the coverage report in HTML format:
go tool cover -html=coverage.out
https://url-shortener-ztiqwvbfiq-rj.a.run.app/doc/
20 users making 500 parallel requests during 1min 19sec, total 10,000 requests:
CPU utilization:
Memory utilization: