DEV Community

Discussion on: URL shortener with Elixir and Phoenix

Collapse
rhamorim profile image
Roberto Amorim

I think checking is not necessary; you can just proceed with the insert, and, if any unique violation occurs, generate a new key and try inserting again, repeat until it works. That way you make sure it works while not incurring in any penalty on the "happy" path.

Thread Thread
hlappa profile image
Aleksi Holappa Author • Edited on

Yes! That would be even better! I’ll update the article at some point to handle it like this. 👍