Generate 7-char Base62 codes via counter ranges (ZooKeeper/Redis) or truncated hash + collision check (avoid sequential ID leakage if security matters). Store in Postgres/KV, cache hot short_code -> long_url in Redis (302 if analytics/edits matter, 301 for browser caching), and log clicks asynchronously via queue/batch writes so redirects stay <20ms.
Follow-up Interview Question · Why would you choose 302 Found over 301 Moved Permanently if you need accurate click analytics?