You run next build, then next start. The terminal says the app is ready on localhost:3000.
At that moment, your laptop is a server. It waits, and it answers each request that arrives.
A server at work is the same idea, in a bigger box that never sleeps. In this lesson you open that box.
A server is a program that waits
The word "server" has two meanings. People use both, often in the same sentence.
- The program. A program that starts, then waits for requests and sends back replies.
next startis one. NGINX and PostgreSQL are others. - The machine. The computer that runs that program all day.
┌────────────────────────────────────────────┐ │ │ │ browser your laptop │ │ ┌─────────┐ request ┌──────────────┐ │ │ │ page │ ────────▶ │ next start │ │ │ │ │ ◀──────── │ port 3000 │ │ │ └─────────┘ reply └──────────────┘ │ │ │ └────────────────────────────────────────────┘
The program on a . Port 3000 is the door for your Next.js app. The next lesson explains ports in full.
So any computer can be a server. What makes a machine a "server" at work is its job: it runs a waiting program all day, for many users at once.
What is inside the machine
A server has the same four main parts as your laptop. It has more of each, and no screen or keyboard.
| Part | Its job | Your laptop | A large cloud server |
|---|---|---|---|
| CPU | Runs the code | 8 to 16 cores | 192 vCPUs |
| Memory (RAM) | Holds what runs now | 16 GB | 768 GiB |
| Disk | Keeps files and data | 512 GB SSD | Disks over the network |
| Network card | Sends and gets data | Wi-Fi | 50 Gbit/s |
The large server in the table is a real AWS size, m7i.48xlarge. A is a cloud's way to count cores.
- CPU. The does the work for each request: render a page, check a password, build JSON. More cores means more requests at the same time.
- Memory. holds the running program and its data. When a server runs out of memory, the program slows down or crashes.
- Disk. The disk keeps everything after a restart: the operating system, the app's files and the database.
- Network card. Every request comes in and goes out through it.
When a site gets slow, the team asks which of these four ran out first. That question comes back in the monitoring chapter.
Racks, data centers and virtual machines
A physical server is a flat metal box. It slides into a , like a drawer.
Rack boxes come in a fixed height called a unit (U). One U is 1.75 inches (44.45 mm). A thin "1U" server is the box in the figure above.
┌───────────────────────────────────────────────────┐ │ │ │ one rack a data center │ │ ┌──────────────┐ ┌───┐ ┌───┐ ┌───┐ │ │ │ ▓ switch · │ │▓▓▓│ │▓▓▓│ │▓▓▓│ │ │ │ ░ server 1 · │ │▓▓▓│ │▓▓▓│ │▓▓▓│ │ │ │ ░ server 2 · │ └───┘ └───┘ └───┘ │ │ │ ░ server 3 · │ ┌───┐ ┌───┐ ┌───┐ │ │ │ ░ ... │ │▓▓▓│ │▓▓▓│ │▓▓▓│ │ │ └──────────────┘ └───┘ └───┘ └───┘ │ │ │ │ ▓ network switch ░ server · status light │ │ │ └───────────────────────────────────────────────────┘
A keeps thousands of these racks cool, powered and online. Few companies build their own. Most rent space in someone else's.
Virtual machines
Most teams today do not touch hardware. They rent a , or VM, from a cloud such as AWS, Google Cloud or Azure.
A program called a cuts one big physical server into many VMs. Each VM runs its own full operating system. A new one takes minutes to start, not weeks.
┌────────────────────────────────────────────┐ │ │ │ one physical server │ │ ┌────────────────────────────────┐ │ │ │ ┌────────┐ ┌────────┐ ┌──────┐ │ │ │ │ │ VM 1 │ │ VM 2 │ │ VM 3 │ │ │ │ │ │ web │ │ db │ │ jobs │ │ │ │ │ └────────┘ └────────┘ └──────┘ │ │ │ │ hypervisor │ │ │ │ CPU · memory · disk · network │ │ │ └────────────────────────────────┘ │ │ │ └────────────────────────────────────────────┘
On AWS, a VM is an EC2 instance. You pick an instance type, and the type sets the size.
A t3.micro has 2 vCPUs and 1 GiB of memory. An m7i.large has 2 vCPUs and 8 GiB.
- Your own serversbuy, rack and repair
- -Order hardware weeks ahead
- -Your team swaps broken disks
- -Pay up front, even when idle
- Rented VMsthe cloud owns the hardware
- +A new VM in a few minutes
- +The cloud swaps broken parts
- +Pay by the second, stop any time
Where your Next.js app runs
On Vercel, you never pick a server. Vercel calls this .
Serverless does not mean "no servers". It means the servers are someone else's job.
- Browseropens shop.com
Vercel
- Vercel CDNsends static files
- dynamic pageVercel Functionrenders the page
- runs on
- Real serverin a data center
- Static files, such as images and prebuilt pages, come from Vercel's CDN. Load balancers, proxies and CDNs covers CDNs.
- Dynamic code, such as a Route Handler or a server-rendered page, runs as a Vercel Function.
- By default, Node.js functions run in one region: Washington, D.C. (
iad1). You can move them closer to your database. - Vercel starts more copies when traffic grows. With no traffic, it stops them all.
Each copy is still a program on a server, with a CPU, memory and a network card. You rent a slice of it for each request, not the whole machine.
- 01
A server is a program that waits for requests, and also the machine that runs it all day.
- 02
Every server has four main parts: CPU, memory, disk and network card.
- 03
Physical servers sit in racks in data centers. Most teams rent virtual machines, slices of those servers.
- 04
Serverless platforms like Vercel still run on servers. Someone else runs them.
Read more
- What is a web server? from MDN. The hardware side and the software side.
- Amazon EC2 instance types. The sizes you can rent, from tiny to huge.
- Vercel Functions. How your server code runs, scales and picks a region.
- Stack Overflow's architecture and hardware posts from 2016, the story above.
- Docker in Action, 2nd edition, chapter 1: read 1.1.3 on what a virtual machine is.
The next lesson is "How a request reaches your app".