nnovoice / tinyurl

Creating my implementation of a tinyurl
MIT License
1 stars 0 forks source link

Short code generator starts from the beginning after application restart #2

Open nnovoice opened 4 years ago

nnovoice commented 4 years ago

Short code generator is created as an Iterator that starts from aaaaaaaa and goes on. It does not remember where it left off on an application restart. Got to fix this.

raoprasad-zz commented 4 years ago

Potential approaches below. Let's review and identify one:

  1. Add an entry for the next indices and length of sequence in DB to restore on restart.
  2. Add a column for time ticks(elapsed since epoc) in the URL table in postgre. On restart, obtain the latest URL inserted based on the time ticks. Identify current indices based on the short url in the record. generate next url based on current short url.

Edit: Looking at "https://github.com/nnovoice/tinyurl/issues/3", it appears neither of the options will work. Instead we completely randomize the sequence and check against the URL repository to check if the sequence has been consumed.

nnovoice commented 4 years ago

We need to find a way to return sequences in a random order. How about pre-generating say 10 million sequences and return them randomly? the next 10 million can be generated when needed and randomize them. we could potentially do this in a separate thread pool. Need a simple mechanism.