1. Home
  2. Explore
  3. Engineering
  4. System Design Course

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

System Design Course

Transcript

This course is a detailed introduction to system design for software developers and engineers. Gaurav Sen developed this course. He is an experienced software engineer and he also has a popular YouTube channel. You will learn about basic engineering design patterns that are used to build large-scale distributed systems. In the second part of the course you will learn how to use the principles from the first part to design and code a live streaming video app. Hello everyone. Welcome to the System Design course. This course is for beginners in a sense that if you have never done system design before or you have done very little system design or you have just heard of it or read about it, but not got an opportunity to actually do it, this course is right for you. At the end of this course, you'll be able to identify some basic engineering design patterns, which are used to design large scale distributed systems. Let me define each of these terms in detail.

Large scale distributed systems, as the first part of the term, says large scale, meaning that something which is being used a lot or is very intensive in terms of compute or data or any, computer engineering principle. For example Google, let's say Google Maps. This is large scale because A: it has a lot of data. The whole world's map has to be stored, incited. B: it's being used by a lot of people. C: it's being updated very frequently, and b, it has a lot of performance expectations from it. You don't expect Google Maps to go down. You expect Google Maps to return results quickly. You expect it to be accurate, so on and so forth. So it's a very good product being used at a large scale. Distributed systems means that the server or the code that is actually executing this program is not in one place.

It's disputed all around the world. So you might have one server in India, one server in the us, one in Japan for tolerance, so that if one of these servers crashes, the rest of the servers can take the load. It's also for performance. If the Indians want a Google Map result, they go and talk to the Indian server because that gives a quick result back. While if they go to the US server, they have to go across continents and then get a response, which is a slow result. Okay? So that's the point of a large scale distributed system. Many of these companies which provide these solutions, Expect their engineers to know about system design, to know how to build these large scale distributed systems. So to do this, their engineering team depends on design patterns, which we mentioned earlier. Design patterns are particular practices, principles, or processes which are used by engineers to build these systems.

For example, you have a common problem of a celebrity posting on social media and that post being distributed to a lot of their followers. For example, if Brad Pitt posts something on YouTube and then post on LinkedIn, the problem is very similar. It's one piece of content which has to be made into an event and notified to millions of people potentially. And what you want to do is you want to notify them quickly, but you also don't want to put too much load on your service so that the rest of the requests, which are coming into it continue being served. This is a common problem, so you extract out a common problem and you solve it using a common solution.

, this would be a design pattern. Right now, you don't know what design patterns exist, but one popular design pattern for this kind of a problem is a publisher subscriber model where Brad Pit is a publisher and their event is subscribed to by millions of people. And Intermediately decides the pace at which you send these notifications, which keeps the server loaded low, and also make sure that all the notifications actually reach all the subscribers. Now, seeing this, you can tell that as an engineer you can take a lot of business requirements and convert them into technical solutions, and engineers use system design patterns to make reliable, scalable, and maintainable systems.

This helps them convert business requirements into technical solutions. If this sounds exciting to you, watch's the rest of the video and you won't be disappointed. Okay, let's start with an example. Let's say that you join a company which does broadcasting of videos to millions of people. This could be Hot Star, it could be YouTube, it could be Zoom also. So some sort of events which are being broadcast to millions of people. And you as an engineer have to devise the solution for this, come up with some technology which can handle this problem. So the first thing that we need to do as engineers is to define these requirements from the user's perspective.

And often engineers don't do this. They're product managers and a company which write a product requirement document based on user feedback and data. So that's good to have. You have a well documented, thought business banked document, which the engineer can then read and decide on how they can make it happen. Amongst these, you pick up the most important features first. Taking the example of a live streaming system, users who tune into your system should be able to watch the stream live.

Whether you see it at HD quality or you see it at four 80 p, that's probably a secondary issue, but being able to see the video is a primary issue. So for that, you have to make sure that your server doesn't go down, and you have to also make sure that your bandwidth requirements are sufficient. Second, you reduce these features to data definitions. So one of the features which might be defined is users should be able to like a video or should be able to like a comment. What you then do is you look at the concept of a, like the abstract concept of somebody liking something. What does that mean? It means that a particular user likes a particular comment. Okay, so it has a like id, it has a user ID who's done this. It has a timestamp. When was this video liked or when was this comment liked? The comment itself is an abstract concept. It's probably going to be mapped into an object. It has an id, it has a user who has typed this comment.

