DSA & Algorithms
Part 15 of 16 · DSA Advanced & Company FavoritesCoding-round System Design Lite - rate limiter, URL shortener coding shapes
Coding-round shaped designs: rate limiter, URL shortener, tiny LFU/cache - not full HLD.
- 1Gist
- 2Maps
- 3Q&A
- 4Sandbox
Voice readout needs Web Speech Synthesis in this browser.
The coding prompt is a small service class
Prefer
API, in-memory state, one algorithm
Token bucket, base62 ids, and a timestamp queue are the usual shapes.
- Say the class methods first.
- Bound memory on purpose.
- This is not a multi-region HLD.
Alternative
Draw boxes for five microservices
The interviewer asked you to code the limiter.
- You never name the data structure.
- You leak every timestamp.
- You skip the duplicate-id case.
Code the class, not the company
Methods, fields, complexity.
- 1
Name the methods
hit, getHits, encode, allow. - 2
Pick the structure
Queue of timestamps, map of ids, or a bucket. - 3
Bound the memory
Drop stamps outside the window.
Overview
Coding-round shaped designs: rate limiter, URL shortener, tiny LFU/cache - not full HLD.
When companies ask this
Recognition cues: implement rate limiter class; encode/decode tiny URL; design hit counter; logger rate limiter - not full "design Twitter HLD".
Scope: Single-process coding shapes with clean APIs - not the full system-design cluster.
Mental model
Decisions
- 1
1. Name the class methods
- next2. In-memory fields
- 2
2. In-memory fields
- next3. Which shape?
- ?
3. Which shape?
- rate4. Token bucket or window
- id5. Base62 map or hit queue
- 4
4. Token bucket or window
- 5
5. Base62 map or hit queue
Lesson map
Coding-round System Design Lite - rate limiter, URL shortener coding shapes
Coding-round shaped designs: rate limiter, URL shortener, tiny LFU/cache - not full HLD.
Architecture. Architecture
Select a node to see why it exists, or an edge to see the protocol, direction, effect, and consequence.
Mermaid export
flowchart TB api["1. Name the class methods"] state["2. In-memory fields"] alg["3. Which shape?"] rl["4. Token bucket or window"] api -->|1. Name the class methods| state state -->|2. In-memory fields| alg alg -->|rate| rl
Core template (Python)
Press Run. Snippets must be self-contained — no network, files, or native modules.
Core template (TypeScript)
Press Run. Snippets must be self-contained — no network, files, or native modules.
Complexity + pitfalls
- Token bucket O(1). The hit counter advances a head index and compacts the array so memory stays bounded.
- Pitfalls: wall vs monotonic clock; base62 bugs; unbounded logger map.
Interviewer traps
LeetCode drill (real problems)
- Logger Rate Limiter
- Design Hit Counter
- Encode and Decode TinyURL
- Design Underground System
- Moving Average from Data Stream
- Design a Leaderboard
- Time Based Key-Value Store
- Design Browser History
- Design Parking System
YouTube
Interview Q&A
Token bucket vs leaky?
Answer
Token allows bursts; leaky smooths output.
Sliding window log?
Answer
Store timestamps; drop older than window.
TinyURL id?
Answer
Counter + base62; or hash with collision check.
Hit counter 5 min?
Answer
Deque prune ≤ now-300.
Distributed?
Answer
Only if interviewer expands (Redis etc.).
Related?
Answer
design-datastructures, concurrency.
Logger 10s?
Answer
Map message -> last print time.
Not full HLD?
Answer
Coding APIs only - no multi-DC capacity planning here.