Skip to content

4. What a VPS Actually Is

“Somebody else owns the building. You still have to lock the door.”

The phone buzzed at 2:14 in the morning, face down on a nightstand in Pune. The message was three words long: “site is down again.” If you have ever run a production app, you know that tone. It is not angry. It is the tone of someone who has already refreshed the page twice.

The app, a composite of a few real nights, was a Next.js site on a small VPS. The VPS was up. You could reach it, SSH logged in, and the domain pointed at the right address. But the page returned a 502 from nginx, the reverse proxy standing in front of the app, and the logs said almost nothing. The Node process was not running. It had not crashed with a stack trace. It had quietly stopped, as if someone had walked in and switched it off.

Someone had, in a sense. The machine had 1 GB of RAM and no swap. At around two in the morning a nightly job began importing a large CSV of ticket sales. The Node process grew past what the machine could hold, and the Linux kernel picked a victim and ended it. The kernel did not send a letter. It killed the process and moved on, and the only trace was a single line in a log nobody had opened since the day the server was built.

What made it feel cursed was that the same job had run fine on the developer’s laptop. The laptop has sixteen gigabytes and a generous temperament. “Works on localhost” is the most expensive sentence in web development, and the VPS is where the bill arrives.

Notice what was not broken. DNS was fine. The certificate was fine. The route was fine, and the door was open. The failure showed up at the very end of the chain, in the App step, but the cause sat underneath it, in the machine that holds the app, and in a decision made months earlier about how much memory that machine would have. Fixing that kind of problem means knowing what a VPS really is, what the provider has promised you, and what you have quietly promised yourself.

You have walked this chain before, in Book 1 and in the first three chapters of this one. From here on we will write it the same way every time:

Name → Address → Route → Door → Guard → Receptionist → App

The 2 a.m. failure happened at App. The reason lived lower down. This chapter is about the floor beneath App, the machine itself, and about who is responsible for each part of it.

Start at the bottom, with a physical server: a grey box with cores, RAM, disks and one network card. For a long time one of those boxes ran one operating system, and that operating system ran one important thing. It worked, and it wasted most of the machine. A modern server CPU has dozens of cores, and a single web app uses a sliver of them.

The fix is a hypervisor, a thin layer whose only job is to carve one machine into several and let each piece believe it owns a whole computer. Each piece is a virtual machine, or VM. It runs its own kernel, sees its own disk and its own network card, and never touches the real hardware. Only the hypervisor does that.

Most cloud providers run KVM on Linux, which turns the Linux kernel itself into a hypervisor. The CPU you rent is a vCPU: a time slice the hypervisor schedules onto a real core on your behalf. When the plan says “2 vCPUs”, you are promised a share of real cores, not two cores you can point at.

That share is where the trouble lives. Providers sell more vCPUs than the host has cores. This is overselling, and it works because not every tenant wants full speed at the same moment. Most days the bet pays. Then one afternoon a neighbour starts a backup or a large build, and your steady machine slows down for reasons nothing in your dashboard explains. Those neighbours are called noisy, and the name is earned. It is also why a benchmark run once tells you very little.

So what is a VPS? A virtual private server is a VM that someone else runs on hardware they own, rented to you by the month, with a control panel and an API bolted on. The marketing says “private server”. The honest description is “a small virtual machine, sliced from a bigger one, whose hypervisor you will never see.”

One physical server running a hypervisor and three virtual machinesThree virtual machines sit on a hypervisor layer, which sits on one physical server. Your VPS is the left-hand machine.Your VPSown kernel, own disk2 vCPU sliceNeighbour VMown kernel, own diskbusy at 3 a.m.Neighbour VMown kernel, own diska Windows boxHypervisor (KVM): hands out slices of CPU, RAM and diskPhysical server: real cores, RAM, disks, one network card
Figure 4.1. One physical server, sliced. Only the hypervisor touches the hardware.

A container looks like a VM from the outside. It has its own filesystem, its own list of processes, its own hostname. Inside, though, there is no second kernel. A container is an ordinary Linux process fenced in with namespaces, which control what it can see, and cgroups, which control how much it can use. Every container on a host shares that host’s kernel.

