System Design Notes
1 min readMay 17, 2023
URL Shortner
Functional Requirements :
- Create Short URL for Long URL
- Retrieve Long URL from Short URL
Non-functional Requirements:
- Traffic : Read Calls -> ~500 TPS, Write Calls -> 100 TPS
- Data : short_url,long_url,created_at,expiry_at -> ~ 2KB per transaction
Storage :
- For a day : 24 * 60 * 3600 * 500 = ~2.5 M TPD
- For a year : 365 * 2.5 = ~912.5 M TPY
- Total Data = 1.8 TB in a year
- For 10 years -> 18 TB storage capacity
Choose Database : We need high availability and low latency, we can go with NoSQL .i.e MongoDB,Cassandra
How to generate unique short url ?
we need to generate unique id for distributed system. We can go with Token generator or Zookeeper, which will provide range to each application server.
Length of Unique Id and Hash Function ?
Usually, we take 7 chars unique id and we can use Base64 (0–9,a-z,A-Z) or MD5 Hash function to encode.
Collision case ?
It might be possible we can have same unique id for different urls, it is collision. that the reason we are using Zookeeper.