ash-jc-allen / short-url

A Laravel package for creating shortened URLs for your web apps.
MIT License
1.25k stars 158 forks source link

Increase Short URL key entropy to decrease likelihood of key collisions #291

Open stevebauman opened 1 month ago

stevebauman commented 1 month ago

This is related to PR https://github.com/ash-jc-allen/short-url/pull/290, but is a slimmer approach to decreasing the likelihood of collisions. This means that two or more queued jobs attempting to create Short URL's at the same time will have to execute at the same microsecond to generate the same short URL key (very unlikely).

ash-jc-allen commented 1 month ago

Hey @stevebauman! Sorry for not checking this one out yet. Last week was crazy busy! But I'm hoping to check it out this week 😄

stevebauman commented 1 month ago

Hey man no worries at all! In no rush as I was already able to make this change in production (appreciate you making this customizable!), take your time 🙏

ash-jc-allen commented 1 month ago

Hey @stevebauman! I've been looking at this and I can't make my mind up on something, so I'm hoping you'll be able to advise me. Do you think this would be better as the default generator? Or do you think this should be added as a separate generator class (that someone could then just set via the config)?

I feel like the existing generator logic has worked pretty well for a large majority of applications for the past few years. So I don't know if it should be left as the default. Or, maybe your new logic should become the default if it's not going to affect any existing apps? In my mind, if a dev using the package doesn't notice any difference in the keys being generated, that's perfect for me! I'm just scared of disrupting any existing apps haha 😄

stevebauman commented 1 month ago

Hey @ash-jc-allen !

Totally understandable. I think adding it as a separate generator as you mentioned may be the better choice to avoid any possible disruption to existing production applications.

Maybe we should add a note to the readme to possibly enable this generator in situations of creating short URLs in queued jobs to prevent the likelihood of collisions?