Which of the following lists correctly identifies the essential components needed to build a scalable URL shortener?
Think about what components handle requests, store data, and redirect users.
The core components include an API Gateway to receive requests, a Database to store mappings, a URL Redirect Service to handle redirection, and optionally an Analytics Service to track usage.
In a URL shortener, most traffic is read-heavy (redirects). Which approach best improves read scalability?
Consider how to reduce load on the main database for frequent reads.
Read replicas allow scaling read operations, and caching popular URLs reduces database hits, improving performance and scalability.
Which URL key generation method balances uniqueness, short length, and ease of generation?
Think about avoiding collisions and keeping keys short.
Sequential IDs encoded in base62 produce short, unique keys easily without collisions, unlike random strings which risk collisions and longer keys.
What is the best approach to handle URLs that have expired or been deleted in a URL shortener system?
Consider user experience when a URL is no longer valid.
Redirecting to a default page informs users the link is invalid and can provide options, better than a plain 404 error which can be confusing.
Estimate the approximate storage required to store 100 million URL mappings if each original URL averages 100 characters and each short URL key is 7 characters. Assume UTF-8 encoding (1 byte per character) and 20 bytes overhead per record for metadata.
Calculate total bytes per record and multiply by 100 million.
Each record: 100 bytes (original URL) + 7 bytes (short key) + 20 bytes (metadata) = 127 bytes. 127 bytes * 100 million = 12.7 billion bytes ≈ 12 GB.