The Academy

Loading the search index…

Searches the academy on this device only.

Web servers, hosting, CDNs, cookies and sessions

See where websites actually live, why big sites copy themselves to many places, and how cookies and sessions let a site remember you although the web itself has no memory.

30 minelementaryPractical task needs a laptop or desktop

Marking a lesson as read does not prove you can do it. Skills count as demonstrated when you pass the quiz (not yet) and complete the practical tasks (not yet).

By the end of this lesson you will be able to

  • Explain what a web server is and where a website physically lives.
  • Compare the main ways of hosting a site at a beginner level.
  • Describe how a CDN makes pages load faster for people far away.
  • Explain why cookies exist and how a session keeps you signed in.
  • Describe a full browser request as a sequence of steps and name the client and server roles.

A website is not a cloud or a magic place. It is files on a computer somewhere, answering requests all day. Understanding where those computers are and how they remember you explains common experiences: why a site loads fast one day and slowly the next, why you stay signed in, and why a cookie notice appears on almost every page you visit.

What a web server really is

A web server is a computer, or the program on it, that stores the files of a website and sends them to browsers that ask. When you open a page, your browser is the Client and that computer is the Server, exactly as in the first lesson of this module. A server program waits on port 443 and answers every request that arrives, often thousands each second.

Some pages are just stored files, handed out as they are. Others are built on request: the server runs a small program, perhaps looks up your account in a database and assembles a page that is different for you. A news site shows the same articles to everyone; a bank shows your own balance.

Hosting: where the server lives

Hosting means renting space and attention on a computer that is always on and always connected. Nobody runs a website from a laptop on the kitchen table, because it would go off whenever the laptop slept. Hosting companies keep thousands of servers in a data centre: a building with backup power, cooling, security and very fast network links. You choose how much of the work you take on.

Diagram

Three common ways of hosting a website, from least to most work for the owner.

Shared hostingOne server, many sites
  • Cheap and simple
  • Owner looks after site files
  • Busy neighbours can slow it

Good for small sites.

Rented serverYour own slice
  • Flexible
  • Owner updates and secures the software
  • Needs technical skill

More control, more work.

Managed platformProvider runs it
  • Publish with an upload
  • Provider keeps servers updated
  • Very little maintenance

Easiest for simple sites.

Three common ways of hosting a website, from least to most work for the owner.
Read this figure as text

A three-column comparison of shared hosting, a rented server and a managed platform.

Shared hosting: many small sites share one server; cheap and simple; the owner manages only the site's files; performance may dip if neighbours are busy. Rented virtual server: the owner rents a private slice of a server and looks after its software and security; flexible but needs technical skill. Managed platform or static site service: the provider runs the servers and the site is published with a few clicks or uploads; very little maintenance; the Computer Literacy Academy you are using is a static site of this kind. All three keep the site in a data centre.

CDNs: copies close to you

Distance matters. A request that must cross an ocean takes longer than one that travels across town. A content delivery network (CDN) solves this by keeping copies of a site's files, such as pictures, styles and videos, on many servers around the world. Your browser is sent to the nearest copy. The main computer that holds the original is the Origin server; it is asked only when a copy is missing or out of date.

Diagram

A CDN serves a visitor from a nearby copy instead of the faraway original.

ask1copy2only if no copy3VisitorNearby CDN copyfastOrigin serverfar away
A CDN serves a visitor from a nearby copy instead of the faraway original.
Read this figure as text

A network diagram of a visitor, a nearby CDN copy and a distant origin server.

On the left a visitor's laptop. In the middle, a CDN server close to the visitor. On the right, far away, the origin server that holds the original website. Step 1: the laptop asks the nearby CDN server for the page's picture. Step 2: if the CDN already has a copy it replies at once, which is quick; this is the usual case. Step 3: only when the CDN has no copy does it ask the faraway origin server, store the answer and pass it on. Later visitors nearby then get the stored copy.

Your own browser keeps a copy too, called a Cache. If you revisit a site, it may reuse pictures it already stored. That is why a reload sometimes shows an old version of a page: the cache or a CDN held an earlier copy.

A page visit, start to finish

Diagram

Everything from the lessons so far, joined into one page visit.

  1. Step 1: Read the URLYou press Enter
  2. Step 2: DNS lookupName to address
  3. Step 3: ConnectPort 443
  4. Step 4: TLSCheck certificate
  5. Step 5: Request and responseHTML, styles, pictures
  6. Step 6: Draw the pageBrowser shows it
Everything from the lessons so far, joined into one page visit.
Read this figure as text

A flow of six steps from typing an address to seeing the page.

Step 1: you type or click an address and the browser reads the URL. Step 2: DNS turns the domain name into an IP address. Step 3: the browser connects to the server's address on port 443. Step 4: TLS sets up a protected connection and checks the certificate. Step 5: the browser sends an HTTP request and the server (or a CDN copy) sends a response containing the page. Step 6: the browser reads the page, asks for the pictures and styles it names, and draws it on the screen.

Cookies and sessions: giving the web a memory

