Sub topic 9
Choosing a Kind of Web Hosting
This chapter assumes you know what an IP address is, how an A record maps a name to an address, and how to run commands in a terminal. You don't need to have rented a server before. By the end you should be able to compare the main hosting models, predict how each one affects your DNS records, and pick one for a given site.
What a host provides
A web host is a computer, or a slice of one, that is connected to the internet and runs software that answers HTTP requests. DNS only tells a browser which IP address to contact. The host is what answers at that address.
Hosting types differ in three things:
- Who manages the machine. This covers the operating system, security patches, and the web server software.
- How resources are shared. CPU, memory, disk, and network can belong to you alone or be split among many customers.
- How your code gets there. You might upload files by FTP, log in over SSH, or push to a Git repository.
More control usually means more work. Less work usually means less control. Every option below sits somewhere on that line.
Shared hosting
On shared hosting, one server runs hundreds or thousands of customer sites. Each customer gets a directory, a control panel such as cPanel, and often a one-click installer for WordPress. The provider manages the operating system and web server.
Many sites share one IP address. The web server tells them apart using the Host header in each HTTP request, which is called name-based virtual hosting. For HTTPS, the browser sends the hostname during the TLS handshake in a field called SNI (Server Name Indication), so the server can pick the right certificate.
Strengths:
- It is cheap, often a few dollars a month.
- There is almost no server administration.
- Email hosting is often bundled in.
Weaknesses:
- Neighbors affect you. A busy or compromised site on the same server can slow yours down. This is the "noisy neighbor" problem.
- You can't install arbitrary software or change server settings.
- The IP address may change if the provider moves your account. Your A record then points at the wrong place until you update it.
Virtual private server (VPS)
A VPS is a virtual machine on a larger physical host. A hypervisor, which is software that divides one physical machine into several virtual ones, gives you a guaranteed share of CPU and memory. You get root access, so you install what you want. You are also responsible for updates, firewalls, backups, and monitoring.
A VPS normally comes with a dedicated IPv4 address, and often an IPv6 address too. That makes it a good fit when you need to run your own mail server, a database, a background worker, or an unusual runtime.
The main risk is neglect. An unpatched VPS is a common source of compromised sites. Budget time for maintenance, not only the monthly fee.
Dedicated server
A dedicated server is a whole physical machine rented to you. Nothing is shared, so performance is predictable and you can tune hardware, disks, and network settings. It costs the most and takes the most skill. A hardware failure is your problem unless the provider offers replacement guarantees. Choose it when a VPS can't meet your load, you have strict compliance rules about isolation, or you need specific hardware such as GPUs.
Static site hosting
A static site is made only of files (HTML, CSS, JavaScript, images) that are served as they are. There is no server-side code running per request. Static hosts, including object storage with website mode, put those files on a content delivery network (CDN). A CDN is a set of servers in many locations that serve copies of your files from near the visitor.
Strengths:
- It is very fast and often free or nearly free.
- There is little to attack, because no code runs on the server and there is no database to breach.
- Scaling is handled for you.
Weaknesses:
- Anything dynamic, such as logins or form handling, must come from an outside API or a serverless function.
- Content changes mean rebuilding and redeploying the site, usually from a Git push.
Static hosts often don't give you a fixed IP address. They ask for a CNAME to a hostname they control, because their IP addresses change as they rebalance traffic.
Platform-based hosting
Platform hosting, also called a Platform as a Service (PaaS), runs your application for you. You push code or a container image. The platform builds it, starts it, restarts it if it crashes, and adds more copies when traffic grows. Examples include Heroku-style services, managed app platforms from the large cloud vendors, and managed WordPress or e-commerce platforms.
Strengths:
- You skip operating-system work and get deploys, logs, and scaling.
- It suits teams who want to write code, not run servers.
Weaknesses:
- Cost grows quickly with traffic and number of instances.
- You depend on the platform's supported languages, limits, and pricing. Moving away later takes real work. This is called lock-in.
- Like static hosts, platforms usually give you a hostname to alias, not a stable IP address.
Comparing the options
| Type | You manage | Isolation | Typical IP | Best fit |
|---|---|---|---|---|
| Shared | Files and content | Low | Shared, can change | Small brochure site, blog |
| VPS | Whole OS and software | Medium | Dedicated, stable | Custom stack, small apps |
| Dedicated | Whole OS and hardware | Full | Dedicated, stable | High load, compliance |
| Static | Files and build | Not applicable | Hostname, no fixed IP | Docs, portfolios, marketing sites |
| Platform | Application code | Medium to high | Hostname, no fixed IP | Web apps with a team |
How the hosting type shapes your DNS records
The previous chapters covered A, AAAA, and CNAME records. The hosting type decides which one you use.
- A host that gives you a fixed IP (VPS, dedicated, some shared plans) means an A record, plus an AAAA record if you have an IPv6 address.
- A host that gives you a hostname (most static and platform hosts) means a CNAME for
www. - The bare domain, called the apex, can't hold a CNAME beside the SOA and NS records that must exist there. Hosts that only give you a hostname need a workaround. Some DNS providers offer ALIAS or ANAME records, or CNAME flattening, which resolve the target on the server side and answer with A records. Otherwise you redirect the apex to
www. - Shared IPs make the A record fragile. If the provider migrates you, ask for the new address and update the record.
You can check how the host looks from DNS with the commands from the dig section:
dig example.com A +short
dig www.example.com CNAME +shortIf www returns a hostname rather than an address, the host expects you to alias it. If the A record shows an address, you can find out whether the address is shared by testing other domains, as in this script:
import socket
from collections import defaultdict
names = ["example.com", "example.org", "example.net"]
by_ip = defaultdict(set)
for name in names:
try:
infos = socket.getaddrinfo(name, 80, family=socket.AF_INET, type=socket.SOCK_STREAM)
except socket.gaierror as err:
print(f"{name}: lookup failed ({err})")
continue
for info in infos:
by_ip[info[4][0]].add(name)
for ip, hosts in sorted(by_ip.items()):
print(ip, "->", ", ".join(sorted(hosts)))Replace the three names with domains you want to compare. If two unrelated names print under one IP, the server tells them apart with the Host header. A CDN or a shared host can produce this result, and the script can't tell which.
A decision path
Trade-offs and edge cases
Cost is not only the monthly fee. A cheap VPS needs your time for patches and backups. A free static host has limits on build minutes and bandwidth. A platform's free tier may put your app to sleep after inactivity, so the first request is slow.
Mixing types is normal. A common layout is a static marketing site at example.com, an application on a platform at app.example.com, and a mail provider for MX records. Each subdomain gets its own record pointing to its own host. DNS makes this easy.
Traffic spikes. Shared and single-VPS setups have a fixed ceiling. Static hosts and platforms scale more easily. A CDN placed in front of a VPS or shared host can absorb read-heavy spikes.
Migrations depend on TTL. Before moving to a new host, lower the record's TTL a day or more ahead. Then switch the record, and keep the old host running until caches have expired. Your record's old TTL is the longest wait for any resolver that cached it.
Backups and exit plans. Shared hosts may include backups, but you shouldn't rely on that alone. On a VPS or dedicated server, backups are yours. On a platform, check how you export data and configuration.
Location. A server far from your visitors adds delay to every request. Pick a region near most of your users, or use a CDN.
Exercise
Exercise
A small bakery wants a five-page website with opening hours and a menu, changed a few times a year by one person who knows only basic HTML. The owner wants the lowest cost and the least maintenance. Which hosting type fits best, and which DNS record will you probably need for www?
Show answer
Static hosting fits best, since the pages are fixed files with no server-side code, and it is cheap or free and needs no server maintenance. Static hosts usually give a hostname to alias, so www will probably be a CNAME to that hostname. The apex may need an ALIAS/ANAME record, CNAME flattening, or a redirect to www. Shared hosting would also work, in which case an A record to the host's IP address would be used.
Exercise
A startup runs a Python API and a background job queue. Two developers do not want to administer servers. Which two hosting types are the strongest candidates, and what is the main downside of each?
Show answer
Platform-based hosting is the best fit, with the downside of rising cost and lock-in to the platform's limits. A VPS is the other candidate, because it allows any runtime and queue software, but the developers must patch, secure, and back up the server themselves, which they said they don't want to do.