That one fact explains most of what you will read about Docker. Containers start in well under a second and pack densely, because there is no second operating system to boot or pay for. The cost is isolation. A VM boundary is enforced by the hypervisor, which exposes a narrow set of hardware-shaped doors. A container boundary is enforced by the shared kernel, which exposes a very wide set of system calls. Both are strong. They are not equally strong, and the difference matters on the day someone publishes a kernel bug.

For your own stack, the sensible shape is a VM you control with Docker Compose inside it. You get containers for packaging and a whole machine for isolation. We come back to running that shape day to day in Chapter 19.

Containers share one kernel while virtual machines each carry their ownTwo stacks side by side. The virtual machine stack has its own guest kernel above a hypervisor. The container stack has no guest kernel and sits on a host kernel that every container shares.Virtual machineContainerApp AGuest kernel (its own copy)HypervisorHardwareApp A and App BContainer runtimeHost kernel, shared by allHardware
Figure 4.2. Containers share one kernel. Virtual machines each carry their own.

Who carries which layer: the hosting spectrum

Section titled “Who carries which layer: the hosting spectrum”

In Book 1 you met hosting as a shopping list. Read it again from the seat you sit in now. The question is not “what is cheapest” but “which layers am I carrying, and which ones have I handed over”.

Shared hosting gives you a folder on a machine full of other people’s folders. You upload files, and the provider’s web server decides how they run. You own your site and almost nothing else. It is the cheapest seat in the house, and it is the one where a neighbour’s runaway script can make your page crawl with no way for you to fix it.

A VPS gives you the operating system. You own everything from the kernel upward: the patches, the firewall, the database, the mistakes. This is the seat this book is about.

Dedicated hardware gives you the whole physical box, with no hypervisor between you and the metal. The performance is steadier, and the software you own is the same as on a VPS. The price follows the hardware, and the datacentre still owns the power, the cooling and the cable.

PaaS (Platform as a Service) is where Vercel, Render and Railway sit. You hand over code and a little config, and they run the operating system, the runtime, the routing and most of the scaling. You patch less. Their rules become your rules: build minutes, memory per instance, what may run in the background.

Serverless and edge go one step further. You hand over a function, and the platform decides where it runs, how many copies exist, and when they sleep. Edge platforms run the same function in many cities near the visitor. It is cheap when idle and surprising when a cold start lands on a checkout page.

The cloud vendors have a name for the split between the two sides: the shared responsibility model. The provider secures the thing that runs your code. You secure the code, the data, the access rules and the configuration. Move up the spectrum and the provider’s side of the line grows. Your data and your access rules never move to their side. That is the part people forget when they choose a platform to save an afternoon.

Five hosting models and who runs which layerFive columns: shared hosting, VPS, dedicated, PaaS and serverless. Each has a teal band of what you run and a blue band of what the provider runs.SharedVPSDedicatedPaaSServerlessyour files,your siteOS, app,patches, TLSthe whole box,all of ityour code,your configyour functions,your dataserver, OS,PHP, the resthardware,hypervisorrack, power,uplinkOS, runtime,routing, scaleservers,scaling, patchingTeal = you run it. Blue = they run it. Your data stays teal everywhere.
Figure 4.3. Each step up the spectrum moves a layer from your pile to theirs.

Open the console of any big cloud provider and click “Create instance.” Within a minute you are asked about an image, a shape, a boot volume, a network, a subnet, an SSH key, and a block of YAML nobody reads. It looks like a form with too many fields. It is really a floor plan, and every field is a room.

Let’s walk the rooms, mapping each one onto the city so it sticks.

The image is the prefabricated floor plan. It is a disk that already has an operating system installed, Ubuntu 24.04 in our lab. Picking an image decides what the house is built from. It does not decide the furniture you bring later.

The boot disk is the foundation and the ground floor in one. It holds the operating system and everything you install on it. Read the “delete boot volume when instance is terminated” checkbox twice before you click anything, because that option decides whether deleting the instance also deletes the house.

