In this lesson,
we will learn about scaling considerations.
Scalability is measured by the number of requests
an asset or server can effectively support simultaneously.
When the system or application
can no longer handle additional requests,
you have found the limits of that system's scalability.
In traditional networks and servers,
this occurs due to the limitation of processing capacity
or the amount of physical memory the machine has,
or even the amount of network bandwidth that is available.
Now, if you begin to run out of resources
when trying to support requests from users,
then you need to scale up
or scale out to increase those resources
and be able to support the additional requests.
Scaling up is known as vertical scaling.
Scaling out is known as horizontal scaling.
Let's take a look at each of these.
Vertical scaling refers to adding more resources,
such as more processing power, more memory, more storage,
or more bandwidth to your existing machine.
For example, in my laptop, I have 16 gigabytes of RAM.
Now, if I find the system starts slowing down
when I open really large files,
I may need to increase my available memory,
and I could do this by adding additional RAM
to bring my total amount up to 32 gigabytes of RAM.
This is a really simple example
of scaling up or using vertical scaling.
Vertical scaling is very popular
in traditional systems and networks,
and it can also be done when you're using cloud services.
For example, let's pretend
that you're going to start a new blog
and you decide to use a simple cloud solution
like AWS Lightsail to host that blog.
Well, you might start out with the $5 per month plan.
This plan might have one gigabyte of memory,
a single core processor, 40 gigabytes of disc space,
and two terabytes of data transfer each month.
Now, over time, your blog gains more readers
and you realize that you need to scale up
or scale vertically.
So, you click a button
and you upgrade to the $20 per month plan.
This gives you four gigabytes of memory
instead of that one gigabyte of memory,
increases your data transfer allowance,
and doubles your processing power and disk storage space.
This is vertical scalability or scaling up.
Now, you can keep scaling up vertically
until you reach the largest plan size.
And let's say that plan gives you 32 gigabytes of memory
and 8 core processor, 640 gigabytes of disk space,
and 7 terabytes of data transfer per month.
So, what do you do when you can't vertically scale anymore?
Well, you're going to need to re-architect your website
to allow for horizontal scaling, also known as scaling out.
Horizontal scaling is not as easy
as just adding more resources.
Horizontal scaling forces you
to break down your workloads into smaller pieces of logic
that can be executed in parallel across multiple machines.
For example, if you are using a database
to run your website, horizontal scaling will allow you
to partition the data across multiple databases,
so that each database only contains some of that whole data.
So, let's think back to that blog.
You might have a collection of thousands
of different articles split across multiple servers,
one server for each year of articles that you wrote.
So, when somebody wants to read one of those articles,
the request will get answered by the corresponding server
and database based on the year
of the article that was requested.
This is a good example
of breaking down a workload into smaller pieces.
Once workloads are broken down into smaller pieces,
scaling out can occur.
In general, scaling out is better for the long-term,
because adding an individual machine
is cheaper than adding resources to a single machine.
Also, scaling out is virtually limitless,
because you can keep adding smaller, inexpensive machines
to meet the increasing workload
that's being caused by additional users and their requests.
By focusing on horizontal scaling,
your resources become infinitely elastic,
and the only limit becomes your ability to pay
for cloud computing time from your cloud service provider.
By using horizontal scaling in this manner,
you can have instant and continuous availability,
no limit to hardware capacity,
cost that's going to be assessed
on a per use basis in the cloud,
built-in redundancy, and it's going to be easier to size
and resize your infrastructure to meet your needs.
But the challenge with horizontal scaling
is that you first need to design your applications
to work in smaller self-contained blocks
that interact to create the results you need.
To do this, your application
must be designed as a stateless application.
Stateless applications do not store any session data
or information about the user's interactions
on the server itself.
Instead, each request from a user is treated independently
with no reliance on previous requests.
This design allows an application
to be easily distributed across multiple servers
as no server
needs to retain information about user sessions or state.
Additionally, if there is any necessary session data,
it can be stored externally in a database or cache,
allowing any server
to access that session data and handle a request.
This makes horizontal scaling much simpler,
because you can add or remove servers
without disrupting the user experience
or losing important session data.
So, remember, scalability refers to the ability
of a system to handle increasing demand
by effectively managing resources.
Vertical scaling or scaling up
involves adding more resources such as memory
or processing power
to a single machine to improve its capacity.
However, vertical scaling has limits,
and once those limits are reached,
horizontal scaling or scaling out becomes necessary.
Horizontal scaling involves spreading workloads
across multiple machines
and typically involves designing applications
to be stateless, meaning that each request
is handled independently
without relying on previous interactions.