Assuptions:
Storage:
5 * 12 * 100M * 500B = 6000M * 500B = 3TB
QPS:
Network:
Cache:
header JWT | session token
body
{
original_url,
custom_alias,
expiration_date
}
header JWT | session token
301 redirect
302 redirect
I have 2 scenarios:
For the first case:
The Client sends request to Load Balancer(LB) and LB routes it to one of Application server nodes(AS). AS tries to find it in cache or DB and if it can't do it then call Short URL Generator service, which returns a valid short URL to AS and AS saves mapping of Short-Long URLs to DB and return it to the client.
For the second case:
If AS doesn't find short URL in cache but find it in DB then AS saves url mapping record to the cache.
For Storage I would select a NoSQL DB with Key-Value storage like DynamoDB, MongoDB, or Cassandra because it is better in horizontal scaling.
For Cache I would select Redis
Entity:
ShortURL -> (LongURL, UserId(Optional), Expiry)
| Column | Type | Notes |
| short_code | String (HASH key) | e.g., "abc123" |
| long_url | String | Original URL |
| user_id | String (optional) | Owner |
| created_at | Timestamp | |
| expires_at | Timestamp (TTL) | Auto-delete |
Short URL Generator principle:
Distributed Unique ID Genarator + Base 64
Generate Unique ID: 64 bits: 2^64-1. We can use SnowFlake algorithm by Twitter: 2^63-1.
And after that, apply Base64: 0-9,A-Z,a-z,+,/. Output example: Aa87BzE
Availability
If one of App servers is down then it is not a problem because we have additional App server nodes.
The same thing as with DB, because we will use multiple DB servers with partitions with replication as well.
Scalability
We can just add more servers as well for scaling purposes how for
Applications so for DB's and Cache's.
Readability
We transform our ID's to base 64 system, it is a human readable industry standard.
Latency
We have Cahe for Read heavy loading and NoSQL give us milliseconds guaranties in read operations.
Upredictability