Estimate the scale of the system you are going to design...
Define what APIs are expected from the system...
only two apis for now
Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...
we are going to use nosql database for this, as our main goal is availability over consistency, also we dont require the complex quries so sql has no major advantage here.
schema:
{
uniqueId: string, (primary key)
shortUrl: string,
longUrl: string,
ttl: timestamp
}
the client request first goes to the dns, then it goes to the load balancer, it then goes to the server, which maintains a cache, and a database as the source of truth.
For the write flow: for the write we will use write around cache strategy, firstly the request goes to the web server to generate the short url, the server will generate the short url and then puts into the db.
For read flow: we will use read through strategy, the web will ask for the long url, the request will go to the cache, it will check in the cache, if not found, it will check in the db and then populate the cache and return the response.
Webserver: the webserver will have just two api to support,
we can use any standard web server, and can later scale it as per the load, also the webserver uses the cache only in read, the writes are made directly to the db.
Cache: we will use write aside for the writes and we will use read through for the reads, we will set 15 minutes as the cache expiry limit. Also we will use LFU cache eviction policy.