Skip to main content

TinyURL

What is TinyURL​

img_583.png img_584.png img_585.png

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.

img_586.png

Requirements of TinyURL's Design​

img_587.png


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.


img_588.png


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.

img_589.png img_590.png img_591.png img_592.png img_593.png img_594.png img_595.png img_596.png

Design and Deployment of TinyURL​

img_597.png img_598.png img_599.png img_600.png


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

Details

img_601.png


img_602.png img_603.png


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

img_604.png


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

img_605.png


img_606.png


How does our system avoid duplicate short URL generation?

Details

img_607.png


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

Details

img_608.png


img_609.png


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

Details

img_610.png


img_611.png img_612.png img_613.png img_614.png img_615.png img_616.png img_617.png img_618.png img_619.png img_620.png img_621.png img_622.png img_623.png img_624.png img_625.png img_626.png img_627.png img_628.png img_629.png img_630.png img_631.png img_632.png img_633.png

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?

img_634.png


Encoder for TinyURL​

img_635.png img_636.png img_637.png img_638.png img_639.png img_640.png img_641.png img_642.png img_643.png img_644.png img_645.png

Evaluation of TinyURL's Design​

img_646.png img_647.png img_648.png img_649.png img_650.png img_651.png

img_652.png img_653.png img_654.png img_655.png