Block volumes are detachable storage sheds. You attach them over the network, format them, and mount them at a path such as /data. They survive the instance being rebuilt, which is why a database’s data directory often lives on one when you want the data to outlast the machine. Measure before you trust one: latency and snapshot behaviour differ from the boot disk.

Snapshots are photographs of a disk at one moment. They are your undo when a package upgrade goes wrong at midnight. A snapshot kept in the same building is not a backup, though. A backup is a copy that survives the building burning down, and we come back to that in Chapter 19.

Public and private IPs. The public IP is the street address the internet can see. The private IP, such as 10.0.0.5 in our lab, is the address inside your own private network. Traffic from the internet hits the public address. Traffic between your own machines uses the private one.

The VCN or VPC. Oracle calls it a virtual cloud network. Most others call it a virtual private cloud. It is the gated colony’s internal roads: a private address range, subnets, route tables, and a gate to the outside. The provider builds the roads, and your instance lives on one of them. The default network is usually fine until the day it isn’t.

Security lists and security groups are the guard with the clipboard. Each rule says which door numbers are open to which sources, for example “allow TCP 22 from my home IP, allow TCP 443 from anywhere.” Oracle calls the rule set a security list and applies it to a subnet. AWS calls it a security group and applies it to an instance. The names differ, the job does not. Hold that thought, because Chapter 14 gives the guard a second clipboard.

Console access is the back door with its own key. We cover it in the callout below, because it is the one thing people discover too late.

Cloud-init is the moving-in checklist. It is a YAML file you hand the instance as user data, and it runs once, on first boot. It can create the user ops, install your SSH public key, set the hostname to lab, and install packages. Chapter 6 writes one properly.

Every piece above is a layer in the chain you already know: Name → Address → Route → Door → Guard → Receptionist → App. The public IP is the Address. The security list is the Guard. The port is the Door. The image and cloud-init decide what the Receptionist and the App are.

Anatomy of a cloud VPSThe internet reaches a security list, which admits traffic into a virtual cloud network holding an instance with a boot disk and a block volume. A console path reaches the instance directly, bypassing the network.The rooms you touch on day oneInternetuntrustedpublic IP203.0.113.10Security listallow 22, 80, 443VCN: your private streetsInstance10.0.0.5boot diskblock volumeconsole (lifeline)The console talks to the VM through the hypervisor, not through the network.
Figure 4.4. The rooms you touch on day one, and the back door that does not need the network.

You can run the lab on almost any company that rents you a Linux machine with a public address. Choosing one is like choosing a flat in Pune: the rent matters, but so do the neighbourhood, the landlord, and what happens at midnight when the water stops. Here is the shortlist I would give a friend, as of the mid-2020s. Every number is a hedge, so check the live pricing page before you click anything.

  • Oracle Cloud, Always Free. The most generous free offer, if memory serves: Arm (Ampere) compute, roughly 4 OCPUs and 24 GB of RAM across the free allowance, plus some block storage. The fine print is the interesting part.
  • Hetzner. Cheap, fast and dull in the best way. Excellent value in Europe, and a Singapore location if you want Asia nearby. No Indian region, so the round trip from Pune is longer.
  • DigitalOcean. Droplets with a Bangalore region, a clear console, and predictable pricing at a slightly higher price per gigabyte than Hetzner.
  • AWS Lightsail. A fixed-price VM with a simpler console than full EC2, and a Mumbai region. Pick it when you already have an AWS account and want the bill to stay boring.

Platform services like Render, Railway and Vercel are not on the lab list, because they hand you an app rather than a machine. Ch 19 comes back to their trade-offs.

The region rule is simpler than the price rule: put the machine near the people using it, not near you. A Mumbai or Hyderabad region is tens of milliseconds from Pune. A European region can be well over a hundred. You will not feel that on one request. You will feel it on a page that makes forty small ones.

Oracle’s free tier is the best deal here and the most sharp-edged. Three things will bite you.

