POST urlshortener.com/create
Request:
body: {
"link" : https://example.com
"custom": mylink
}
Response:
body: {
"link" : https://urlshortener.com/
}
Ex:
GET urlshortener.com/
Request:
https://urlshortener.com/ef92b778
https://urlshortener.com/customlink
Request comes through load balancer which gives us good scalability in situation whew we need to handle more load, so when we need to scale a server.
Application server is a server which gonna to handle traffic and save and get data from the database.
Redis will improve our database health, so if there are people who have multiple urls shortened, or there are organisation which use multiple urls we can take advantage of that
Prometheus is giving us metric on which we can act upon
Application Server contains 3 services that handle the core logic:
SHA-256 hash of the URL, take last 8 charactersepoch + salt, re-hash, retry until successful{short_hash → long_url} to the database301 Redirect immediately301 redirect responses at edge — handles viral links without hitting originPostgreSQL native hash partitioning distributes data across 10 partitions:
CREATE TABLE url_mappings ( short_hash TEXT PRIMARY KEY, long_url TEXT NOT NULL, created_at TIMESTAMP) PARTITION BY HASH (short_hash);
hash % 10 → picks the right partitionshort_hash has maximum cardinality and the only query is WHERE short_hash = ?Why hash partitioning works here: Every redirect query includes the short hash, so each lookup hits exactly one partition — no scatter queries across all shards.