System Design BASICS: Horizontal vs. Vertical Scaling

Gaurav Sen
29 Jul 201807:56

Summary

TLDRThis video script introduces the fundamentals of system design, starting with the concept of an algorithm turned into an API accessible over the internet. It covers the transition from a single desktop to cloud computing, explaining the importance of scalability through vertical and horizontal scaling. The script discusses the trade-offs between the two, highlighting the benefits of a hybrid approach that combines speed, consistency, and resilience. It concludes by emphasizing the importance of designing a system that is scalable, resilient, and consistent, acknowledging the inevitable trade-offs in the process.

Takeaways

  • 💡 The video is an introduction to system design, aimed at beginners.
  • 💻 An algorithm written on a computer can be exposed via an API (Application Programming Interface) for others to use, turning it into a service.
  • 🔌 The interaction with the service involves sending a 'request' and receiving a 'response'.
  • 🖥️ To support the service, a computer might need to be connected to a database and configured with specific endpoints.
  • ⚡ Considerations for system reliability include handling power loss scenarios to ensure continuous service.
  • 🌐 Hosting services on the cloud is recommended for scalability and reliability, as it provides access to a set of computers for running algorithms.
  • 💨 The cloud is essentially a collection of computers that can be rented for computation power.
  • 🔍 Scalability can be achieved through vertical scaling (upgrading to a bigger machine) or horizontal scaling (adding more machines).
  • 🔄 Vertical scaling involves a single machine and can be limited by hardware constraints, while horizontal scaling involves multiple machines and can be more resilient.
  • 🔗 Network calls between servers in horizontal scaling are slower compared to interprocess communication in vertical scaling.
  • 💾 Data consistency can be challenging in horizontally scaled systems due to the complexity of managing transactions across multiple servers.
  • 🛠️ A hybrid approach combining the strengths of both vertical and horizontal scaling is often used in real-world systems.

Q & A

  • What is the purpose of exposing code through an API?

    -The purpose of exposing code through an API (Application Programming Interface) is to allow users to access and use the code remotely over the internet without needing to physically possess the computer where the code is running. This enables the code to be used by multiple users simultaneously, which can be monetized.

  • What is the difference between a request and a response in the context of APIs?

    -In the context of APIs, a request is a message sent to the API to perform a specific action or retrieve data. A response is the result or output that the API sends back after processing the request. Essentially, the request initiates the interaction, and the response concludes it by providing the desired information or result.

  • Why is it important to consider the need for a database when setting up a computer to run an API?

    -A database is often necessary when setting up a computer to run an API because it serves as a storage system for the data that the API needs to access or manipulate. This can include user data, application data, or any other relevant information that needs to be retrieved, updated, or managed through the API.

  • What is the significance of hosting services on the cloud?

    -Hosting services on the cloud is significant because it provides scalability, reliability, and cost-effectiveness. Cloud services can dynamically adjust to the demand, ensuring that the service remains available even during high traffic. Additionally, cloud providers handle much of the maintenance and security, allowing the focus to be on business requirements rather than infrastructure management.

  • What is the fundamental difference between a desktop and the cloud in terms of computing?

    -The fundamental difference between a desktop and the cloud is not in the nature of computing but in the accessibility and management. The cloud is essentially a set of computers provided by a service provider for a fee. These computers can be accessed remotely, similar to a desktop, but they offer the advantage of being scalable and managed by the service provider, reducing the need for local maintenance.

  • Why is scalability an important consideration in system design?

    -Scalability is crucial in system design because it determines the system's ability to handle an increasing number of requests as user demand grows. A scalable system can efficiently manage more connections and data, ensuring that the service remains responsive and reliable without degradation in performance.

  • What are the two main approaches to increasing the scalability of a system?

    -The two main approaches to increasing the scalability of a system are vertical scaling and horizontal scaling. Vertical scaling involves increasing the capacity of a single machine by making it more powerful, while horizontal scaling involves adding more machines to distribute the workload.

  • What is the primary advantage of vertical scaling compared to horizontal scaling?

    -The primary advantage of vertical scaling is that it can provide faster processing due to the increased capacity of a single machine. Additionally, it simplifies data management and ensures data consistency, as all data is stored and processed in one location.

  • What is the main disadvantage of horizontal scaling in terms of data consistency?

    -The main disadvantage of horizontal scaling in terms of data consistency is that it can become complex to manage and maintain data integrity across multiple machines. This can lead to issues such as dirty reads or inconsistent data states, requiring more sophisticated mechanisms to ensure transactional integrity.

  • Why might a system designer choose a hybrid approach combining both vertical and horizontal scaling?

    -A system designer might choose a hybrid approach to leverage the benefits of both vertical and horizontal scaling. This can provide a balance between the fast processing and data consistency of vertical scaling and the resilience and scalability of horizontal scaling. It allows for efficient resource utilization and better adaptability to varying loads.

  • What are the key considerations in system design according to the script?

    -The key considerations in system design, as outlined in the script, are scalability, resilience, and data consistency. Designers must balance these factors to create a system that meets business requirements and can adapt to changing conditions without compromising performance or reliability.

