Hosting: The Network Infrastructure Serving a Website, Types of Hosting

Lecture



Hosting (from English “hosting”) – is a service that provides resources and infrastructure for hosting websites, applications or other online services. Hosting providers (or hosters) rent out servers or virtual servers on which you can host your website or application. Hosting allows websites and applications to be available on the Internet 24/7 without the need for your own infrastructure and support. Customers of hosting providers can choose various types of hosting depending on their needs, such as shared hosting, a virtual private server (VPS), a dedicated server, cloud hosting and others, more on this below.

The main components of hosting include:

  1. Servers: Hosting providers provide servers that supply computing resources, data storage and network connectivity for your website or application. Servers can be physical machines or virtual machines, depending on the type of hosting.

  2. Data storage: Hosting providers provide space for storing your website’s files, including HTML, CSS, images, video, databases and other resources. This can be represented as disk space on the server or through cloud data storage.

  3. Network connectivity: Hosting providers provide network connectivity for your website or application so that it is accessible on the Internet. This includes broadband Internet access, network infrastructure and security.

  4. Server management: Hosting providers provide tools and interfaces for managing your website or application on the server. This may include a control panel, FTP access, SSH access and other tools for managing files, databases, server settings, etc.

  5. Technical support: Hosting providers provide technical support to help resolve problems, configure the server or address security issues. This may include email, online chats, phone calls or ticket support systems.

Website infrastructure

So what exactly is virtual Apache hosting? It’s one big server with a fairly high “population” density, which makes it very cheap, accessible and mass-market. But because of this there are a number of problems lying in wait for the customer, many of which we managed to solve by introducing fourth-generation hosting.
You know in advance that you’ll have an authorization system and that you’ll need to store user information, so you need a database. Because of the limited budget, let’s place it on our single server. In the end we get the following infrastructure:

Hosting: The Network Infrastructure Serving a Website, Types of Hosting
Fig. 1

For now this is enough. In fact such a system can operate for quite a long time. The service is small, fewer than 10 visits a day. Perhaps even a small instance would have been enough, but we look at the company’s growth with optimism.

The value of the business — is in the database, so it’s very important. You need to make sure that if the server fails, you won’t lose data. It’s probably worth making sure the database contents aren’t stored on a temporary disk. After all, if the instance is deleted, you’ll lose your data. That’s a very scary thought.

You should also make sure you have backups on external storage. S3 seems like a good place for them, and relatively inexpensive, so let’s set that up too. And you definitely need to check that the backup works, by periodically restoring a backup copy.

Now the system looks roughly like this:

Hosting: The Network Infrastructure Serving a Website, Types of Hosting
Fig. 2

we improved the database’s reliability, and it’s time to prepare for “overload” by running a load test on the server. Everything seems fine, until 500 errors appear, followed by a stream of 404 errors, so you investigate what happened.

It turns out you have no idea what happened, because you were writing logs to the console and not redirecting the output to a file. You also see that the process isn’t running, so you can reasonably assume that’s exactly why the 404 errors are appearing. A wave of relief washes over you that you sensibly ran a local load test instead of triggering a real Habr effect as your test load.

You fix the auto-restart problem by creating a systemd service, and start a web server that simultaneously solves the log-writing problem. Then you run another load test to check.

And again we see 500 errors (fortunately, no 404s). You check the logs. It turns out the database connection pool is full, because a small limit of 10 connections was set. You update the limit, restart the DB and run the load test again.

Launching a production project or running a mass advertising campaign


Your service instantly becomes a hit. You get featured on the front page and receive 7000 views in the first 30 minutes — and you see the comments. What are they writing?

I got a 404 error, so I had to open the cached version of the page. Here’s the link, if anyone needs it: …

…

Nothing opens. Also, I have Javascript disabled. Why do people think I want to load their 2 MB of Javascript…

…

The homepage takes 4 seconds to load. A traceroute from Australia shows the server is located somewhere in Texas. Also, why does the first page load 2 megabytes of Javascript?


In a mad rush you set up Nginx as a reverse proxy for your application and configure a static 404 page there. You also change the deployment procedure to send static files to S3: this is needed for the CloudFront CDN to work, to reduce load times in Australia.

Hosting: The Network Infrastructure Serving a Website, Types of Hosting
Fig. 3

Having solved the most pressing problem, you go to the server and check the logs. Your SSH connection is unusually laggy. After some investigation you see that the log files have completely used up the disk space, which caused the process to crash and prevented it from restarting. You create a much larger disk and mount the logs there. You set up logrotate so the log files no longer grow to such sizes.

Infrastructure performance problems


Months go by. The audience grows. The site starts to slow down. You notice in CloudWatch monitoring that this happens only between 00:00 and 12:00 UTC. Because the lag starts and ends at the same time, you guess it’s related to a scheduled task on the server. You check crontab and realize one job is scheduled for midnight: backups. Of course, the backup takes X hours and overloads the database, causing a significant slowdown of the site.

