Bird
Raised Fist0
HLDsystem_design~20 mins

First design walkthrough (URL shortener) in HLD - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
URL Shortener Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Architecture
intermediate
2:00remaining
Identify the main components in a URL shortener system

Which of the following lists correctly identifies the essential components needed to build a scalable URL shortener?

AFile Storage, Image Processing, CDN, Video Streaming Service
BLoad Balancer, Cache, User Authentication, Payment Gateway
CAPI Gateway, Database, URL Redirect Service, Analytics Service
DWeb Server, Email Service, Notification Service, Logging Service
Attempts:
2 left
💡 Hint

Think about what components handle requests, store data, and redirect users.

❓ scaling
intermediate
2:00remaining
Scaling the database for high read traffic

In a URL shortener, most traffic is read-heavy (redirects). Which approach best improves read scalability?

AAdd read replicas to the database and use caching for redirects
BUse database sharding to split data by URL hash ranges
CStore all URLs in a single master database with no replicas
DUse a distributed file system to store URL mappings
Attempts:
2 left
💡 Hint

Consider how to reduce load on the main database for frequent reads.

❓ tradeoff
advanced
2:30remaining
Choosing the URL key generation strategy

Which URL key generation method balances uniqueness, short length, and ease of generation?

AGenerate a random 10-character alphanumeric string for each URL
BUse a sequential numeric ID converted to base62 encoding
CUse the full original URL as the key without shortening
DUse the current timestamp as the key
Attempts:
2 left
💡 Hint

Think about avoiding collisions and keeping keys short.

🧠 Conceptual
advanced
2:30remaining
Handling expired or deleted URLs

What is the best approach to handle URLs that have expired or been deleted in a URL shortener system?

ARedirect to the original URL regardless of expiration
BReturn a 404 error when the short URL is accessed
CAutomatically generate a new short URL for the expired one
DRedirect to a default homepage or informational page
Attempts:
2 left
💡 Hint

Consider user experience when a URL is no longer valid.

❓ estimation
expert
3:00remaining
Estimating storage needs for URL mappings

Estimate the approximate storage required to store 100 million URL mappings if each original URL averages 100 characters and each short URL key is 7 characters. Assume UTF-8 encoding (1 byte per character) and 20 bytes overhead per record for metadata.

AApproximately 12 GB
BApproximately 10 GB
CApproximately 15 GB
DApproximately 8 GB
Attempts:
2 left
💡 Hint

Calculate total bytes per record and multiply by 100 million.

Practice

(1/5)
1. What is the primary purpose of a URL shortener system?
easy
A. To generate random passwords for users
B. To increase the length of URLs for security
C. To store user passwords securely
D. To convert long URLs into short, easy-to-share links

Solution

  1. Step 1: Understand the function of a URL shortener

    A URL shortener takes a long URL and creates a shorter alias that redirects to the original URL.
  2. Step 2: Identify the correct purpose among options

    Only To convert long URLs into short, easy-to-share links describes this function correctly; others describe unrelated tasks.
  3. Final Answer:

    To convert long URLs into short, easy-to-share links -> Option D
  4. Quick Check:

    URL shortener purpose = convert long URLs to short [OK]
Hint: Focus on what URL shorteners do: shorten URLs [OK]
Common Mistakes:
  • Confusing URL shortening with security features
  • Thinking it stores passwords
  • Assuming it generates random data unrelated to URLs
2. Which component is essential for generating unique short codes in a URL shortener?
easy
A. Cache server
B. Load balancer
C. Short code generator
D. User authentication module

Solution

  1. Step 1: Identify the role of each component

    Short code generator creates unique short strings; load balancer distributes traffic; cache stores data temporarily; authentication manages users.
  2. Step 2: Match component to short code creation

    Only the short code generator is responsible for creating unique short URLs.
  3. Final Answer:

    Short code generator -> Option C
  4. Quick Check:

    Unique code creation = short code generator [OK]
Hint: Short codes come from the short code generator [OK]
Common Mistakes:
  • Confusing load balancer with code generation
  • Thinking cache generates codes
  • Assuming authentication creates short URLs
3. Given a URL shortener system, what happens when a user clicks a short URL http://short.ly/abc123?
medium
A. The system looks up abc123 in storage and redirects to the original long URL
B. The system generates a new short code for abc123
C. The system deletes the short URL from the database
D. The system asks the user to enter the long URL manually

Solution

  1. Step 1: Understand the redirection process

    When a short URL is accessed, the system finds the original URL mapped to the short code and redirects the user.
  2. Step 2: Evaluate each option

    The system looks up abc123 in storage and redirects to the original long URL correctly describes this lookup and redirect. Others describe incorrect or unrelated actions.
  3. Final Answer:

    The system looks up abc123 in storage and redirects to the original long URL -> Option A
  4. Quick Check:

    Click short URL = lookup and redirect [OK]
Hint: Clicking short URL triggers lookup and redirect [OK]
Common Mistakes:
  • Thinking system creates new codes on click
  • Assuming deletion happens on access
  • Believing user must input original URL manually
4. In a URL shortener design, which issue arises if the short code generator does not check for duplicates?
medium
A. The system runs out of storage space quickly
B. Multiple long URLs map to the same short code causing incorrect redirects
C. Users cannot create new accounts
D. The system slows down due to too many cache hits

Solution

  1. Step 1: Understand duplicate short code impact

    If duplicates exist, different long URLs share the same short code, causing wrong redirection.
  2. Step 2: Analyze options for relevance

    Multiple long URLs map to the same short code causing incorrect redirects correctly identifies this problem. Others describe unrelated issues.
  3. Final Answer:

    Multiple long URLs map to the same short code causing incorrect redirects -> Option B
  4. Quick Check:

    Duplicate codes cause wrong redirects [OK]
Hint: Duplicates cause wrong URL redirects [OK]
Common Mistakes:
  • Confusing storage issues with duplicate codes
  • Thinking duplicates affect user accounts
  • Assuming cache hits cause this problem
5. To scale a URL shortener for millions of users, which design choice improves performance and availability?
hard
A. Use distributed storage with caching and load balancing
B. Store all data on a single server to simplify access
C. Generate short codes sequentially without randomness
D. Disable caching to ensure fresh data every time

Solution

  1. Step 1: Identify scalability needs

    Millions of users require fast access, high availability, and fault tolerance.
  2. Step 2: Evaluate design choices

    Distributed storage spreads data load; caching speeds up lookups; load balancing distributes traffic. This combination supports scale.
  3. Step 3: Reject poor choices

    Single server limits scale; sequential codes risk collisions; disabling cache slows response.
  4. Final Answer:

    Use distributed storage with caching and load balancing -> Option A
  5. Quick Check:

    Scaling needs distributed storage + cache + load balancer [OK]
Hint: Scale with distributed storage, caching, and load balancing [OK]
Common Mistakes:
  • Choosing single server for large scale
  • Ignoring caching benefits
  • Using sequential codes risking collisions
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard