4. Linkshortener with akka #1 - concept

2021-07-31 linkshortener concept networking api

Motivation

All links I have added to tweets are quite long. It would be nice to short them a little. Moreover, Linkshortener is great service to keep information about links clicks. The last motivation is practice of writing application with Akka. Akka is powerful library, certainly too powerful for this simple case. Linkshortener is also service with good know interface, so it is good case to practice.

Requirements

Linkshortener service will consist of two endpoints. First must be private and will be used to create new short link from the original link. Second must be public and will be used to redirect to the original link. All calls of the second endpoint correspond to link clicks. Click events should be persisted for statistical purposes.

Deployment concept

The following picture shows how Linkshortener service will be deployed to meet all described requirements:

Linkshortener deployment concept

Linkshortener will run in docker container, so all Linkshortener’s endpoints will be accessible in docker network (via 172.27.x.x address or via container name). First endpoint (to create short links) need to be private. Because of that I will expose Linkshortener port at VPN interface (10.27.x.x). Service client needs to connect to VPN to access private endpoint. Returned short links will look like this: https://stepniewski.tech/f/hash.

Public endpoint will be accessible through reverse proxy. Clients will request GET endpoint with url looks like this: https://stepniewski.tech/f/hash. This endpoint in first order will be handled by reverse proxy which will proxy this request directly to docker container (to url looking like this: http://linkshortener/short-links/hash, linkshortener is a docker container name). Thanks to that clients will have access to public endpoint while other endpoints still will be private.

Service API

Private endpoint to create short link:

POST {{private-address}}/api/v1/short-links
Content-Type: application/json

{
  "originalLink": "https://stepniewski.tech/blog/post/3-know-java-time-better/"
}
200 OK

{
    shortLinkId: Sou9Choh
    shortLink: http://stepniewski.tech/f/Sou9Choh
}

Public endpoint to redirect to the original link:

GET {{public-host}}/api/v1/short-links/Sou9Choh
301 Moved Permanently
Location: https://stepniewski.tech/blog/post/3-know-java-time-better/

In this post I described concept of Linkshortener service. In the next post I will describe Linkshortener service implementation.