Loading...
. Create Short URL
/api/v1/urls{
"long_url": "[https://example.com/very-long-path](https://example.com/very-long-path)",
"custom_alias": "custom-alias",
"expire_at": "2026-12-31T23:59:59Z"
}
201 Created{
"short_url": "[https://sho.rt/custom-alias](https://sho.rt/custom-alias)",
"hash": "custom-alias"
}
2. Get URL Stats
/api/v1/urls/{alias}/stats200 OK{
"total_clicks": 1502,
"breakdown": { "US": 500, "VN": 200 }
}
1. Redirect
/{alias}302 Found (Temporary Redirect)Location: {long_url}ShortURL -> LongURL. Checks here first for redirection.To ensure short links are unique and collision-free, we cannot rely on simple database auto-increment (predictable and hard to shard).
Chosen Approach: Base62 Conversion + Distributed ID Generator
[A-Z, a-z, 0-9].10000000001).10000000001 -> sT4nZ).Redirection speed is critical. We must not write to the analytics database synchronously during the redirect request.
{short_id, timestamp, user_agent, ip} to a Message Queue (Kafka).We can use a NoSQL database (like DynamoDB or Cassandra) for the URL mappings due to massive scale and simple Key-Value structure.
Table: URL_Mapping
hash (String) - The short aliasoriginal_url (String)created_at (Timestamp)expiration_date (Timestamp)user_id (String)Table: User (Relational DB is fine here)
user_id (PK)emailapi_keyplan_typehash (short alias) to determine which database shard stores the data.