educative.io

Detailed explanation is lacking

Link: Design and Deployment of TinyURL

Question: Upon successful allocation of a custom short URL, how does the system modify its records?

Please answer these question and try to answer the actual question with detailed explanation

When will the generated base 10 unique ID is moved to unused list ? and by which service / application?
When will the base 10 Unique ID is moved from unused to used list ? and by which service / application?
What if a base 10 unique ID of a custom short URL is yet to be generated by one of the counters ?
On every unique ID generation, should the service check if this is used / unused ? Doesn’t it increase latency ?

Hi Hitesh

  1. We use a Sequencer to generate. a batch of IDs and put them in the unused list for future allocations.
  2. The base 10 unique ID is moved from the unused to the used list at the time of URL allocation. This process is triggered by the service or application responsible for managing the allocation of custom short URLs. Once a URL is allocated, the associated unique ID is marked as used in the system’s records.
  3. If a base 10 unique ID for a custom short URL is yet to be generated by one of the counters, the system must ensure that the generated ID is unique and has not been used before. The generation process should account for the uniqueness requirement and avoid collisions with previously used IDs.
  4. To address latency concerns, the system has employed an optimized approach. Instead of checking the usage status of each unique ID at the time of generation, we generate a batch of IDs and use them till we need to generate more IDs. (By its intrinsic design, the sequencer ensures the uniqueness of generated IDs). This quick and simple explanation of the URL shortening workflow might help you clear a few things: we’re generating a batch of IDs and putting them in an unused list. Upon allocation, we move from the unused list to the used list. Since we’re explicitly keeping separate lists for used and unused lists, we do not need to check on each URL shortening. In the case of custom URL shortening, the requested short URL can be in one of the three states: i. Not generated, ii. Unused, or iii. Used. For i, we generate it. For ii, we allocate it. For iii, we deny the request. For regular URL shortening requests, we allocate one of the available unused IDs and update the status of that ID by moving it from the unused to the used list.

Thank you