Requirements
Functional Requirements:
- Create a short URL for a given long URL.
- Redrict to the long URL associated with a given short URL.
Non-Functional Requirements:
- The redirection service should have low latency, around ~100ms.
- The url generation service can take relatively more time. 1 to 3 seconds
- The system should have high availability, 4 nines
- The mapping of urls must persist even after a system restart.
API Design
- url creation service api: /<user>/create_url
- url redirection service api: /<url_code>
High-Level Design
- A read cache is used between the data base and the url redirection service to reduce the latency of redirection.
- The client sends request to a server and the server makes api calls to the service.
- Sharding can be used to horizontally scale the database.
- TTL is used so that a url will stop woring after the set time.(automatic url management)
- Consistent Hasing must be use to scale the database.
- An additional secondary storage can be used for data persistance.
- A load balancer can be user for read service if reads become a bottle neck.
Detailed Component Design
- 8 bytes for short code, 100 byte url, 8 bytes TTL, 8 bytes user. Total = 124 bytes = ~ 128 bytes
- If 10 urls / sec are generated, 1280 bytes of data is generated per second.
- If we want it to run for a year: Storage = 365 * 24 * 60 * 60 * 1280 = ~ 40TB is required
- Including backup total storage is 80TB. where the primary storage should have high read speed.