CodePark/ questions / Classic design problems
START PRACTICINGPRACTICE
Backend question · System design & architecture › Classic design problems

Your URL shortener must count every click for analytics. Which redirect status should it return, and why?

302, because browsers do not cache it by default, so every click reaches the service

Return 302. A 302 Found (or 307) is a temporary redirect, and browsers do not cache it by default. So every click reaches the service and can be counted. The cost is more traffic.

A
301 Moved Permanently can be cached by browsers. Repeat clicks then go straight to the target, and the shortener never sees them. That is why "301, because browsers never cache redirects" is wrong: browsers do cache 301. And "301, because permanent redirects are faster for every request" misses the point, because the shortener would lose the clicks it must count.