HTTP has no memory. Each request is a separate event, and the server does not automatically know that two requests came from the same person. To fix this, a site can ask your browser to store a small piece of text called a Cookie and send it back with every later request to that site.

Here is how a sign-in works. You send your username and password over HTTPS. The server checks them and starts a Session: a record on the server that says this person is signed in. It sends your browser a cookie holding a long random code that identifies that session. Your browser returns the code with every request, so the server recognises you without asking for the password again. When you sign out, or when the session expires, the server forgets the code.

Cookies are used for three common jobs: keeping you signed in, remembering choices such as language or items in a shopping basket, and tracking, where advertising companies recognise you across many sites. Cookies set by the site you are visiting are called first-party. Cookies set by another company whose content is embedded in the page are third-party, and these are the ones used for most tracking. Browsers let you block or clear them, and many sites now ask your permission before using tracking cookies.

Diagram

The client-server idea, as layers: what your browser sees and what sits behind it.

Your request travels down; the answer travels back up

BrowserThe client on your device
Internet and CDNCarry the request
Web serverReceives and routes it
ApplicationBuilds the page for you
DatabaseAccounts, messages, orders
The client-server idea, as layers: what your browser sees and what sits behind it.
Read this figure as text

A stack of layers from the browser on your device down to the database behind the web server.

Layers, from the top: first, your browser on your device (the client), which asks and displays. Second, the internet and any CDN, which carry the request. Third, the web server, which receives the request and decides what to send. Fourth, the application program behind it, which builds pages for you. Fifth, the database, which stores accounts, messages and orders. Each layer only talks to the one next to it.

Common mistakes

  • ✖ Instead of: Believing that deleting cookies removes all your files or ruins the computer.

    ✔ Do this: Clearing cookies only signs you out of sites and forgets some preferences. Your own files are not touched.

  • ✖ Instead of: Thinking a website exists 'in the cloud' with no particular place.

    ✔ Do this: It sits on real servers in real data centres, often with copies in several places.

  • ✖ Instead of: Assuming a page you reloaded is always the latest version.

    ✔ Do this: A cache or a CDN may hold an earlier copy. A hard refresh (Ctrl+F5 on many browsers) asks for a fresh one.

If something goes wrong

A site keeps signing me out.
Check that your browser is not set to clear cookies every time it closes, and that the date and time on your computer are correct. Some sites also end sessions after a period of inactivity on purpose.
A site says cookies are blocked, but I want to use it.
Open the site settings for that site in your browser and allow first-party cookies for it. You do not need to allow third-party cookies for a site to work in most cases.

Key terms

Data centre
A building full of servers, with strong power, cooling and network links.
Origin server
The main server that holds the original copy of a website, which a CDN copies from.
Web server
A server that stores websites and sends pages to browsers that ask for them.
Hosting
A service that keeps a website's files on a server so people can visit it.
CDN
A group of servers around the world that keep copies of a website so it loads quickly for everyone.
Cookie
A small file a website saves in your browser to remember things about you.

Practise it for real

Reading is not the same as being able to do it. Complete these on your own computer, then tick only what you have actually done. These ticks are your own honest record: nothing checks them for you.

Guided exerciseNeeds a laptop or desktop

See which sites keep data in your browser

On your real computer, open your browser's settings and find the area about privacy, cookies or site data (names and positions vary by browser and release, so use the search box in settings). Look at the list of sites that have stored data. Do not delete anything yet. Write down three sites you recognise and one you do not.

You have succeeded when:
Independent challenge

Challenge: explain one visit

Without looking at the lesson, write the sequence of events from pressing Enter on https://example.org to seeing the page, using these words at least once each: DNS, TLS, request, response, server, CDN. Then add what happens differently when you sign in to an account on the next page.

You have succeeded when:

Knowledge check

6 questions. You need 80% to pass. Mistakes here are part of learning, and you can retry as often as you like.

  1. Question 1.What is a web server?
  2. Question 2.A cookie is a small program that can run on your computer.
  3. Question 3.Wanjiru lives far from the data centre where a news site's main server sits, yet its pictures load quickly for her.What most likely explains this?
  4. Question 4.Put the steps of a sign-in with a session cookie in order.
    1. The server sends a cookie with a random session code
    2. The server checks them and starts a session
    3. Your browser sends that cookie with every later request
    4. You send your username and password over HTTPS
  5. Question 5.Match each term to its meaning.
  6. Question 6.Why should you sign out of your accounts on a library computer?

Summary

  • A web server is a computer or program in a data centre that answers browsers' requests.
  • Hosting is rented space on an always-on computer; the domain name is bought separately.
  • A CDN keeps copies of files near visitors, and the origin server holds the original.
  • HTTP has no memory; cookies and sessions are how a site remembers you.

Checklist: can you do these?

Marking a lesson as read does not prove you can do it. Skills count as demonstrated when you pass the quiz (not yet) and complete the practical tasks (not yet).

Related lessons

References and further reading

Official sources for details that can change between versions.

On this page