Outlines

00:00

💻 Basics of System Design and API Introduction

This paragraph introduces the fundamental concepts of system design, particularly for those new to the field. It explains the process of turning an algorithm into a service by exposing it through an API over the internet. The paragraph discusses the importance of hosting services on the cloud for reliability and the basic differences between a desktop and cloud computing. It also touches on the concepts of scalability, vertical scaling, and horizontal scaling, explaining how they are used to handle increased demand for a service.

05:01

🔄 Scalability Options: Vertical vs. Horizontal

The second paragraph delves deeper into the scalability options available for system design. It contrasts vertical scaling, which involves increasing the capacity of a single machine, with horizontal scaling, which involves adding more machines to distribute the load. The paragraph highlights the pros and cons of each method, including load balancing, resilience to failure, data consistency, and hardware limitations. It also introduces the concept of a hybrid solution that combines the strengths of both scaling methods, suggesting an initial focus on vertical scaling before moving to horizontal scaling as user trust and demand grow.

Mindmap

Keywords

💡System Design

System design refers to the process of planning and creating a system, particularly in the context of software and computing. It involves understanding the requirements and constraints to build a system that meets those needs. In the video, system design is the overarching theme, focusing on how to expose an algorithm as a service and handle various challenges such as scalability and reliability.

💡Algorithm

An algorithm is a set of rules or steps to be followed in calculations or other problem-solving operations, especially by a computer. In the script, the algorithm is the core functionality that the video discusses, emphasizing how it can be exposed as a service and utilized by paying customers.

💡API (Application Programming Interface)

An API is a set of protocols and tools for building software applications. It allows different software components to communicate with each other. In the video, the API is used to expose the algorithm to users over the internet, enabling them to send requests and receive responses.

💡Request

A request in the context of computing is a message sent to a server or a service asking for a certain action or information. The video explains that when users want to use the exposed algorithm, they send a request, which triggers the algorithm to process and return a response.

💡Response

A response is the answer or result returned by a server or a service in response to a request. The script mentions that the output of the algorithm is returned as a response when a request is made, highlighting the interaction between the user and the system.

💡Database

A database is a structured set of data held in a computer, especially one that is accessible in various ways. In the video, a database is mentioned as a potential requirement for the system, suggesting that it might be used to store data or results generated by the algorithm.

💡Cloud

The cloud refers to remote servers on the internet used for data storage and access, rather than local servers or personal computers. The video discusses hosting services on the cloud as a way to ensure reliability and scalability, contrasting it with traditional desktop setups.

💡Scalability

Scalability is the ability of a system, network, or process to handle a growing amount of work, or its potential to be enlarged to accommodate that growth. The script discusses two types of scalability: vertical and horizontal, explaining how they can be used to handle more requests as the system grows.

💡Vertical Scaling

Vertical scaling, also known as scaling up, involves increasing the capacity of a single server or system by adding more resources such as CPU, RAM, or storage. The video contrasts vertical scaling with horizontal scaling, noting that it involves making a single machine more powerful.

💡Horizontal Scaling

Horizontal scaling, or scaling out, involves adding more machines or servers to a system to handle more requests. The video explains that this approach distributes requests across multiple machines, enhancing the system's ability to handle increased load.

💡Load Balancing

Load balancing is the distribution of workload across multiple computers or a computer cluster to ensure no single system is overwhelmed and to ensure redundancy. The script mentions load balancing in the context of horizontal scaling, where it is necessary to distribute requests among multiple servers.

💡Data Consistency