It has a creation time and maybe it also has a thread in which it was posted. So you're seeing that I'm taking features or I'm taking these abstract concepts from the product requirement document and converting them into data definitions, which are used, useful for an engineer. These definitions can then be mapped into objects, which can then be mapped into the database. Once you've defined the data that you need to store, you need to define endpoints through which this data can be manipulated or queried.

So I want to read comments, give me an API and sgp api ftp API for all WeCare. The network protocol at this point is not important, but some method by which I can send an electronic signal from one place to our server, and our server can respond to that signal with the data that they need. So our server is now encapsulating this data as per the user requirement and defining some endpoints, which are called APIs. So that external users can query and manipulate our data. We do this for every feature that we have, core features and also optional or good to have features. Usually a product requirement document does not define optional or good to have features. These are all core features which are required in the document. The good to have features will be probably picked up in the next document, so you don't need to think of which features are optional, but you do think of which features are most important as an engineer.

The second thing is you also have certain engineering requirements. When you're creating these designs or coming up some code, you want to make sure that none of your services fail If there is an outage, so for example, if you have an outage in India and your common service is in India, then you don't want the entire system to collapse. We talked about this a little earlier, that you have multiple server spread across the world to avoid a single point of failure. . You may also have multiple servers in India itself. So if one Indian server fails, another one picks up its responsibility.

So here you might have some sort of data duplication because of which the other server is quickly able to pick up the responsibility. Or you have some sort of partitioning that 50% of the users are going to this server, 50% of the users are going to another server. So just 50% of the users are affected under the common and often missed out engineering requirement is extensibility, which means it's not just about the technical solution that you come up with, but also how easy it is to change that solution. For example, if you write code to send a message to millions of users, and you need to make a small tweak to that code because now you don't want to just send it to 1 million users. You also want to check whether they have read those messages. So read receipt. The problem with writing code, which is highly coupled with the feature. Is that whenever there's a changing requirement, you have to put in a lot of effort to redesign, test, and actually deploy that code again.

So you want your features, your engineering features. To be extensible for this, you have to take out your engineering pistol ball and gaze deeply into it. Actually what you do is, as an experienced engineer, especially, you look back at your past projects you look back at things that you have done, you look back at things that people have done. You know what the world is doing. And based on that combined knowledge, you build a system so that you can reasonably expect it to scale and extend as requirements change and as more and more users join you, finally this design needs to be tested. This is an important part of system design, which is not really thought through in interviews, but in the real world, when you have a system which is designed by, let's say a senior engineer that design has to be tested. You run through a couple of requests with edge cases, with common cases, and whether these

requests are having a sensible flow in the system at a high level. The other thing that you can do is you can use sophisticated tools to load test this design. You can have some sort of capacity estimation to actually see whether this design is feasible, but importantly, you have to test this design before you start getting into the code. Okay. Let's recap with an example. Let's say we have a live streaming system. How would we go about designing this? Requirements would be streaming video, processing video, sending video to multiple customers. So that is broadcasting not failing is a requirement. Showing advertisements, allowing reactions, showing disclaimers or news flashes, having graceful degradation of video quality in case you have low bandwidth, allowing multiple device support. and so on. Amongst these, you'll see that the product requirements are mainly showing video to a lot of users. That's a major requirement.

And also, of course, comments is a thing and being able to react as a thing. You may also consider product requirements to be showing a banner in case there's a problem. It is, but the core requirement, of course, is just showing a video, so I'll pick this feature first. This means that I have to capture video from a source, let's say, which is shooting at eight K, and I should be able to store it in someplace in my server so that I can query it later in a live streaming system. The later part, the query it later is probably milliseconds, so I may not want to query that data at all. I may want to directly stream it from the video camera onto millions of people taking a step back. It looks impractical because if I'm shooting at eight k at very high quality, and this is raw footage. Sending that much data to people on their mobile phones is unreasonable.

