Whiteboard ScaleURL ShortenerProblem Patterns
Problem Patterns

URL Shortener Design Patterns

Recurring patterns and approaches. Learn to recognize the pattern, understand the trade-offs, and apply the right solution.

01

Back-of-Envelope Estimation

Pattern

Calculate QPS, storage, bandwidth, or cache size from given traffic numbers.

How to recognize

The question asks you to estimate numbers: 'How much storage?', 'What QPS?', 'How many servers?'

Start with monthly active users or daily requests. Convert to per-second. Apply read:write ratio. Multiply by record size for storage. Use 80/20 rule for cache sizing.
02

API Design

Pattern

Define RESTful endpoints with request/response schemas.

How to recognize

The question asks 'Design the API' or 'What endpoints would you expose?'

List endpoints (POST create, GET redirect, DELETE remove). Define request bodies and response schemas. Consider rate limiting, authentication, and error codes.
03

Schema Design

Pattern

Choose tables, columns, indexes, and database type for the system.

How to recognize

The question asks about 'database schema', 'data model', or 'what tables would you use?'

Identify entities and relationships. Choose primary keys (short_code for O(1) lookups). Decide SQL vs NoSQL based on access patterns. Add indexes for query patterns.
04

Trade-off Analysis

Pattern

Compare two approaches and justify choosing one over the other.

How to recognize

The question presents options: 'Base62 vs MD5', '301 vs 302', 'SQL vs NoSQL'.

List pros and cons of each. Identify the deciding factor (usually simplicity, performance, or correctness). State your choice with reasoning. Mention when the other option would be better.
05

Scaling Bottleneck Identification

Pattern

Identify what breaks first as traffic grows, and how to fix it.

How to recognize

The question asks 'How would you scale?', 'What happens at 1M QPS?', or 'Where is the bottleneck?'

Walk through the request path. Identify the single-threaded or single-instance components. Propose horizontal scaling (stateless app servers), caching (Redis), and data partitioning (sharding).
06

Cache Strategy Selection

Pattern

Choose the right caching pattern and eviction policy for the access pattern.

How to recognize

The question involves caching: 'How would you cache?', 'What cache invalidation strategy?'

Identify read:write ratio (100:1 = cache-aside is ideal). Choose eviction policy (LRU for URL shortener). Size the cache (20% of URLs = 80% hit rate by Zipf's law). Handle cache invalidation on URL deletion.
07

Collision Handling

Pattern

Handle the case where two inputs map to the same output.

How to recognize

The question mentions 'What if two URLs get the same short code?', 'How do you handle collisions?'

With Base62 counter: no collisions possible (each ID is unique). With hashing: check DB before inserting, retry with salt on collision. With pre-generated keys: use a key generation service that guarantees uniqueness.
08

Monitoring and Alerting Design

Pattern

Define metrics, dashboards, and alerts for production health.

How to recognize

The question asks 'How would you monitor?', 'What metrics would you track?', 'How do you know if something is wrong?'

Track latency (p50, p95, p99), error rate, cache hit ratio, DB connection pool usage. Alert on latency spikes, error rate > 1%, cache hit ratio drops. Use async event streaming for click analytics.