Data consistency refers to the accuracy and reliability of data across a system. The video discusses the challenges of maintaining data consistency in a distributed system, especially when using horizontal scaling, where transactions might need to be coordinated across multiple servers.

💡Hybrid Solution

A hybrid solution combines elements of different approaches to solve a problem. In the video, a hybrid solution is suggested for system design, where systems start with vertical scaling for fast interprocess communication and data consistency, and then move to horizontal scaling for better scalability and resilience.

Highlights

Introduction to system design basics for beginners.

Concept of exposing code through an API for internet use.

Explanation of request-response model in APIs.

Importance of hosting services on the cloud for reliability.

Clarification of cloud computing as a set of computers provided for a fee.

The role of cloud providers in managing server configurations and reliability.

Discussion on handling increased load with scalability.

Definition and explanation of vertical scaling.

Definition and explanation of horizontal scaling.

Comparison of pros and cons between vertical and horizontal scaling.

The concept of load balancing in horizontal scaling.

Advantages of single machine architecture in terms of data consistency.

Challenges of maintaining data consistency in a distributed system.

Differences in communication speed between interprocess and network calls.

Hardware limitations and the practicality of vertical scaling.

The linear scalability of horizontal scaling with user addition.

Real-world application of a hybrid approach combining vertical and horizontal scaling.

Strategic approach to scaling: starting with vertical and transitioning to horizontal as trust grows.

The essence of system design: balancing scalability, resilience, and consistency.

Transcripts

play00:00

This video is on the basics of system design.

play00:02

If you have never designed a system before, this is probably the place to start.

play00:06

So imagine you have a computer with you in which you have written an algorithm.

play00:10

So some code is running on this computer and this code is

play00:15

like a normal function. It takes some input and it gives out an output.

play00:19

Now people look at this code and they decide that this is really useful to them.

play00:23

So they're ready to pay you so that they can use that code.

play00:27

Now you cannot go around giving your computer to everybody.

play00:29

So what you do is you expose your code using some

play00:34

protocol, which is going to be running on the internet,

play00:37

and by exposing your code using something called an

play00:42

a p i application programmable interface, when your code does run,

play00:46

it'll give an output and instead of storing that in the file or storing it in

play00:49

some database or something like that,

play00:51

you return that and that's called a response. Interestingly,

play00:56

the thing that is sent to you is called a request

play01:01

where people request you. So that's what it is. There's a request sent,

play01:05

and for each request,

play01:07

there's a corresponding response that your computer will be sending back.

play01:10

Imagine setting up this computer.

play01:13

It might require a database to be connected to it.

play01:15

It's within the desktop itself.

play01:18

You might require to configure these endpoints that people are connecting to.

play01:22

And you also need to take into consideration what happens if there's a power

play01:26

loss. If someone pulls the plug or something like that,

play01:28

you cannot afford to have your service go down because there's lots of people

play01:32

paying money for you. You should host your services on the cloud.

play01:36

So what's the difference between a desktop and a cloud? Nothing really.

play01:41

The cloud is a set of computers that somebody provides to you for money,

play01:45

of course. So if you pay a cloud solution, for example,

play01:50

Amazon Web Services, which is the most popular one, if you pay these guys,

play01:55

they're going to give you computation power.

play01:57

Computation power is nothing but a desktop that they have somewhere which can

play02:01

run your algorithm. How will you actually store your algorithm in that desktop?

play02:06

Well, you can do something like a remote login into that

play02:11

desktop. That's what the cloud is. It's a set of desktops,

play02:15

not necessarily desktops,

play02:16

but a set of computers that you can use to run your service.

play02:21

The reason we like to do this is because the configuration,

play02:23

the settings the reliability can be taken care of to a large extent by the

play02:28

solution providers.

play02:30

So now that we have our server hosted on a cloud,

play02:33

which is basically some computer that we don't know about,

play02:37

we can focus on the business requirements.

play02:41

What business requirements could we possibly have? Well,

play02:44

there's lots of people who are using algorithm now,

play02:49

and it gets to a point where the code that you have running on the machine is

play02:53

not able to handle all of these connections. So what do you do?

play02:58

One of the solutions is to buy a bigger machine, Right?

play03:03

This is solution number one. The solution number two is to buy more machines.

play03:10

The ability to handle more requests by buying more machines or buying bigger

play03:14

machines is called scalability.

play03:18

And this is a very important term that we need to understand. Well,

