URL shortener
0-day streakReview

Your progress

Level 1

0 XP100 XP to level 2
0day streak
0best streak
0topics started
0cards reviewed
    Review cards

    Progress is stored only in this browser. No account is required.

    Layer 3 · Go deeper · 11 min

    Go deeper

    Size it, build it, then make the calls an interviewer will push you on.

    Back of the envelope

    Size it up

    Tap through each step of the arithmetic.

    How many redirects a second at peak?

      How many characters does a code need?

        Should paste text live in the links database?

          Build-up · 5 steps

          Build the high-level design

          One functional requirement at a time, ending with a design that works in one region at moderate traffic.

          Step 1 of 5

          Shorten a long URL

          The Write API accepts only http or https, under 2,048 characters, never pointing back at sho.rt. It takes the next code and stores it with a conditional put, so it never silently replaces a link.

          6 interview moments

          You’re the candidate

          The interviewer pushes on the hard parts. Pick an approach and see how it holds up.

          1. Deep dive 1 of 6

            Interviewer

            “You need seven-character codes for 110 billion links, never duplicated and hard to guess. How do you mint them?”

            Your move. Pick an approach:

          2. Deep dive 2 of 6

            Interviewer

            “Someone clicks a short link. Do you answer with a 301 or a 302, and with what caching?”

            Your move. Pick an approach:

          3. Deep dive 3 of 6

            Interviewer

            “Peak is 140k redirects a second, and in an IPL final one sponsor’s QR code alone draws 17k a second. How do you serve them?”

            Your move. Pick an approach:

          4. Deep dive 4 of 6

            Interviewer

            “Two shopkeepers press “create” for sho.rt/diwali-sale at the same moment. How do you make sure exactly one wins?”

            Your move. Pick an approach:

          5. Deep dive 5 of 6

            Interviewer

            “A paste expires at 11:00. How do you make sure nobody reads it at 11:01, and that its storage comes back?”

            Your move. Pick an approach:

          6. Deep dive 6 of 6

            Interviewer

            “Owners want opens by day and country, and the sponsor link gets 17k clicks a second. How do you count without slowing redirects?”

            Your move. Pick an approach:

          Build-up · 7 steps

          Follow one click through it

          Reads flow through the edge and three cache layers; writes go through one API that mints codes from reserved blocks; counting happens off to the side, from logs.

          Step 1 of 7

          Edge

          sho.rt resolves to the nearest CDN location. It answers cached 302s for 60 seconds and paste pages until they expire, without touching the origin: about 43% of peak redirects.