All jobs / DevOps / SRE / cloud
DevOps / SRE / cloud interview question · 1–3 years
URL shortener: how do you generate the short code?
The strongest answer
Either hash the long URL and take the first characters, handling collisions by retry, or hand out pre-generated unique codes from a counter or key service; say which, and why — a counter gives guaranteed uniqueness but predictable codes, a hash is stateless but needs collision checks
Why it works
Right. Name the scheme and its trade-off.
What a good answer covers
- Hash-and-truncate or pre-generated keys.
- Handle collisions explicitly.
- Predictability vs statelessness.
- Length from the target count.
Answers that fall short
- Close, but not the strongest: Use the database auto-increment id shown in base 62
Works, but codes are guessable and enumerable; say so. - Weak: Use a random string and hope it does not collide
Hope is not a collision strategy. - Red flag: Use the long URL's md5 in full
32 characters is not short.
Who gets asked this
- Backend developer
- Full-stack developer
- DevOps / SRE / cloud
- Data engineer
- Data science / ML / AI
- Engineering manager / tech lead
- Solutions / cloud architect
- AI engineer
More DevOps / SRE / cloud questions
- A service on a VM needs to read from a storage bucket. How does it get permission?
- Design a rate limiter: which algorithm and where does its state live?
- Active-passive versus active-active across regions — what does active-active cost you beyond money?
- A hot cache key expires and 5,000 requests miss at once. Design against it.
- How do you limit the blast radius of a failure in a system serving millions?
- Your DR runbook is a document. How do you make it real?
- A user has an allow policy for an action and their group has a deny for it. What happens?