It is Arm. Ampere instances are arm64, not the amd64 your CI may build for. Most popular images are multi-architecture now, so pulling a public image usually picks the right one. A custom image built on an x86 runner will fail with an “exec format error”, and that error is about the CPU, not your code.

It reclaims idle machines. Oracle’s Always Free rules say that instances which sit almost idle for a long stretch can be stopped and reclaimed. I have heard that threshold described as about a week of very low CPU and network use, but treat that as a widely told story until you read the current policy. The lesson holds either way: a box that does nothing can vanish. Keep the lab busy, and snapshot anything you care about.

Its firewall is double. The VCN has a security list (or a network security group) at its edge, and the Ubuntu image ships its own iptables rules. On the images I remember, those rules allow SSH and drop nearly everything else. Open port 3000 in the console and the packet still meets the second guard. Ch 14 takes both apart properly.

Everyone asks how big a box they need, and most people ask about the wrong number first. CPU sounds like speed, so it gets the attention. For the stack you are running, the number that decides whether you sleep well is RAM.

Here is the usual shape of a small production box for a Next.js app and a Postgres database. The Node process for a modest Next app sits at a couple of hundred megabytes, and it grows under traffic and during a build. Postgres wants a generous cache and spends a few megabytes on every open connection. Docker adds its own overhead on top. None of these numbers is alarming alone. Together, on one gigabyte, they leave almost no room for the moment you did not plan for.

That moment is usually a build. Running next build on the server itself is the classic trap, because the build can briefly need more memory than the running app ever will. A small box that runs happily for months can fall over the first time you deploy from it.

One gigabyte of RAM divided among its tenantsA long bar for one gigabyte. Slices for the operating system, the Node app and Postgres fill most of it, with a thin strip of free space at the end. A red arrow past the right edge shows a build that needs more than the box has.one gigabyteOS, ~150 MBNext app, ~200 MBPostgres, ~300 MBfreebuild wants moreRough, illustrative numbers. The point is the proportions.Free space is the first thing a spike takes. After that, the kernel has to choose.
Figure 4.5. One gigabyte, shared out. Under a spike, the free strip disappears first.

Swap is the next idea. Swap is disk pretending to be RAM. When memory runs short, the kernel moves rarely used pages out to a file on disk and brings them back when they are needed. Disk is far slower than memory, so a box that is swapping feels sluggish, but it is still alive. Think of swap as a seatbelt, not a second engine. A modest swap file is a sensible safety net on a small box, and it buys you time to notice a problem. It does not fix one.

The OOM killer is the part nobody warns you about. When the kernel has run out of memory and swap, it picks a process to kill, usually the greediest one, and it does not ask. The out-of-memory killer is the silent assassin of small servers. Your app gets no polite error. It just stops. The app’s log may end mid-sentence, and the kernel’s own log records the kill, if you think to look there.

Here is the goal. You will rent one small machine, look at what the provider handed you, and then do something careless on purpose: you will start an app on every address the machine has, and then you will knock on its public door from outside. The result will teach you more about the guard than any diagram can.

Laptop reaches a lab VPS across the internet past a guardA laptop at home sends a request across a cloud labelled the internet. A guard stands between the cloud and a box on the right, which has a public address and a private address. A door numbered 3000 is drawn open by mistake, and the request has to pass the guard to reach it.Your laptophome 192.168.1.7behind your routerthe internetThe lab VPSpublic 203.0.113.10private 10.0.0.5app on port 3000the guard203.0.113.10:3000The guard is a rule, not a person. Some providers place two of them in your path.
Figure 4.6. Your laptop, the internet, and a door on the lab box. Something in the middle decides whether the door opens.