So yes, I need to store it in some sort of a database or a file system, and then I should be able to stream that or query that out so that I can distribute it to all of my customers. But I don't want my customers to know exactly how I'm doing this or I don't want them to know about, there's a change in implementation tomorrow. I want this to be a black box so that they can pay me and relax. They just hit an API and their problem is solved. Of course, I might give them clients which are download on the app store which take care of all of this API and querying also so that as end users, they can just enjoy watching an event instead of thinking about how the technical part of this is actually happening. These APIs have well defined signatures. You can tell that if I want this video Id in a particular format, then I have to query a particular API called Get video. , which is going to be returning me objects of type frames. And those

frames are also well defined. So if you have ever written a program, you know that these API signatures are very similar to method signatures. The only difference being that these APIs might be queried not through a programming language, but through a network protocol like G R P C, htp, ftp, any kind of protocol which defines exactly how an electronic message is going to be taken from one place and sent to another. And also how the response is going to come back and how the behavior of this interaction is going to be that is defined by the protocol. So this is great. We have a system which is storing some data, which is valuable to us because we want to watch this event live. And this data is going to be queried using APIs. Also, these APIs are going to be tested beforehand so that, the clients who are using this work, paying for this service are not disappointed when they actually query it. As engineers, we have to think of various failures and our use.

. What if the database, which is stored in your videos crashes? What if a particular firewall on the internet starts blocking all of your requests? What if one of the services that you've written in your entire system, one program, one piece of code, starts misbehaving because you have, introduced a bug in it? Or there is somebody who has maliciously entered the system and changed the code in that system? We have to use some design principles that we talked about earlier. This challenge may also be a feature request, like if you want the musician who's playing in this live event to be able to talk to the audience, do a back and forth with some audience members who they select either randomly or based on their activity.

So you have to display those users to this musician live and be able to broadcast two parties to millions of people out there. So taking these requirements, let's try to design a live streaming application. So there's two ways to approach this. One is, From customers or our clients to our server, which is out there in different parts of the world. And then to our database, which may be, again, in different parts of the world. That's one way to think. And the other way to think is from our database to our server. So what kind of detail do I need to store to enable my server? And what kind of APIs do I need to expose to enable my customers to be able to use my product? Okay. Both of these approaches are fine. They require different ways of thinking, though.

When it comes to a data based approach, you will need to consider what kind of data do you need to store. And often you'll be thinking of these pieces of data as tables. So you need to store a video with an id. The video has a name, it has a size, and it has some data. That's one way to think. I prefer the other approach where customers define their problems, which are then fulfilled using APIs on the server, which are then fulfilled by storing some sort of data in the server, in the database. And that data is then mapped onto tables like and so for this system, this is the product we'll be using.

Okay? In our case, customers are live streaming customers, so they may be streaming from their cell phones or laptops or the tv and we can't assume which device is being used more often. In certain countries you'll have certain devices being used more. There there could also be a tablet of course, from which they're streaming this video. But that there are multiple devices which need to be catered to. This is a front end UI design problem. System design is more to do with the distributed systems' backend part of things.

There is some system design involved when it comes to API interactions and how to store or cash data on the front end, but that is not what we are focusing on here. We are focusing on the backend part of the system. Okay? So these clients need to be able to query our server in real time. So what does our server need to have? Its APIs are going to be something like get video and you pass in the video ID and you pass in your device type. So I send you the resolution based on your device type and you might have a particular offset that you know, I've already seen the first 10 minutes of the video. Show me everything after the 10th minute. If I have a video API like this, I also need to return something. So the return type could.

Some frames, some video frames. Let's say each of these frames is 10 seconds long. So a single frame is what I sent back, such that it is off this video for this device. And after 10 minutes, so 10 minutes to 10 minutes and 10 seconds, that frame is picked up and sent to the client. If you know about API design, that this API is not well named. Get video means you get an entire video, but you're returning a frame. So maybe we can rename this to get video frame. Other thing is if you're using a

