LESSON 03 · Read behavior

Choose redirect and expiry semantics

HTTP status codes determine who sees future clicks and how failures appear.

SYSTEM VIEW

The system

Diagram view
Status—
Clicks seen—

Watch one visitor open a link five times under a 301 and a 302, then see what expiry changes.

  1. A visitor opens x7Kp2Qa, the first of five clicks this week. The Redirect service looks up the saved destination and answers 301 with a Location header pointing to it. The browser follows it to the Destination site.

    What changed

    • GET /x7Kp2Qa
    • 301 · Location: the long URL
    • Click 1 of 5 seen
  2. A 301 is a permanent move, and HTTP lets browsers cache it by default. With no cache headers, this browser keeps it: clicks 2 to 5 go straight to the Destination site, and analytics records one visit of five.

    301
    cacheable by default

    What changed

    • Browser keeps the 301
    • Clicks 2–5 skip the service
  3. The owner repoints x7Kp2Qa to a new page in the Mapping database. The browser still holds the 301, so it never asks and keeps going to the old page. A 301 fits only a link that never changes and whose clicks nobody counts.

    What changed

    • x7Kp2Qa → new page
    • Browser still goes to the old page
  4. Replay the week with a 302, a temporary move that isn’t cached unless the response says so. All five clicks reach the Redirect service: five chances to log a visit and send it to the new page, though that traffic stays on your servers.

    302
    not cached by default
    Cache-Control
    overrides either
    Exact count
    no: bots, prefetch

    What changed

    • 301 → 302
    • Every click reaches the service
  5. A CDN edge in front of the service can cache a 301 or a 302. Here it answers four of the five clicks from its copy: the Redirect service carries less load, but those clicks show up only in the CDN’s logs.

    What changed

    • CDN edge
    • 4 of 5 clicks answered at the edge
    • Click data in the CDN’s logs
  6. Without the CDN edge, the visitor opens Bv3Yd7n, a key that was never issued. The Mapping database has no row for it, so the Redirect service has nowhere to send the browser and answers 404 Not Found.

    What changed

    • CDN edge
    • GET /Bv3Yd7n
    • 404 Not Found
  7. An older link, p4Nz8Lc, has passed its expiry. The Redirect service reads its row, the Expiry check compares expires_at with now, and the answer is 410 Gone, never a redirect to the old destination.

    Unknown key
    404 Not Found
    Expired link
    410 Gone

    What changed

    • Expiry check
    • GET /p4Nz8Lc
    • 410 Gone, no redirect
  8. x7Kp2Qa expires in 10 minutes, and its 302 carries a max-age. Try 1 hour: the browser reuses the redirect for 50 minutes past expiry without asking. Try 5 minutes: the copy lapses first, so a later click asks again and gets 410 Gone.

    Link expires in
    10 min

    What changed

    • x7Kp2Qa expires in 10 min
    • max-age on the 302
    max-age

Space plays · ← → step · Home resets

THE IDEA

How it works

For a valid key, respond with a redirect and a Location header pointing to the saved destination. A 301 expresses a permanent move. HTTP treats it as cacheable by default, so browsers or intermediaries can reuse it and skip your service. A 302 expresses a temporary move and is not cached unless the response says so, which suits links whose clicks you count or whose destination may change. Cache-Control headers can override both defaults, and neither status guarantees an exact analytics count, because bots and prefetching also produce requests.

Follow one visitor who opens a link five times in a week. With a 301 and no cache headers, the browser may contact your service only on the first click: analytics records one visit, and if the owner repoints the link, that browser may keep going to the old page. With a 302, all five requests reach you, which gives five chances to log and update but keeps that traffic on your servers. A CDN such as CloudFront can cache either response, cutting load but moving click data into its logs. A 301 fits a link that will never change and whose clicks nobody counts.

Check expiry before redirecting. An unknown key can return 404; a known, deliberately expired link may return 410 Gone. Never redirect an expired link to an old destination, and keep cache lifetimes (often called TTL, time to live) shorter than the link’s remaining life: a one-hour max-age on a link expiring in ten minutes can outlast it by 50 minutes.

DECISION POINT

The product needs accurate per-click reporting and destinations can change. Which redirect is safer?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • 301 and 302 are product and caching decisions, not just performance switches.
  • TTL and error responses are part of the public link contract.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
ApplyQUESTION 01

A short link will be printed on 50,000 flyers, and the landing page may move. Which redirect setup fits?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.