Practice: URL shortener, chat, news feed, rate limiter
Run a 45-minute design interview end to end.
By Invicly Tech, , in Interview Preparation. About 13 minutes to read.
In short
Practice applies the framework to classic prompts like a URL shortener, chat, news feed and rate limiter. The goal is a clear 45-minute walk from requirements to a defended design.
Explained simply
Practising system design is like practising a speech. You can read every article about URL shorteners, but the first time you explain one out loud under a timer, you will run out of time or forget the database. The only fix is doing it many times.
The four classic prompts each teach something different. A URL shortener teaches ID generation and read-heavy caching. A chat system teaches real-time connections and message ordering. A news feed teaches the fan-out trade-off. A rate limiter teaches shared counters and atomic operations.
Each design follows the same path: requirements, estimates, API and data, a high-level drawing, then a deep dive and trade-offs. After a few rounds the path becomes automatic, and you can spend your energy on the interesting parts.
Treat the interviewer as a teammate. Ask what matters most to them, check in every ten minutes, and offer choices: "we could do A or B; I'd pick A because...". That conversation is what they are grading.
Press Play on a diagram to walk through it one step at a time.
- 1Clients
POST long URL, GET short code
- 2Load balancer
Spreads traffic over app servers
- 3Stateless app servers
Generate codes, return 301 or 302 redirects
- 4Redis cache
Hot code to URL lookups, read-heavy
- 5Key-value database
code to long URL, sharded by code
- 1Requirements: 5 min
Features, scale, read/write ratio
- 2Estimates: 5 min
QPS and storage
- 3API and data: 5 min
Endpoints and schema
- 4High level: 10 min
Draw the boxes and data flow
- 5Deep dive: 15 min
Bottlenecks, scaling, failures
- 6Wrap up: 5 min
Trade-offs and next steps
- 11 sign bit
Always 0, so IDs stay positive
- 241 bits: timestamp
Milliseconds since a chosen start, about 69 years
- 310 bits: machine ID
Up to 1,024 generators
- 412 bits: sequence
Up to 4,096 IDs per millisecond per machine
- Write post ID to each follower's feed
- Reads are one fast lookup
- Celebrity posts mean millions of writes
- Merge followed accounts' posts at read time
- Writes are cheap
- Slow for users following thousands
- Push for normal accounts
- Pull celebrities at read time and merge
- Used by large social apps
In depth
URL shortener: IDs, redirects and caching
The core is generating short, unique codes. Option 1: a database counter encoded in base62. To avoid one hot counter, each app server reserves a block of IDs (say 1,000 at a time) and hands them out from memory. Option 2: a Snowflake-style 64-bit ID made of a timestamp, a machine number and a sequence; it needs no coordination but gives longer codes. Option 3: hash the long URL and take 7 characters, checking for collisions. Sequential codes are guessable, so some designs shuffle or encrypt the number first.
Redirects: 301 (permanent) lets browsers cache it and skip you next time, which saves load but hides clicks. 302 (temporary) brings every click back to you, which analytics needs. Reads outnumber writes by about 100 to 1, so put the hot codes in Redis and the rest in a key-value store sharded by code.
- Browser to App server: GET /abc1231GET /abc123
- App server to Redis: GET code abc1232GET code abc123
- Redis to App server: miss3miss
- App server to Database: look up abc1234look up abc123
- Database to App server: long URL5long URL
- App server to Redis: cache it with a TTL6cache it with a TTL
- App server to Browser: 302 Location: long URL7302 Location: long URL
Chat: connections, ordering and offline users
Clients keep a WebSocket open to a gateway server, so messages can be pushed instantly. Because users connect to different gateways, keep a registry (often in Redis) of which gateway holds each user's connection. When Alice sends a message, the chat service stores it, gives it a sequence number within the conversation, acknowledges Alice, and pushes it to Bob through Bob's gateway.
Server-assigned sequence numbers per conversation give a clear order even when phone clocks disagree. If Bob is offline, the message waits in storage and a push notification goes out; when he reconnects, his app asks for everything after the last sequence number it saw. Messages are typically stored in a wide-column store partitioned by conversation_id. Presence (online or offline) comes from heartbeats every few seconds. Large group chats multiply delivery work, so they are often capped in size or handled by a separate fan-out path.
- Alice to Chat service: send over WebSocket1send over WebSocket
- Chat service to Message store: write with seq 422write with seq 42
- Message store to Chat service: stored3stored
- Chat service to Alice: sent (seq 42)4sent (seq 42)
- Chat service to Bob: push via Bob's gateway5push via Bob's gateway
- Bob to Chat service: delivered ack6delivered ack
News feed: push, pull or both
Fan-out on write (push) adds each new post's ID to every follower's feed list, often a Redis list capped at a few hundred IDs. Reading a feed is then one fast lookup, which suits the common case where reads far outnumber writes. Fan-out on read (pull) builds the feed when the user opens it, by fetching recent posts from everyone they follow and merging them. It is cheap to write but slow to read for people who follow many accounts.
The usual answer is a hybrid. Push for normal accounts. For celebrities with millions of followers, skip the push and merge their recent posts in at read time. The feed stores only post IDs; post bodies come from a separate cache, which keeps the feed small. Page through feeds with a cursor (the last seen ID or timestamp), not OFFSET, so new posts do not shift pages. Ranking, if asked, is a scoring step after merging.
Rate limiter as a service
Clarify first: limit by user, API key or IP? One rule or many (login is stricter than search)? Where does it run? A common design puts the limiter in the API gateway or as middleware in each service, with rules loaded from configuration and counters stored in Redis so every server sees the same numbers.
The check and the increment must be atomic, or two servers can both read 99 and both allow request 100. Use a single INCR (fixed window), a MULTI transaction, or a Lua script that Redis runs as one step (token bucket or sliding window). Return 429 with a Retry-After header. Discuss failure: if Redis is unreachable, fail open (allow traffic) or fail closed (block it), and say which suits this API. For very high traffic, servers can keep small local counters and sync with Redis periodically, trading a little accuracy for speed.
- Key: user, API key or IP
- Atomic check plus increment in Redis
- 429 with Retry-After
- Decide fail-open or fail-closed
- Rules in config, not in code
Running the 45 minutes well
Write the requirements in two short lists, functional and non-functional, and confirm them before drawing. Give estimates quickly and use them: "40 writes per second fits one database; 4,000 reads per second means we cache". Draw the high-level boxes and say what data flows along each arrow.
At about the 25-minute mark, ask "which part would you like me to go deeper on?" or pick the riskiest part yourself. Keep a list of trade-offs as you go, so the wrap-up is easy. If you get stuck, say what you are weighing; silence is the worst outcome. Finish by naming what you would add with more time: monitoring, alerts, multi-region, security. In timed mock practice, record yourself, then check where the minutes really went.
- Confirm requirements before drawing
- Use every estimate to make a decision
- Ask where to go deep
- Name the trade-offs you made
- End with what you would add next
Learn it in 5 short steps
About 2h each. Track them with a timer in your plan.
- 1Design a URL shortener~2h
- 2Design a chat system~2h
- 3Design a news feed~2h
- 4Design a rate limiter~2h
- 5Run timed 45-minute mock designs~2h
Key points
- URL shortener: unique id from a counter or ID service, encoded in base62.
- Chat: WebSockets for live delivery, store messages per conversation, track presence.
- News feed: fan-out on write for most users, fan-out on read for celebrities.
- Rate limiter: token bucket counters in Redis shared by all servers.
Key terms
Tap a card to flip it. 0/5 known
Examples
ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
def base62(n):
if n == 0:
return ALPHABET[0]
out = []
while n:
n, r = divmod(n, 62)
out.append(ALPHABET[r])
return ''.join(reversed(out))
# base62(125) -> '21'; 7 chars cover 62^7, about 3.5 trillion idsURL shortener: from numbers to decisions
Requirements: shorten a URL, redirect fast, links last for years, click counts wanted. Estimates: 100 million new links a month is about 40 writes per second. With 100 reads per write, that is about 4,000 redirects per second on average. Each record is about 500 bytes, so 50 GB a month, about 6 TB over ten years. Decisions follow from the numbers: writes are tiny, so one ID service with block allocation is enough; reads dominate, so cache hot codes in Redis; 6 TB needs a sharded key-value store; analytics needs 302, not 301; 7 base62 characters give about 3.5 trillion codes, far more than the 12 billion needed.
Writes: 100M/month / (30 x 86,400 s) = ~40/s
Reads: 100 x writes = ~4,000/s (peak ~12,000/s)
Storage: 100M x 500 B = 50 GB/month -> ~6 TB in 10 years
Codes: 62^7 = ~3.5 trillion >> 12 billion links in 10 years
Choices: block-allocated counter IDs, Redis for hot codes,
sharded key-value store, 302 redirects for click analyticsNews feed: one normal user and one celebrity post
Maya has 300 followers. When she posts, a fan-out worker reads her follower list and pushes the post ID into 300 feed lists in Redis: 300 small writes, done in milliseconds, and each follower's next feed load is one list read. A singer with 50 million followers posts. Pushing would mean 50 million writes for one post, minutes of work, repeated for every post. So her account is marked as a celebrity and skipped by fan-out. When a follower opens the feed, the service reads their precomputed list, fetches the latest posts of the few celebrities they follow, merges both by time, and returns the first page with a cursor.
Quick reference
- URL shortener: 7 base62 characters give 62^7, about 3.5 trillion codes
- 302 redirects bring every click back for analytics; 301 lets browsers cache and skip you
- Snowflake ID: 41 bits time, 10 bits machine, 12 bits sequence (4,096 IDs per ms per machine)
- Chat: WebSockets plus a user-to-gateway registry; order by a per-conversation sequence number
- Feed: push post IDs to followers; pull celebrity posts at read time and merge
- Page feeds with a cursor (last seen ID), not OFFSET
- Rate limiter: atomic counters in Redis (INCR, MULTI or Lua); choose fail-open or fail-closed
- Every 10 minutes of a mock, sum up where you are and what comes next
Common mistakes
- Spending 20 minutes on requirements and never reaching a design.
- Drawing boxes without saying what data flows between them.
- Not practising out loud under a timer.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
A shortener expects 500 million new links per month, 20 reads per write, and keeps links for 5 years. Estimate write and read QPS and total storage at 500 bytes per link.
- Exercise 2medium
Describe, in about eight lines, how a chat system delivers a message when the recipient is offline, and how it keeps messages in order.
- Exercise 3hard
Write your checkpoint notes for a timed 45-minute "Design a news feed" mock: what you will cover by minutes 5, 10, 15, 25, 40 and 45.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- How many system designs should I practise before interviews?
- Aim for eight to ten different prompts, with at least four done out loud under a 45-minute timer. Repeating a prompt a week later is a good test of whether the framework has stuck.
- Should I draw diagrams during the interview?
- Yes. Draw boxes for clients, load balancer, services, caches and stores, and label the arrows with what flows along them. A clear drawing gives you and the interviewer something to point at.
- What if the interviewer mentions a technology I don't know?
- Say so honestly and ask what property they care about, such as ordering or durability. Then reason from that property; interviewers value clear thinking over memorised product details.
- How deep should I go on one component?
- Deep enough to show real trade-offs, such as how IDs are generated and what happens when that service fails. Ask the interviewer which area they want, and keep an eye on the clock so you still have time to wrap up.