Url creation path:
Url retrieval path:
There are two separated paths:
Firstly, we access the CDN to reach our administration frontend.
When we create a shortened url, the Frontend reaches first Api-gateway. This api-gateway handles authentication, authorization and rate-limiting. After successful verification of requiest it is routed to Administration service.
The Administration service is stateless, so it can be scaled. Firstly it needs to get new identifier from Hash Generator.
The Identifier generator generates random UUIDs and makes sure, that they were not previously used.
After hash is generated, the original url is stored in read-write DB (may be relational Database).
Database assures that the identifiers are unique (e.g. by unique constraint in relational Database).
There is only one instance of Identifier database.
Using Change-Data-Capture, the entry is propagated to Read Database. This Database must be replicable and must use shards. Target shard is selected using consistent hashing basing on shortened-url.
Coming back to url creation - after persisting an entry in Read-write DB, we need to make sure, that the result will be available for client, so we need to access Retrieval service to verify it. We can use short pooling for reaching Retrieval service with retry in case of failure.
After confirming the result is available, we can respond with the result (shortened url) to client.
URL retrieval:
When user request shortened url, request is routed to LoadBalancer which executes rate-limitting to avoid flooding our service. The rate-limiter should reject excessing coming requests.
LoadBalancer firstly checks if searched value is present in cache.
If not LoadBalacer routes request to one of multiple RetrievalService. The RetrievalService using consistent hashing queries one of database shards to obtain the result.
The cache stores results during return to LoadBalancer. There should be a TTL policy.
The administration servlice could also disable shortened url. Then the information should remove entry from
cache and from read key-value store.