We will need two endpoints:
The client sends us a POST request with a long URL. Our service uses a hashing operation to create a unique short URL for the given long URL. We store both URLs in a database.
When the client sends us a short URL, we check the database and send the corresponding long URL if the short URL is valid. Otherwise, we send an error response.
For the hashing service, we need to be able to provide unique URLs for incoming long URLs. We can use numbers, characters and special symbols like @, ! etc.
This gives us close to 60 characters of vocabulary. We can create unique hashes of length 20, giving us 20 ^ 60 unique short URLs, which is more than enough size for the current internet size.
The biggest problem is storing these URLs and retrieving them from the DB. Searching over all URLs is impossible. We can use PostgreSQL to store the URLs and cache popular URLs in Redis to improve performance. We can research sharding strategies to reduce the search space per query.