Here are the steps, in the order you will meet them. None of them needs a clever trick.

  1. Create the box. Pick Ubuntu 24.04. On Oracle, choose an Arm (Ampere) shape from the Always Free allowance. On Hetzner or DigitalOcean, a small plan will do if you want fewer surprises. Add your SSH public key during creation. We do the key properly in Ch 6; for now, notice that the provider wants a key before it lets you in at all.
  2. Write down two addresses. One is public, the address the internet sees. The other is private, the address inside the provider’s network. On many clouds the box only knows the private one, and the public one is a mapping the provider keeps outside the machine. That mapping is the same trick your home router plays for your laptop.
  3. Find the console. Every provider offers a browser or serial console that works without SSH. Find it while everything is working, open it once, and write down where it lives. This is your lifeline on the day SSH breaks, and that day will come.
  4. Check the memory. Look at how much RAM the box reports and whether it has swap. Reason about the ballpark: if the Next app and Postgres both lived here, would there be room? Sit with the answer before you move on. If swap reads zero, you have no seatbelt, and you will feel the difference later.
  5. Run the tiny app carelessly. Start hello-pipes listening on every address, 0.0.0.0, on port 3000. That is the careless part. You are telling the machine to accept connections from any network interface, including the one facing the internet.
  6. Knock from outside. From your laptop, which is on your home network and not on the box, request the public address on port 3000. Predict the result first, out loud if it helps. Then watch.

On Oracle, I expect the request to hang and then give up. That is two guards at work. The cloud’s security list blocks the port at the edge, and the image’s own iptables rules block it again once a packet gets inside. On a provider with a lighter default, the door may just open, and hello-pipes will answer with the Host header it saw, your home IP, and every header your browser sent. Open to the world. Uh oh. That is the moment to close it, not to admire it.

How you’ll know it worked. You can name the public and private address without looking. The console opens when you need it. You predicted the outcome before you knocked. And when the request failed or succeeded, you could say which guard answered, and why that tells you something about the next step.

A VPS is a slice of someone else’s hardware, cut by a hypervisor and handed to you as a machine with its own kernel, its own disk, and its own addresses. You rent the slice, and you inherit the slice’s responsibilities: the operating system, the patches, the memory budget, and the guards in front of your doors.

Containers share a kernel and VMs do not. Overselling is the reason a cheap plan can feel slow on a busy afternoon. The hosting spectrum is a ladder of who owns which layer, and each rung you climb hands you more freedom and more worry. RAM is almost always the first wall you hit with Node, Next and Postgres together, and the out-of-memory killer is the silent assassin that rewards you with a dead process and no message.

You now have a lab box with two addresses, a console you know how to reach, and a careless app you have already knocked on. That is real progress. Most people learn about their firewall the hard way, at 2 a.m. You learned it on purpose, on a box that does not matter.

1. What does the hypervisor do that the VPS customer never sees directly?

It sits between the physical hardware and the guest operating systems, carving the host’s CPU, memory, and devices into virtual machines. Each guest believes it owns its own machine. In practice the hypervisor is the referee that keeps one guest from reading another’s memory.

2. Why can two containers on one host be less isolated than two VMs?

Containers share the host kernel. They get separate namespaces and cgroups, which limit what they can see and use, but a bug in the kernel is a bug shared by every container on that box. A VM brings its own kernel, so the boundary sits lower in the stack.

3. What is a vCPU, and why does a busy neighbour matter to you?

A vCPU is a slice of host CPU time presented to your guest as a processor. If the host is oversold and the neighbours are busy, your vCPU waits for physical time that is already spoken for. Your code did not get slower; the wait is invisible to your own tools.

4. On a PaaS like Vercel or Render, which layer do you still own?

Your code, your configuration, and usually your data and its backups. The provider owns the operating system, the patching, the process supervision, and most of the network edge. You gain speed of deployment and lose control of the machine underneath.

5. Why is the cloud security list not enough on its own on some providers?

Because the image may carry its own host firewall rules, such as iptables, that drop traffic the cloud list allowed. Two guards must both let a packet through. Opening one of them tells you nothing about the other, which is why a timeout can have two very different causes.

6. What is the OOM killer, and why is it called a silent assassin?

It is the kernel’s last resort when memory runs out. It picks a process, often your largest, and terminates it, usually without a friendly message in your application logs. From the outside you see a process that quietly vanished and a service that restarted, if you configured a restart at all.

