From The Challenges - URL Shortener
Exploring five software engineering lessons we can learn from the solutions I've seen.
Hi this is John with this week’s Coding Challenge.
🙏 Thank you for being one of the 74,065 software developers who have subscribed, I’m honoured to have you as a reader. 🎉
If there is a Coding Challenge you’d like to see, please let me know by replying to this email📧
Welcome To Coding Challenges - From The Challenges!
In this Coding Challenges “from the challenges” newsletter I’m sharing some of the common mistakes I see software engineers make when tackling the Coding Challenges.
I’m sharing both the mistakes people make and some thoughts on how you can you avoid making the same mistakes when taking on the coding challenges or when writing software professionally. Sometimes we have to make mistakes to learn from them, somethings we can learn from other people’s mistakes, then make our own new ones! 😀
Recapping The URL Shortener Coding Challenge
In the build your own URL Shortener coding challenge the goal was to write your own URL shortening service. Think bit.ly or tinyurl.com.
Basically it’s a service that lets a client submit a long URL which is then shortened to make it easier to use.
New Year Sale Now On. Finishes January 6th!
During the New Year sale you can get 30% off all Coding Challenges courses for paid subscribers to Coding Challenges. Check out the paid subscriber benefits page for the coupon code!
If you’re not a paid subscriber you can get 50% off a 12 month subscription as part of the New Year sale too! CLICK HERE to claim it!
Or if you’re not a paid subscriber you can still get 15% off all the courses using the code NEWYEAR2025 at the checkout:
Build Your Own Redis Server (Go Edition) PRESALE - To be released 13th Jan 2025
Five Common Mistakes Software Engineers Make Solving the URL Shortener Coding Challenge
I’ve pulled together this list of common mistakes from the submissions I’ve been sent privately and the many shared in the Coding Challenges Shared Solutions GitHub Repo.
Mistake 1 - Sanitise User Input
Many of the solutions did not sanitise the user input. They simply took whatever data was sent to the API and inserted it into the database. You should never trust user provided data, even if it is via an API. Validate and sanitise all input data to protect against both malicious and accidental abuse.
Mistake 2 - Not Handling Short Key Collisions
A couple of solutions generated random short keys using a small set of input characters. Had the solutions been real and been deployed they’d very quickly end up with collisions.
This was also often accompanied by the mistake of not presenting the users with a useful error. Failing to provide a useful error leaves the user with no idea what to do next / if the issue was their input or something, possibly temporary, on the server end.
The issue of collisions could have been handled by using a hashing function - and if you’re not familiar with them, this is a great time to learn. You can learn more about hash functions in the coding challenges that have you build your own password cracker and build your own bloom filter.
Mistake 3 - Copying-And-Pasting Code Without Understanding
I believe these Coding Challenges are a great way to learn a new programming language. It’s the approach I’ve used for over 30 years to learn Basic, C, C++, Perl, Python, PHP, Java, C#, Rust and Go. In fact I started writing and sharing the Coding Challenges in 2023 when I was using them to learn Rust and in 2024 I started using them to learn Go.
But to really learn when doing them you need to write the code to solve them yourself. If you’ve just copied-and-pasted a solution from Stack Overflow or an AI system without understanding what you’ve copied, you won’t learn and you will limit your progress. Unfortunately I saw evidence of copy-pasting in a few solutions and yes, it solved the problem, but it cheated the person doing it out of the learning opportunity.
So, by all means copy-and-paste, but, then take the time to read, understand and modify the code to your needs. You’ll maximise the learning you get from doing the work!
Mistake 4 - Env File In The Repo
A few repo’s that were shared with me contained .env
files which contained passwords and other configuration information. That’s a security violation, try to avoid doing it, even if they contain dummy entries. Once they’re in a repo, it’s very easy for someone to accidentally put live credentials in there.
Mistake 5 - A Bare Repo Containing Just Code
Several solutions I was sent were rather bare. No README, no details of the dependencies that are needed, nothing, just a couple of source code files.
In contrast check out Mohit Jain’s solution. Mohit provides a detailed README and has deployed his solution so you can see it live (link in the about section of his Github repo). If you’re looking for work, a deployed and well documented solution to one of the Coding Challenges is more impressive demonstration of your skills than just a couple of files of source code!
Mohit wasn’t alone, many of the solutions this time around did provide a good README and instructions on how to develop locally and deploy the solution. That was awesome to see!
Bonus - Building It With AI
Mike Thornton built the URL Shortener with AI and wrote a series about it. You can find his solution on Github here and the series on Substack here. It’s a fascinating look at what it really takes to use AI to develop a solution.
Request for Feedback
I’m writing these coding challenges and this new from the challenges series to help you develop your skills as a software engineer based on how I’ve approached my own personal learning and development.
What works for me, might not be the best way for you - so if you have suggestions for how I can make these challenges more useful to you and others, please get in touch and let me know. All feedback greatly appreciated.
You can reach me on Bluesky, Twitter, LinkedIn or through SubStack
Thanks and happy coding!
John
P.S. If You Enjoy Coding Challenges Here Are Four Ways You Can Help Support It
Refer a friend or colleague to the newsletter. 🙏
Sign up for a paid subscription - think of it as buying me a coffee ☕️ twice a month, with the bonus that you also get 20% off any of my courses.
Buy one of my courses that walk you through a Coding Challenge.
Subscribe to the Coding Challenges YouTube channel!