Skip to content

Design a URL Shortener, stage 4 of 9: decide

Choose the redirect status: 301 or 302

The redirect response is what every click receives. Its status code decides who may cache it and for how long, and that affects analytics, edits and takedowns.

System so far· 5 parts
123CLIENTClickersSERVICERedirect serviceDATABASEPostgresSERVICELinks APICLIENTCustomerdashboard

Select a component to see what it is responsible for and which state it owns.

  1. 1Redirect service → Postgres: Look up code
  2. 2Customer dashboard → Links API: Create, edit, disable
  3. 3Links API → Postgres: Insert with unique code

What you need to know

0 of 2 checks done
  1. A redirect is an HTTP response with a status code and a Location header. The browser reads the header and requests the new URL. The status code also tells caches (the browser's own cache and any CDN in between) whether they may reuse this answer next time.

    StatusMeaningCaching by default
    301 Moved PermanentlyThis URL will always go thereBrowsers may keep it for a very long time and stop asking you
    302 FoundGo there for nowNot reused unless Cache-Control allows it
    308 / 307Like 301 / 302, but a POST stays a POSTSame as 301 / 302
  2. Check

    A link was served as a 301. The customer then changes its destination. What happens to people who already clicked it once?