You’ve read about this before — and decide to run backups on a subordinate database (slave). Then you remember: you don’t have a slave database, so you need to create one. It doesn’t make much sense to run the slave database on the same server, so you decide to expand. You create two new servers: one for the master database and one for the slave database. You change the backup process to work with the slave DB.

Hosting: The Network Infrastructure Serving a Website, Types of Hosting
Fig. 4

Growing the team


For a while everything goes smoothly. Months go by. You hire developers. One of the newcomers introduces a bug that takes down the production server. The developer blames the development environment, which differs from production. There’s some truth in his words. Since you’re a reasonable person with a good temperament, you take this event as a lesson.

It’s time to create additional environments: staging, QA and production. Fortunately, you automated infrastructure creation from day one, so everything goes smoothly and simply. You’ve also had good continuous delivery practices in place from day one, so you easily assemble a pipeline from the new branches.

The marketing department insists on releasing version 2.0. You don’t quite understand what 2.0 means, but you agree. It’s time to prepare for another traffic surge. You’re already close to the peak on the current server, so it’s time for load balancing. Amazon ELB makes this easy. Around this time you notice that the multi-tier diagrams in this article should show the layers top to bottom, not left to right.

Hosting: The Network Infrastructure Serving a Website, Types of Hosting
Fig. 5

Confident that you can handle the load, you advertise the site. Wonder of wonders, it holds up under the traffic. Big success!

Everything seemed to go well, until you went to check the logs. Checking 12 servers took an hour (four servers in each environment). A real nerve-wracking ordeal. Fortunately, there’s enough money to buy the ELK stack (ElasticSearch, LogStash, Kibana). You deploy it and point all the servers from every environment there.

Hosting: The Network Infrastructure Serving a Website, Types of Hosting
Fig. 6
You notice similar suspicious entries in the DB servers’ logs and wonder how they even got connected to the internet. It’s time to implement public and private subnets.


Hosting: The Network Infrastructure Serving a Website, Types of Hosting
Fig. 7

Web hosting architecture on your own servers

The following types of hosting are distinguished:

  • Shared Hosting — the cheapest way to host a site on the internet. This service includes access to a server with pre-configured software for a specific stack, for example Linux + PHP + MySQL. This method is suitable for the simplest sites and requires minimal configuration.
  • VPS/VDS — the most balanced service, under which a virtual machine is provided. The advantage is that this type of hosting lets you make use of more server resources: CPU, memory and disk. There’s no pre-installed software, everything has to be done yourself. Compared to shared hosting you’re not limited in your rights and can configure the server however you like.
  • Dedicated Server — a server (either your own or rented). This type of hosting requires the most involvement, but in return you get the best performance-to-price ratio.
  • IaaS (Infrastructure as a Service) — infrastructure as a service. A type of hosting in which most of the capabilities are provided as a service. Amazon Web Service (AWS) is an example.
  • PaaS (Platform as a Service) — platform as a service. The most expensive and most automated out-of-the-box way to host sites. Deployment of the site happens literally with the command git push. Besides price, it’s important to consider the technologies and approaches used. PaaS has the largest number of restrictions on what and how you can do things, but in exchange you get not just automated hosting, but a platform that automatically “scales” under load.

Let’s start with the architecture of classic hosting:
Hosting: The Network Infrastructure Serving a Website, Types of Hosting
We have several web servers, a separate database server and a management system responsible for the configuration of the web servers, all simple, everyone knows about it.
Our new hosting has a cluster architecture:
The main components include load balancers, Linux web servers (with Apache), Linux database servers (with MySQL or PostgreSQL) and NFS servers. The overall diagram is shown in the figure below.

Hosting: The Network Infrastructure Serving a Website, Types of Hosting
And all the interesting stuff is inside:

Hosting: The Network Infrastructure Serving a Website, Types of Hosting

Load balancers:

  • They serve to provide high fault tolerance, dynamic load redistribution and seamless resource management;
  • Direct routing is used – any web server can respond to requests for any IP;
  • Persistent sessions are used for effective caching.



Web servers:

  • Each web server can handle requests for any site, there’s no binding of a site to a web server;
  • Web servers also handle FTP and SSH connections;
  • The web servers run the Cloud Linux OS, which supports LVE (Light Virtual Environment) technology, which allows strict isolation of individual sites from one another.



Data storage servers:

  • Clients using MySQL are served by several servers;
  • NFS3 file systems are used to store site content;
  • All file systems are mounted on all web servers.



Configuration database and management module:

  • The configurations of all sites managed by the web cluster system are stored in a central configuration database on a separate server;
  • The module’s cache service for providing shared hosting is used to retrieve site configuration data; this service caches the data in RAM, and removes it if it changes in the configuration database;
  • The cache service automatically switches to the replica server if the main configuration database is unavailable.

Main differences and advantages of the hosting.

1. Security.


In classic hosting, client sites on the same server are not isolated from one another, which creates security holes if there’s a malicious neighbor, or if a neighbor’s site is compromised. Also, if a neighbor is under a DDoS attack, or simply under a heavy load — everyone suffers.

