Github: https://github.com/kudligi/urlshortener
DockerHub: https://hub.docker.com/repository/docker/kudligi97/urlshortener
-
POST /shorten
Request Body Schema
long_url string, required, url
Response Body Schema
long_url string, url
short_url string, url
Sample request body : { "long_url" : "https://go.dev/blog/error-handling-and-go" }
Sample response body : {
"long_url": "https://go.dev/blog/error-handling-and-go",
"short_url": "http://localhost:4000/38TH3nxg"
}
same long url will always result in same short url within app lifetime.
-
GET shorturl > Redirects to the registered long url
-
POST /shortenBenchmark
Request Body Schema
Response Body Schema
long_url string, url
short_url string, url
Setup Continuous build-test-promote using github actions.
- AppLayer
- Config loaded from environement variables
- Handlers
- DataService
- In Memory Data Store:
- Plain Maps
- sync.Map
- Map + RwMutex
- Map + persistence checkpoints at intervals
- Utility to generate well distributed random short urls
- Seeding RNG with cryptographically secure random number
- Redis based Data Store
Minimal tests for:
- Router
- DataService
- RandomUrl Utility
TODO : Add more automated testig
Load Tested using apache bench tool to simulate conncurrent requests under load conditions to validate correctness and measure impace on performance as implimentation was changing. https://httpd.apache.org/docs/2.4/programs/ab.html
- simultaneous requests to create shorturl for random long urls
$ ab.exe -p sample.json -T application/json -v -c 10 -n 1000 localhost:4000/shortenBenchmark
- simultaneous requests to create shorturl for same long url (supply in sample.json)
$ ab.exe -p sample.json -T application/json -v -c 10 -n 1000 localhost:4000/shorten
- simultaneous requests to redirect for same short url
$ab.exe -c 10 -n 1000 < shortUrl >
- Redis as a distributed/persistent state store.
- Stateless App can be scaled horizontally.
- Nginx loadbalancer to distribute load between the app containers
- Docker Compose as orchestrator
To Start the application with 3 webcontainers:
$ git clone https://github.com/kudligi/urlshortener
$ cd urlshortner
$ docker compose up --scale web=3
Server will be listening on http://localhost:4000/
To Start the application with 3 webcontainers:
$ docker run -p 4000:9090 kudligi97/urlshortener:standalone
Server will be listening on http://localhost:4000/
To Start the application with 3 webcontainers:
$ docker volume create my-vol
$ docker run -p 4000:9090 -v my-vol:/go/app/persist kudligi97/urlshortener:standalone-persistent
Server will be listening on http://localhost:4000/