Shorten URL -> Send user to original URL
Available -> if shortened URL is not working, no point of having it
Reliable -> if shortened URL doesnt bring to correct website, no point of having it
Read to write ration -> 100:1
30,000 per day, 1000 writes per day
170 bytes per row -> 17000 bytes per day -> 17 mb per day
Public Endpoints:
/POST:
Receive original URL in request, and then shorten with MD5 and then 64 base encode it and store in DB
/GET:
Receive shortened URL and link to long/original URL
SQL because we have a strong relationship for all columns
MySQL
URL table:
original -> VARCHAR(150) -> 151 bytes
shortened -> VARCHAR(6) -> 7 bytes
ID -> BIGINT -> 8 bytes
Flow:
Because it is read heavy, we could use read replicas to take pressure off the DBs
Master-Slave replicas
Flow:
Receive long URL, MD5 hash it, base-64 encode it, store in DB using auto increment as ID
Mysql for strong relational rows
Traffic spikes during peak hours, too many reads
To avoid having downtime, have multiple servers and replicas
use MFU cache to cache urls that are used a lot -> redis cache
updates depending on user opinions