client service is a RESTful service. We expose 2 API
Since we expect that the number of read operations will be higher that the number of write operations, these operations will be divided into 2 different services - Read service and Write Service. This approach gives us possibility to scale each service independently.
The client will talk to client service (or one of it replicas), which will identify the type of operation and send a request to the relevant server.
The read service talks to cache service to speed up the operation.
The cache service reads the data from the database when needed.
Read operation when requested url is not in the cache:
Check if cache contains this short url -> cache service does not contain this short url -> cache service reads the long url from the DB by short url -> cache service saves the obtained long url in the cache like the key-pair (short url -> long url) -> cache service returns the long url
Read operation when requested url is in the cache:
Check if cache contains this short url -> cache service not contains this short url -> cache service gets the long url from the cache by short url -> cache service returns the long url
we will use the following approach - Unique Short URLs for Each Request
Write service will generate a unique short url for each long url and it sends a write request to the database.
With this approach we allow to store multiple short urls which refer to one long url.