REST protocol get is going to be defined in the request itself. So g e t or here is going to say that Get Me Video is enough to say that you want a video. In our case, like we said, it's a frame, so maybe get frame or get video frame is what we are looking at. You notice that Wimu also has a similar API when it comes to getting the next 10 seconds. YouTube also has an api which tells you from which point to which point do you want to see the video? I'll give you all those things.

Great. So we have this, what else? You should be able to comment on the video. Okay. So what you should be able to do is you should be able to post a comment. Again, I'm using well-known concept in rest post means you want to put something in the server, you want to manipulate some data, you want to add some data to the server. So if I say post a comment with an ID here, I don't care about which device it is coming from because the comment is just data, which has to be persisted in the server.

Based on that, I'm not going to be, changing my response or changing the behavior in which I'm posting the comment. So I don't need that. I don't need an offset, but I do need the comment data. I need the author of the comment. I need the post on which this comment was made. So maybe the video on which this comment was made. So the video ID. And similarly for each requirement, we can expose APIs, which will allow us to query and manipulate the data as we want. So that roughly defines our server side capabilities. Okay, we haven't spoken about anything in detail. We haven't talked about the network protocol also that we use, but roughly this is what it's, okay. Now let's go for the next part, which is the database side of things.

What kind of data we need to store to satisfy these APIs. Returning frames is something we want to do. Storing comments is something we want to do and also probably get those comments. And to get video frames, we also probably need to put video frames. What kind of database should we use? Comments are rather simple. You can store this in an SQL database such that an SQL table having an ID with you. The data of the comments are text. being stored as a problem. The author, which is a foreign key to a user table, right? So in a user table, you have an id and this author is going to be mapped to an ID over here. Along with that, we have a video id. So there's a video table also, which has an ID and some data. The video IDs are going to be mapped in this way, okay? An example of this would be video ID 10 is over here. This is a cricket match. Video ID 11 would be a musical event. Okay? And this is a comment table.

So for this cricket match, a comment was made in which they said, Hey, and the author was author number one. Author number one happens to be called. That's their username. So if you have to display all comments, In the front end for a particular video. What you want to do is you want to get all of the comments in this table for that video 10. Then you want to get the data for that user because you want to display the username who has made that comment. And you also want to get some video data because you have to display that on top of the page where the comment was made.

So in this way, we are able to satisfy our requirement of posting comments, posting video. Now, overall, this system is complete. We have a system which can answer queries. Okay? This is good enough to start with. This diagram is not incomplete. It's very rough or high level. There's nothing here which is concrete, nothing, which is, let's say, useful when it comes to implementation. A at this point in time, we have a rough idea of how we are going to be talking to each other, not what we are going to use to make this happen. So let's get into those implementation details.

Firstly, on the client side, is there something we need to do? Yes, different APIs require different behaviors. Posting a comment means that I'm posting this once and I'll be querying that comment maybe soon, but it's not like I need something to keep happening. I don't need continuous updates on the comment. Those notifications can be given periodically to me, or maybe I don't need those notifications at all after a few months. I just don't need notifications on that comment.

So you see over here, you have non real time behavior. What about a video frame? When I ask for a video frame, I usually need to ask for the next video frame immediately after that. So I'm watching a live video, I ask for a video frame. I am sorted for the next 10 seconds. In five seconds, I'll be asking the next video frame. . So that behavior is different. It's a more continuous behavior. Okay? So maybe we need to use different network protocols to make this happen. What would I use for a comment? I would use the most common network protocol when it comes to disability systems, which is hdp, HTP gives us the benefit that you have a stateless server. You don't need to store any information when you're handling a request. A stateless server is basically, I have no idea where you are from or what you want.

Define everything in the request. Okay? Goon wants the next 10 seconds of video. What do you mean by the next 10 seconds? Who is God of San? Okay, so what should be there in the request is here's Gossen. This is his user id. You can actually go and look it up in your database. It's not the next 10 seconds that he wants the video from minute number 10 to 10 minutes. 10 seconds. Okay. That video length is also well defined. There is no concept of the next point of view. And the video ID is mentioned. It's not like Gora wants the next 10 seconds of the video he was watching. No, I have no idea what we do. He was watching you define which video needs to be pulled up here. You might think that this is an obvious point, like what's so special about