In our old hosting we solved the problem of an increased number of requests (which often becomes just as acute a problem as DDoS attacks. yep, hello Habr effect) by installing an Nginx frontend on each group of web servers, which acts as a filtering proxy, allowing us to balance the load on sites within a single server. But the isolation problem remained, all sites work with PHP as an Apache module, and still live in a single shared space. That’s sad.

What about this part in our new hosting? First, it has a different architecture, representing a cluster, where the load is evenly distributed among the web servers. We use PHP through FastCGI, which gives us different UIDs for all webspaces, this is already good and secure. And it’s also very cool that each webspace — is an LVE (Light Virtual Environment), a small virtual machine, where all scripts run isolated from other webspaces in their own virtual space, which is allocated certain memory and processor time resources. All this — thanks to the Cloud Linux distribution:
Hosting: The Network Infrastructure Serving a Website, Types of Hosting
And on top of all that, you can also use Nginx. So security in the new hosting is great.

2. Stability


Stability of hosting is affected by the problems described in the previous point. All users are stewing in the same pot and using shared resources. Stability is also threatened by the fact that any system is prone to breaking, because due to hardware or software problems (say, the Apache daemon crashed) all residents of the problematic server are left without hosting, that’s terrible, isn’t it?

With our old hosting it’s all the same — shared resources, shared memory and processor time, that’s the price for the architecture – no matter how you look at it. But we overcame the hardware problem by virtualizing all our servers, specifically they are placed in Parallels Virtuozzo containers. This is great, because if a server needs to be scaled up and given more resources, or hardware maintenance needs to be performed — we simply move the container to a more powerful server without any site downtime. But if a software problem occurs inside the container (well, who hasn’t had that happen?) everyone is left without hosting while the technical department fixes the error, such things, if they happen, only last a few minutes, but it’s still unpleasant for customers. They have a business, clients, visitors, who will be upset if their site goes down even for a few minutes.

The new hosting outperforms everyone here. LVEs, mentioned in the previous point, give clearly limited resources to each webspace, what the client wanted — they get, and they can’t squeeze out their neighbors on the server, neither on the processor nor on memory – this approach is already closer to VPS than to shared hosting. Also, thanks to the cluster architecture, if one of the frontends goes down (they can be scaled horizontally as much as you like), all requests get distributed among the other frontends. That is, even if hardware or software fails on one of the web servers — the balancer instantly removes the problematic server from the cluster and redistributes the load among the remaining servers, and the client will never know that trouble happened on one of the servers. This solution, thanks to its full autonomy and automation, makes the new hosting cheaper for us and as a result for you. As a result we spend more time on new interesting things and ideas.

3. Convenience and speed

  1. Fourth-generation hosting is more convenient and pleasant for the end user in several respects:
  2. Client files belong to the same UID as the files created by the web server. This eliminates frequent inconveniences, it’s easier to install CMS systems, for example it’s easier to install plugins and themes for Wordpress, since the Wordpress interface doesn’t require specifying an FTP password, etc.
  3. Apache now runs in MPM Worker mode. Static requests are served faster in this mode. Content delivery speed will improve for most sites.
  4. Do you need more resources but don’t want to move to a VPS? It’s easy to allocate more memory or processor time, giving us excellent scalability.

Brief summary of everything above:


Pros:
Hosting: The Network Infrastructure Serving a Website, Types of Hosting “Fair” resource division, each site is assigned resources it cannot exceed
Hosting: The Network Infrastructure Serving a Website, Types of Hosting Security, all sites run in separate LVEs and are isolated
Hosting: The Network Infrastructure Serving a Website, Types of Hosting Fault tolerance and stability, cluster architecture.
Hosting: The Network Infrastructure Serving a Website, Types of Hosting Scalability, the management database can change your site’s allowed resources “on the fly”
Hosting: The Network Infrastructure Serving a Website, Types of Hosting Speed, Apache runs in MPM Worker mode.

Cons:
Hosting: The Network Infrastructure Serving a Website, Types of Hosting There may be problems with FastCGI mode PHP for sites written in the early part of the last decade. However, practically all modern engines and CMSes support it natively and painlessly.
Hosting: The Network Infrastructure Serving a Website, Types of Hosting Due to the isolation of sites, no one will constrain your rights to resources, but on the other hand your site won’t be able to get more resources than it’s been assigned.

Hosting: The Network Infrastructure Serving a Website, Types of Hosting

Hosting: The Network Infrastructure Serving a Website, Types of Hosting

Figure, example architecture of the servers of a large system

See also

  • [[b5820]]
  • [[b8703]]
  • [[b11050]]
  • [[b11062]]
  • [[b5894]]
  • [[b5895]]
  • [[b889]]
  • [[b8]]
  • [[b9]]
  • [[b6486]]

See also

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Highly loaded projects. Theory of parallel computing. Supercomputers. Distributed systems"

Terms: Highly loaded projects. Theory of parallel computing. Supercomputers. Distributed systems