url-shortening is a micro-service solution that allows storing short urls
Micro-services:
- api-service − service to create short urls and redirect by them
- id-service − service to identify api-services if multiple of them have been started
- hazelcast-service − IMDG service (aka cache) to store and retrieve urls
- config-service − service to store all service configs
- eureka-service − service discovery
- zuul-service − entry-point service with LB
Storage:
- Hazelcast − IMDG solution included into hazelcast-service. Can be distributed, so all solution can be scaled easily
TODO: add picture
If you run solution at localhost
with default properties then entry-point url will be localhost:8090
All communication between services and API is REST
- Request:
Response:
GET /as/<shortUrl>
302 Found Location: <long_url>
- Request:
Response:
POST /as { "url" : "<long_url_here>"" }
200 OK <shortUrl>
- java >= 1.8 (make sure java is added to $PATH environment)
- docker + docker-compose (optional: for convenient start only)
Run the following command from the project root:
./gradlew cleand build
To start any service go the according folder (e.g. api-service)
cd api-service/build/libs
and run
java -jar api-service.jar
To run multiple instances of service you should change the start-up port:
java -jar api-service.jar --server.port=[port]
Build the whole project as described in build section and then run the following command:
docker-compose build
Project has docker-compose.yml for example with the following service configuration:
- eureka-service - 1 instance
- config-service - 1 instance
- zuul-service - 1 instance
- hazelcast-service - 3 instances
- id-service - 1 instance
- api-service - 2 instances
As for now there is no dependencies between services they should be started in the order they mentioned above. So the start will look like:
docker-compose -d up eureka-service
docker-compose -d up config-service
docker-compose -d up zuul-service
docker-compose -d up hazelcast-service-1 hazelcast-service-2 hazelcast-service-3
docker-compose -d up id-service
docker-compose -d up api-service-1 api-service-2
Request API stays the same
For simple load testing ab utility can be used:
ab -p ./post.json -T application/json -n 100000 -c 4 -k http://localhost:8090/as
where post.json file contains request body. Read request:
ab -n 100000 -c 4 -k http://localhost:8090/as/<short_url>
where <short_url> − one of short urls generated at previous step
- Data storage under Hazelcast
- id-service must free IDs not in use
- Run services with tune memory
- Start up of some service must depend on other ones
- Integration tests
- Docker build images via Gradle task
- Separate read and write operations into two services
- Set expiration time for urls
- Add DeveloperConsole service
- Spring-boot-starters for common configs