Warm-up 1. Name the layers. Without looking back, list the four layers between physical hardware and your Node process on a cloud VPS, from the bottom up.

Answer

Physical hardware, then the hypervisor, then the guest kernel and operating system on your VM, then your Node process (with your app inside it). Your responsibilities start at the guest kernel and go up.

Warm-up 2. Public or private? Your VPS has a public address of 203.0.113.10 and a private address of 10.0.0.5. Which one would a stranger on the internet use to reach your app, and which one do other machines in the same cloud network use?

Answer

The stranger uses the public address, 203.0.113.10, provided the guards allow it. Machines inside the same virtual cloud network use the private address, 10.0.0.5, which the internet cannot route to.

Warm-up 3. Shared responsibility. Your Next.js app runs on a plain VPS, then moves to a PaaS. Name one thing you stop worrying about and one thing you still must worry about after the move.

Answer

Stop worrying about: the operating system patches and the process supervisor, which the platform now handles. Still worry about: your application’s code, its secrets, its database backups, and whether the data you need is exportable.

Lab 4. Find the console. On your lab VPS, locate the provider’s browser or serial console and confirm you can reach a login prompt without using SSH.

Hint and model solution

Hint: look for a “Console” or “Serial console” button on the instance page in the provider’s dashboard. It opens a session that does not depend on your firewall or your SSH key.

Model solution: you can see the login prompt in the browser. Log in with the admin user you created, then log out. You have now confirmed that the lifeline works before you need it.

Lab 5. Read your own addresses. Find the public and private address of the lab box, and state which one a visitor from the internet would hit.

Hint and model solution

Hint: once logged in, the network interfaces list shows addresses. Compare what the machine reports with what the provider’s dashboard reports. They should agree on the private address, and the public one is usually mapped by the provider.

Model solution: the private address is 10.0.0.5. The public address is 203.0.113.10. A visitor on the internet reaches the public address, subject to the cloud security list and the host firewall.

Lab 6. Check the memory budget. Report the total RAM and the swap on the lab box, and say whether swap is configured at all.

Hint and model solution

Hint: the free command shows memory and swap in one table. Use the human-readable flag. swapon --show lists active swap files or partitions.

Model solution: report the total RAM, which on a small instance is often well under 2 GB, and the swap total. If swap shows zero, state that a memory spike has no cushion, and note that adding a swap file is a sensible first step on a small box.

Lab 7. Predict the timeout. Before you run anything, write down what you expect to happen when you start a tiny app on port 3000 bound to all addresses, then reach it from your laptop at the public address. Explain your prediction in terms of the two guards.

Hint and model solution

Hint: think about the cloud security list first, then the host firewall. Ask which one would drop the packet before your app ever saw it.

Model solution: a timeout means the packet was dropped silently, typically by a guard that did not allow port 3000. A quick refusal means the packet arrived and nothing was listening. A success means both guards let it through and the app answered. Your prediction should name which guard you suspect and why.

Staff 8. Choose a provider for a team tool. Your 8-person team needs an internal status tool that runs on a single VPS, with a Postgres database and a nightly backup. Pick a provider and region, and defend the choice in five sentences or fewer.

Model answer

A good answer picks a provider whose regions are close to your team, names the free tier or the paid plan with hedged prices, and says where the backups live. It notes that the box is an operational responsibility: patching, backups, and a tested restore are yours. It states one reason to prefer a paid plan over a free tier for a team that depends on the tool, which is predictable reclamation and support.

Staff 9. Size for a Next.js and Postgres pair. Your Next.js build and a Postgres database will share one 1 GB VPS. Explain why the build step is the most dangerous moment, and propose two changes that reduce the risk without upgrading the machine.

Model answer

The build step can spike memory well above the steady state, and the OOM killer may stop Postgres or the build without warning. Two changes help: add a swap file as a cushion so the spike slows rather than kills, and move the build off the production box, for example to a CI runner or a container built elsewhere. Limiting Postgres memory settings is a third option worth naming.

Book 2 of a series. Book 1: The Glue.