play03:22

like we said, we can handle more requests by throwing more money at the problem.

play03:27

When you're buying bigger machines,

play03:29

it means that your computer's going to be larger and therefore it can process

play03:32

the requests faster. So that is called vertical scaling.

play03:38

And when you're buying more machines,

play03:40

it means that the request can fall on any one of these machines and it'll be

play03:44

processed, but because you have more of them,

play03:46

the requests can be randomly distributed amongst the machines that you have just

play03:50

bought. And that is called horizontal scaling.

play03:54

These are two mechanisms by which you can increase the scalability of your

play03:58

system. Like we said, scalability is being able to handle more requests.

play04:03

Like any two approaches, we can compare them with the pros and cons.

play04:07

The first one that we have talked about is we need some sort of load balancing

play04:11

here. Well, that's not the case here.

play04:17

If you have a single machine, there's no load to balance as such.

play04:21

The second point is that with lots of machines,

play04:24

if one of the machine fails, you can redirect the request to the other ones.

play04:29

While over here, there's a single point of failure.

play04:32

So this is a single point failure and here

play04:37

it is resilient. The third thing to note is that

play04:43

all the communication that we have between the servers will be over the network

play04:47

and network calls us slow.

play04:48

It's io while over here you have interprocess communication.

play04:52

So that is quite fast. So here,

play04:55

there is interprocess communication.

play05:00

While over here we have network calls

play05:04

Between two services. So that is remote procedure calls.

play05:08

So this is slow and this is fast.

play05:11

The fourth point is data consistency. For example,

play05:15

let's say you are having a transaction where 3 cents some data to four and then

play05:19

4 cents it to five and 5 cents it to one.

play05:22

Here you see that the data is complicated to maintain.

play05:26

If there is a transaction where the operation has to be atomic,

play05:30

what could happen is that we have to lock all the servers, right?

play05:33

All the databases that they're using, which is impractical.

play05:36

So usually what happens is we have some sort of loose transactional guarantee,

play05:40

and that's, that's the reason why here, the data consistency is a real issue.

play05:47

While over here, there's just one system on which all the data rec resides,

play05:51

and that's why this is consistent.

play05:54

The final point deals with some hardware limitations that you're gonna have

play05:58

because we cannot just make the computer bigger and bigger and bigger and solve

play06:01

the problem. There's going to be some hardware limit that we have here.

play06:06

Point number five, and over here,

play06:08

this scales well in the sense that the,

play06:12

the amount of servers that you throw at the problem is almost linear in terms of

play06:16

how many users are added.

play06:21

These are the five key differences that vertical scaling and horizontal scaling

play06:24

have. So what do you think is used in the real world? Both.

play06:30

we take some of the good qualities of vertical scaling,

play06:32

which is really fast into process communication and the data being consistent.

play06:37

So the cache is going to be consistent. There's no dirty reads, dirty rights,

play06:41

so to speak.

play06:42

We take these two good qualities from here and we take these two good

play06:46

qualities from here, which is it scales well because the,

play06:50

there's a hardware limit over here and it's also resilient in the sense that if

play06:53

one of the server crashes, somebody else can come up. Okay?

play06:58

So the hybrid solution is essentially horizontal scaling only,

play07:02

where each machine has a big box.

play07:07

I mean each machine, you try to take as big a box as possible,

play07:10

as feasible money-wise. And then we,

play07:14

we pick up a solution this way.

play07:16

Initially you can vertical scale as much as you like later on when the users

play07:20

start trusting you, you should probably go for horizontal scaling.

play07:23

So these are the major considerations we have when designing a system.

play07:27

Is it scalable? Is it resilient? And is it consistent

play07:32

with these qualities? There's always gonna be some trade-offs that we have,

play07:35

and that's what system design is.

play07:37

We design a system which is going to meet the requirements,

play07:40

and the requirements are such that it's going to be Computer science way

play07:45

is possible to actually build a system like this.

play07:47

If you have any doubts or suggestions, you can leave them in the comments below.

play07:51

If you want notifications for further videos,

play07:53

hit the subscribe button and I'll see you next time.

Rate This

5.0 / 5 (0 votes)

関連タグ
System DesignScalabilityAPICloud HostingVertical ScalingHorizontal ScalingData ConsistencyLoad BalancingAlgorithm DeploymentComputation Power
英語で要約が必要ですか?