defining everything in the client itself. It looks a little tedious and stupid, but doing it is fine. Doesn't everyone do it? Not necessarily. When you ask for the next 10 seconds of video, for example, very often as a client, you don't know what the next 10 seconds should be. Take an example. Give me the video at 10 minutes, then 10. 10 seconds from 10 minutes. Okay? That's one chunk.

Let's say you make that request. And the server is taking time to give a response. Now you come back and you say, give me the same video because you didn't receive it in time. The server is going to look at that request and serve you the same response again. The other approach to this would be the client making a request. Gimme the next 10 seconds, where next is known to the server. Okay, so here the definition is not 10 minutes to 10 minutes and 10 seconds. The definition here is the next 10 seconds.

The server is now going to take this request, look at the user's current pointer, and then decide which 10 seconds to pull out. So in the first case, it'll take 10 minutes to 10 minutes, 10 seconds. In the second case, it's going to make a decision to send you the video from 10 minutes, 10 seconds to 10 minutes, 20 seconds. What's the benefit? The client didn't need to know which part of the video it wants to watch. , it lets the server handle it. It makes the overall network more efficient because the client is not making duplicate requests, and it makes the client code a little more simple. You don't need to define everything every single time you let the server figure it out with context. That's a difference between a stateful and a stateless protocol. HTP is stateless.

Its benefit is that the server is kept simple. If the server crashes, there is no context on memory that is lost in the server. If you forget where the client currently was pointing to, then this is a serious problem right? You can go and store it in your database instead and make a service stateless. Therefore, the protocol that you're going to use htp can be stateless. The best part about this is you can add new servers without any issue. You have no state being stored in server. So whenever a new server pops up a new request comes with total context in the request itself, which you use. To query your data, right? What about video frames? Do you want to query video frames? You want to get the next one? What kind of a protocol will be nice?

You can use HTP here also, but a much better protocol would be something which is designed for video transmission, because in video you have to consider some other parts. What happens if I have a mobile device, which does not have much resolution? What happens if I have poor bandwidth? What kind of video am I transferring? If it's a live streaming thing, then the current video is the most important video. What happened previously does not matter anymore. If I missed that packet, if that packet was dropped in the network, let go. If it's a, if it's a live streaming lecture where you know, there needs to be full context to understand the next part of this lecture, then you probably want to send it properly. You want to send it over a reliable network and over a reliable protocol. Okay. So if you want a reliable protocol, a TCP back protocol is a good idea. If you want a realtime efficient protocol, then a UTB backed protocol is a good idea.

So over here I'm going to use a protocol like Web RTC here. Web RTCs, a peer-to-peer protocol. So you actually are able to send video from the server to the client. Certain protocols have a client to server expectation. So the client is the only person who can send data who can make a request to the server. The server cannot send data by itself to the client. Okay? So what I'm doing again here is using a peer-to-peer protocol for the video, but for comments, it's always gonna be client to server. So you see that network protocols are also important when it comes to designing systems. Okay, finally, on the server side, what are some considerations we have to take? Similar to the server side we have to think about how are we going to talk to the server, but. Most database solutions, let's say MyQ or post case, define exactly how you're going to be talking to the databases. So this is a TCP backed protocol usually, but the protocol is defined

well, so we don't need to think of that when it comes to talking to service. Elastic Search, for example, has HSTP based protocol Cassandra, Amazon db, Amazon Diameter db MySQL, post Grace all of them, the protocols are identified. The problem then becomes which database solutions should we use? Because there's a ton of solutions out there, and they have tradeoffs. We could store data in the MySQL database also, but it's going to be expensive, and it could be potentially very slow also.

So what is this video data? It's effectively a file. So storing it in a file system is not a bad idea. And you don't want to build a file system yourself. So you want to use a well-known file system solution for this maybe hdfs. That's one solution. You could also use a video hosting solution like wimu. Yeah, it's off the shelf. You can just use it. You can use wimu, by the way, to host events also. So it's best to mention this in the system design requirement, like maybe an enterprise solution from will take care of the entire thing. But if you can't do that, if you can't have a live streaming requirement and you don't wanna lose your job, maybe because then you can use a file system like sdfs or s3, Amazon s3.

