Interview Q&A / System Design
System Design interview questions
Caching, scaling, databases and classic design problems for beginners.
Prefer rapid revision? Practise System Design short interview answers →
- What is caching and what caching strategies should you know?
A cache keeps a copy of frequently used data in faster storage, like memory, so repeated reads are quick. Know cache-aside, write-through and write-back, eviction policies like LRU, TTLs, and the hard part, keeping the cache consistent with the database.
BeginnerIn-depth3 min read - How would you design a URL shortener like bit.ly?
Store a mapping from a short code to the long URL. Generate codes with a counter encoded in base62 (or random codes with a collision check), keep the mapping in a key-value store, put a cache in front for fast redirects, and return a 301 or 302 redirect. Add rate limits, expiry and analytics as extras.
IntermediateIn-depth3 min read - How does a CDN work and what does it improve?
A CDN keeps copies of your content on servers near users around the world. A user is routed to the closest edge, which serves cached content quickly and only contacts your origin server on a miss.
BeginnerQuick answer1 min read - How does the cache-aside pattern work?
The application checks the cache first. On a miss it reads the database, stores the result in the cache and returns it. On writes it updates the database and removes or updates the cache entry.
BeginnerQuick answer1 min read - What is the difference between LRU and LFU cache eviction?
LRU evicts the item not used for the longest time. LFU evicts the item used the fewest times. LRU favours recency and is the common default; LFU favours long-term popularity but is slower to adapt.
BeginnerQuick answer1 min read - How do Cache-Control and ETag headers work together?
Cache-Control says how long a response may be reused without asking. ETag is a fingerprint of the content; after expiry the browser sends it back, and the server replies 304 Not Modified if nothing changed, saving the download.
IntermediateQuick answer1 min read - How do you update a file that is already cached on a CDN?
Either purge the URL on the CDN, which is slow and rate limited, or better, put a version or content hash in the filename, such as app.3f9a1c.js. A new name is a new cache entry, so there is nothing to invalidate.
IntermediateQuick answer1 min read - What is a cache stampede and how do you prevent it?
A cache stampede happens when a popular key expires and many requests miss at once, all hitting the database together. Prevent it with request coalescing or locks, jittered TTLs, and refreshing entries before they expire.
IntermediateQuick answer1 min read - What is the difference between write-through and write-back caching?
Write-through writes to the cache and the database together before replying, so data is safe but writes are slower. Write-back writes to the cache first and flushes to the database later, which is faster but can lose data on a crash.
IntermediateQuick answer1 min read - When would you pick Redis over Memcached for a cache?
Memcached is a simple, fast key-value cache. Redis adds data structures (lists, sets, sorted sets), optional persistence, replication and pub/sub, so choose Redis when you need more than plain get and set.
IntermediateQuick answer1 min read