Skip to content

raymon-02/url-shortening

Repository files navigation

url-shortening

Overview

url-shortening is a micro-service solution that allows storing short urls

Architecture

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

API

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:
    GET /as/<shortUrl>
    
    Response:
    302 Found 
    Location: <long_url>
    
  • Request:
    POST /as 
    {
        "url" : "<long_url_here>""
    }
    
    Response:
    200 OK 
    <shortUrl>
    

Build and start

Requirements
  • java >= 1.8 (make sure java is added to $PATH environment)
  • docker + docker-compose (optional: for convenient start only)
Building

Run the following command from the project root:

./gradlew cleand build
Starting

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]
Building docker images

Build the whole project as described in build section and then run the following command:

docker-compose build
Starting docker-compose

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

Load testing

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

Further possible improvements

Strict improvements:
  • 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
Optional improvements:
  • 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

About

url-shortening solution with IMDG

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published