Let's say we are designing this for a small team of 10 devs. Given that they are developers, each might generate up to 10000 requests per day. that's 100,000 requests per day, or about 1 per second on average. However, I'd expect requests to come in bursts throughout the day. Let's say we need to handle the 10000 a single dev will request, per second.
in pseudocode:
string shorten(string input_url)
the above api takes in a url and returns the shortened version.
sqlite database. each table entry will have the following fields:
needs to be indexable by original url, because that's how we will check if a certain link has been shortened already.
The client sends a request to server that includes the original url. The server checks if this link has been shortened by querying the database. Return shortened link if it has, if not, generate a new short url, write to database, and return to user.
I'd like to talk about server application implementation. When a request for an unseen before url is received, it's important that it generates the short url, write to database, THEN returns to user. This is to prevent the unlikely event of another user requesting the same url at the same time, and the two users end up getting two different shortened urls.
Need database that supports read and write locks. When writing a new entry, cannot read.
Local caching for commonly requested urls per client