Because we have two main functionalities for this design, we will have two main APIs:
Here is the database design for the mapping data:
We might want to add user_id, to indicate the created_by. but I think this is out of scope for our design, as we do not care much about who created the shortURL and/or who has access to the URL.
Since we have two main components, we will use two micro-services: creation service; redirection service.
An API gateway is placed between the user and the service to handle rate-limiting, gatekeeping on malicious activities. Authorization/authentication layer can also be placed here, but I think it is out of scope for this design.
data layer to store the url mapping, caches and CDN is used to improve performance of the system.
We need a sequence generator to generate the alias in the creation service.
Each micro service - creation service and redirection service can have their own load balancer and computing resources. Because we have a higher emphasis on the redirection workflow, we want to put more resource on the redirection service.
Let's consider the failure scenarios.
Say the service scales really fast, the DAU increases 5x, creation requests increases, then perhaps 8 character 62 base string alias can be exhausted. We can update our global sequence generator to start create longer string alias to mitigate this.
Because we have expiration time for some of the URL, we want to have a system where it periodically checks the database and clean up any expired URL. This also frees up some aliases to be reused.
Security - A component to avoid URL abuse will also help improve the service.
Customizable alias.