The benefit of S3 or sdfs is that it is cheap. It's easy to query and you can store very large files inside it, okay? In a database. Yes it's also it's not cheap but it is easy to query and you can store very large files inside. The capabilities that a database gives you in terms of updating data or querying data may or may not be very relevant to you when you have a static file, which is a video file, okay? You're primarily looking at low cost when it comes to storing video solutions.

What about the user or the comment table? These two tables can have a skill solutions back in them, let's say MyQ or post quiz. You may say that a comment is a complex data structure. Every time, a requirement changes, the comment table also needs to change. Maybe you want to persist a lot of data in the comment table per entry. You want to persist all the replies of the comment also in the same entry. So on MySQL database or a SQL database is not what you're looking for. You're looking for a NoSQL database, which is not ideal when it comes to transactions or relational.

Joins, but you don't have that requirement. You're looking for scale When it comes to comments, you just want to persist that data in a key value fashion. So that's no sequel. Great. This is very rough idea of how we are going to be designing, which is satisfying the requirements of the system, and also defining the protocols or the solutions that we'll be using to make it possible. For example, we talked about web RT Cstp when it comes to network protocols, and when it comes to database solutions, we talked about MySQL and a file system, a design can go in more and more depth based on how important that requirement is.

So doing a recap, we see that we have a system, a very rough blueprint even now, which talks about how our customers are going to be accessing our APIs and how those APIs are going to be accessing the data in our database. The data in our database may be being filled by customers like in Facebook. Usually the customers are the people who are filling the data, or it may be filled by an external service. In a live streaming system, it's probably going to be a really high efficient camera, which is going to be recording the video live and persisting to our database. Okay. The network protocol that you probably want to look at is rtmp Realtime Media Protocol which is a guaranteed protocol.

You don't lose any data when you are shooting video using this. And the idea is web rtc, you might lose some data. That's okay. It's the end user watching a live stream. They want data quick and real, but at the source of everything, you don't want to lose any data because everybody else will lose the data if you lose it at the source. So a highly reliable network can be set up over here in a high bandwidth, expensive network because, that video camera is really going to need a high bandwidth, expensive network to process that amount of data into your database and then this data can be sent. You're seeing that I've skipped a lot of requirements. That I can't take this high quality data and just send it, broadcast it to everybody on the planet. What I need to do is transform this data. Okay? So now what we are doing is we have looked at high level what the solutions are going to be and now really getting into the nitty gritties of designing the system.

So the first part of this is how do we take this raw footage, this data over the higher level network, which comes to our database, our file system, and convert it into data that we have to serve our customers. Four adp, seven 20 P, so on and so forth. You can't serve eight K definition. So how do you do that? There needs to be some sort of a transformation service over here, which is going to be taking this live stream and converting it into different resolutions. 10 80 p, which is full hd.

You have seven 20 P, which is hd four 80 P, which is decent for quite a few mobiles. And I don't know if this is something you want to do, but if the live part of your stream is really important, then 1 44 P is also okay. Because as long as people are getting information and they're able to see roughly what's going on, they're going to be happy. Sometimes these resolutions are defined well in the product requirement document itself, the p I d, because after speaking to customers and getting their real feedback, which resolutions are acceptable or tolerable for the customer, there might be some customers who ask for premium 4K transfer also. Okay, so that's fine. You're watching it on tv, then you probably wanna watch it at 4k. Okay. This raw video needs to be converted to these resolutions. How do you do that? So the first thing you'll do is you'll break this video to segments.

This entire raw video is going to be broken into segments of 10 seconds. So you collect video for 10 seconds, chop it off, you break that into one segment, and then you give it for processing at point number 0, 1, 2, 3, and four. So let's say you have these zero to four, which is five programs, which take the raw video and convert it to different resolutions. So if you pass in 1 44 p, then a particular program picks it up. If you pass in four 80 p then another program picks it up. And maybe

