System Design Course


System Design Course

Anna
Michael, have you ever wondered how systems like YouTube or Zoom handle millions of users streaming video at the same time? That's exactly what this course is about — system design for large-scale distributed systems.

Michael
And it's taught by Gaurav Sen, who has a popular YouTube channel on the topic. He says it's for beginners who've never done system design before but want to learn the basics.

Anna
Right. Let's start with what a large-scale distributed system actually is. Large-scale means it's heavily used — like Google Maps, which stores the whole world's map, serves billions of requests, updates frequently, and demands high performance and reliability.

Michael
And distributed means the system runs on multiple servers across the world, not just one. For example, Google Maps might have servers in India, the US, and Japan. If one fails, others take over, and users get faster responses from nearby servers.

Anna
Exactly. To build these systems, engineers rely on design patterns — proven solutions to common problems. Like the publisher-subscriber pattern: when a celebrity posts on social media, you need to notify millions of followers without overwhelming your servers.

Michael
So the pattern decouples the publisher from the subscribers with an intermediary that controls the pace of notifications. That's a classic design pattern. And the course teaches you to convert business requirements into technical solutions using these patterns.

Anna
Let's apply this to a live streaming app. The first step is defining requirements from the user's perspective. For a live stream, the core requirement is simply that users can watch the video live. Everything else — HD quality, comments — is secondary.

Michael
Then you reduce those features to data definitions. For instance, 'liking a comment' becomes a like object with a like ID, user ID, timestamp, and the comment itself has its own structure. This maps directly to database tables.

Anna
Once data is defined, you need APIs to manipulate it. For our live stream, we might have an API like 'get video frame' that takes a video ID, device type, and offset, and returns a 10-second frame. This is how clients interact with our server.

Michael
But you also have engineering requirements beyond features: fault tolerance, so if one server goes down others pick up; extensibility, so you can easily add features like read receipts later; and performance. That's why we test designs before coding.

Anna
Testing can be as simple as running through edge cases or using load testing tools. In our live streaming example, the core requirement is showing video to millions. That means capturing raw 8K footage from a camera and storing it in a file system.

Michael
But you can't broadcast raw 8K to mobile phones. So you need to transform the video. That's where the map-reduce pattern comes in: you split the video into 10-second segments and send each segment to different servers to convert it into various resolutions (144p, 480p, 720p, 1080p) and formats (like H.264).

Anna
And you might also compress the segments. The important thing is that any free server can pick up a task — this is the map part. The reduce part combines the outputs, but in this case, each output is stored separately for later delivery.

Michael
To stream these transformed segments to users, you need the right network protocol. For non-real-time actions like posting comments, HTTP works fine because it's stateless and simple. But for video frames, you want a real-time protocol like WebRTC or adaptive streaming protocols like MPEG-DASH and HLS.

Anna
Adaptive protocols are key because they adjust video quality based on the user's network. If someone enters a tunnel, the stream automatically drops from 1080p to 144p without the user lifting a finger. That's the dynamic adaptive streaming over HTTP, or DASH.

Michael
And for distributing static video content, you use a CDN (content delivery network). CDNs cache popular videos close to users, reducing load on your origin servers and lowering latency. But you have to handle authentication — not everyone should be able to access the video.

Anna
Now let's move to low-level design. This is where you zoom in on a specific piece of the system, like how a user watches a video. You start with a use case diagram to list what the customer can do: play from a timestamp, resume from where they left off, get the best quality automatically, and buffer for smooth playback.

Michael
Then you convert those use cases into classes and objects. The main classes are Video (has frames and metadata), User (has ID and email), WatchedVideo (tracks which user watched which video and their seek position), and VideoConsumingService (the API layer).

Anna
For each class, you define states (data) and behaviors (methods). For example, Video has a method `getFrame(timestamp)` that returns the appropriate frame. And the VideoConsumingService exposes APIs like `getSeekTime(userId, videoId)` and `getFrame(videoId, timestamp)`.

Michael
But the interaction between objects can get complex, so you use a sequence diagram. For instance, the user first requests their seek time from the VideoConsumingService. That service returns a timestamp. Then the user requests a video frame at that timestamp, and the service fetches it from the Video (which may be backed by a file system).

Anna
Finally, you code! The diagrams remove the thinking overhead. For the Video class, you iterate over frames to find the one matching the timestamp. But be careful: frame duration shouldn't be a magic constant. Make it per-frame, because some frames may be shorter if there's a lot of motion.

Michael
That's a great point — it's the difference between a junior and a senior engineer. You make the code flexible by storing the start timestamp and duration in each Frame object. Then `getFrame` simply checks if the requested timestamp falls within any frame's interval.

Anna
And the VideoConsumingService uses the WatchedVideo class to persist seek positions, so users can resume where they left off. The whole low-level design process is language-agnostic — you can apply it in Java, Python, or any OOP language.

Michael
So to recap: we defined requirements, identified data and APIs, chose network protocols and databases, used design patterns like map-reduce and adaptive streaming, and then dove into low-level design with diagrams and code. That's a comprehensive intro to system design.

Anna
And if you want more, Gaurav Sen has free resources on Interview Ready covering load balancing, rate limiting, and caching. There's also a paid section for advanced topics. Check out the free ones first and level up when you're ready. Happy designing!

Ask anything
We've read this whole study set, so questions about it get the best answers.