I will start by creating a RESTful API that will facilitate two main functions: a POST request to create a new shortened URL and a GET request to retrieve the original URL. When a POST request is made, the service will generate a unique hash or ID, save this ID along with the original URL in a database, and then return the new shortened URL, which is constructed by combining a base URL with the generated ID. For the database setup, a key-value store like Redis could be an effective option; we can use the ID as the key and the original URL as the value. To enable scaling of the service, we might consider sharding the data across multiple databases. Based on the hash function selected for ID generation, we could evenly distribute the data among the shards. For mapping URLs, one approach could involve generating a random unique ID for each new URL and linking it to the original URL. However, this method could potentially make the service vulnerable to phishing attacks, as it may allow for the enumeration of all shortened URLs. To mitigate this risk, instead of using entirely random IDs, we could opt for generating URLs in a sequential manner. While this approach decreases the likelihood of URL guessing, it doesn't eliminate the possibility entirely. Therefore, an additional security measure could involve checking URLs against a blacklist of known malicious sites prior to the shortening process.