you have the same program, which is running in, in five concurrent pieces and five threads based on the resolution that you pass. It converts the video, the ten second video footage into that resolution. Similarly, you can think of different formats. So if you have a device, which is an Android device, , it probably has to see the video in a different format. Okay. It can't read all sorts of video. It has some formats which are well defined inside it in the device, so it can read that format.

Similarly, apple devices might have a different format. So these formats define how you're going to read this piece of data. This video data, which is going to be sent over you through the network common video format is H 2 64. Apart from H 2 64, you might have your own proprietary formats. Let's say you have a format which is more efficient than H 2 64 or for your particular type of event, a music event. You research and you find that there's a way to store video more efficiently. So this is more of a very large scale problem, like Netflix has its own formats, but if you're a small company, edge 0.2 64 is very good. Okay? So different resolutions. Different formats.

We need to take our raw video footage and convert this into a combination of a resolution and format. So over here we use a design pattern of map reduce. I won't go into too much detail of this design pattern, but the basic idea is you can take one video split into pieces, which is 10 seconds long, and send it to different servers to get different outputs. Okay? You might have something else also in the process, apart from just transforming the type of video. Maybe you want to compress it here in the next step. That can be in step two. The servers being used here might be s3, S two and S one. So you see S one is being used here and here.

S3 is being used here and here. So there is no there is no guaranteed execution server that you have for one part of the process. Any server, which is free. We'll pick up a task and execute it, whether it's compression or transformation. Again, finally you get three different outputs, which you can store in your database. So this would be the map reduced pattern. It's a very high level overview of this. It's almost a ca of the map reduced pattern cause there's no reduce in this process over here. But have a look at this design pattern. It is useful when it comes to taking a single piece of data or a data lake and converting it into the data streams that you need. Next, how is this data actually going to go to the users who are looking to view it? So this data has to go over here to the server which is

exposing these APIs of get put post. When you query this data using a protocol, you should be able to get it. We spoke about web RTC earlier, which is a peer-to-peer protocol and it's really good for video conferences. Because multiple people are streaming video together. However, in this case, it's a broadcast, not a conference. So we can take a step back and say, instead of web rtc, we are going to use a protocol which is more suitable for streaming. There's a couple of protocols here. Also. The most popular one would be EG dash, EG is a popular protocol. DASHER stands for Dynamic Adaptive Streaming or sstp, which means that depending on your bandwidth, depending on the network that you're on you are going

to be able to see high quality video or low quality video. For example, you are going in a car, you're watching the video at 10 adp, you enter a tunnel, your network is really poor. So you start watching it at 1 44 p as a client, you don't want to handle it. You want the network protocol to handle it. It's defined in impact dash. Very similar protocol is hls. This is useful for iOS or MAC devices. Okay. And finally, what kind of data do you want to store on the server?

Do you want to store any data at all? Do you wanna make it totally stateless? Yes, statelessness is useful when it comes to request serving and keeping context for every user. But for some things you can keep some state when it comes to video, you can cash the last 10 minutes of video on your server. So anybody asking for video in the last, that video, which is inside the last 10 minutes, is going to get it from the cash. Instead of you making a full network call to the database all the way over here, you instead server from server itself. So you avoid this network call saving time and bandwidth, both. So these are the high level considerations that you have when it comes to a system design. Like we said, this is a large scale distributed system. Our assumption is that you have a lot of users because of which. This much planning and this kind of a design makes sense cost-wise and engineering effort wise. We mentioned that there needs to be fall tolerance here.

There needs to be performance here. So you can use things like CDN solutions. So you can use content delivery networks to persist some static data and have the clients actually pull the starting data from here. Webpages are a good idea. You can also have some video data posted on the CDNs, in which case authentication becomes a bit of a challenge because you don't want everyone to be able to see this data. And does the CDN do the authentication for you? Do you write some code and then host it on the cdn, which does the authentication? These are the challenges that you have, especially when you are designing a large scale distributed system where performance is key. Okay, so this is at a high level the things we need to consider when we are designing any sort of a system. Where the requirements are defined. Maybe in the product requirement document, maybe it's a startup. It's at a very, nascent stage. There is no requirement document.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent