TinyURL
What is TinyURL

Details
The four key building blocks required to design a system like TinyURL are: a) A database to store the mappings between long URLs and their corresponding short URLs. b) A sequencer to provide unique IDs that can be used for generating short URLs. c) A cache to store the most frequently accessed short URLs for quick retrieval. d) Rate limiters to prevent abuse of the system by limiting the number of requests a user can make in a given time frame. These components work together to ensure the system is efficient, scalable, and secure.

Requirements of TinyURL's Design

As a design choice, we don’t reuse the expired short URLs. Since we don’t reuse them, why do we need to delete them from our system?
Details
So far, we’ve kept the default expiration time to five years. If we relax that limitation and start saving the records forever, our datastore’s search index will grow without bound, and querying time from it can add noticeable latency.

Why is producing unpredictable short URLs mandatory for our system?
Details
The following two problems highlight the necessity of producing non-serial, unpredictable short URLs:
- Attackers can have access to the system-level information of the short URLs’ total count, giving them a defined range to plan out their attacks. This type of internal information shouldn’t be available outside the system.
- Our users might have used our service for generating short URLs for secret URLs. With the information above, the attackers can try to list all the short URLs, access them and gain insights about the associated long URLs, risking the secrecy of the private URLs. It will compromise the privacy of a user’s data, making our system less secure. Hence, randomly assigning unique IDs deprives the attackers of such system insights, which are needed for enumerating and compromising the user’s private data.

Design and Deployment of TinyURL

Why are NoSQL databases like Cassandra or Riak not good choices instead of MongoDB?
Details


How will we maintain a unique mapping if redirection requests can go to different data centers that are geographically apart? Does our design assume that our DB is consistent geographically?
Details

How will the data-center-specific caching handle an unseen redirection request?
Details
Since we’ve assumed the data-center-specific caching solution for our system, a case needs highlighting: handling unseen redirection requests by our system.
Scenario: The scenario entails receiving an unknown redirection request at a data center. Since the local cache wouldn’t have that entry, it would fetch that record from the globally consistent database and place this entry into the local cache for future use.
What is the probability of collision when we ask the short URL generator for a new short URL?
Details


How does our system avoid duplicate short URL generation?
Details

How do we ensure that two concurrent requests for a short URL do not overwrite?
Details


How does our system ensure that our data store will not be a bottleneck?
Details


Details
For your TinyURL service facing a massive influx of traffic and database slowdowns, here are the solutions:
Short-term Solutions:
- Caching: Implement a caching layer to reduce the read load on the database.
- Database Optimization/Indexing: Optimize the database by indexing the URLs/tables to speed up read/write operations.
- Load Balancing: Use a load balancer to distribute the traffic evenly across multiple servers.
- Vertical Scaling: Increase the capacity of the current server.
Long-term Solutions:
- Separating Read/Write: Implement separate databases or instances for read and write operations to reduce contention.
- Horizontal Scaling: Add more servers to handle increased traffic.
- Database Partitioning/Sharding: Split the database into smaller parts called shards, placed on different servers to improve performance.
- Use a CDN: Implement a Content Delivery Network to cache URLs at various geographical locations.
- Microservices Architecture: Break down the application into smaller, independent services for individual scaling based on needs. These strategies will help manage the load effectively and ensure scalability.
Upon successful allocation of a custom short URL, how does the system modify its records?

Encoder for TinyURL

Evaluation of TinyURL's Design

