Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
How the Web Works  ›  Lesson

Hosting — Where Your Code Lives

What is hosting? 12 minHosting means running your code on a machine that is always on and publicly reachable, and the options trade control against how much the provider manages for you.

Hosting — Where Your Code Lives

The bookshop API runs perfectly at http://localhost:8000. You send the link to a friend, and it fails for them. Your laptop is not always on, it has no public address, and localhost always means "this machine". To be reachable by the world, code needs a host.

The rule

Hosting is renting a computer that is always on, reachable and looked after.

Any hosted backend needs the same few things: a machine that stays running, a public address with a DNS name pointing at it, a process listening on a port, a TLS certificate for HTTPS, a way to restart after crashes, and logs you can read.

The options differ in who looks after what:

Option You provide The provider looks after
Dedicated server everything above the hardware power, network, hardware
Virtual private server (VPS) OS updates, runtime, your app the physical machine, split into virtual ones
Platform as a service (PaaS) your code and settings OS, runtime, restarts, often certificates
Serverless functions individual functions everything else, starting them per request
Static hosting / CDN plain files serving them from locations near users

Shared hosting, where many small sites live on one managed machine, is the cheapest older option, mostly for simple PHP sites.

A detail that trips up beginners: a server program must listen on the right interface. Listening on 127.0.0.1 accepts connections only from the same machine; listening on 0.0.0.0 accepts them from outside too.

uvicorn app:app --host 0.0.0.0 --port 8000

The shortcut

The more the platform manages, the less you control and the less you maintain. Ask one question: "Do I need to control the operating system?" If no, move right in the table toward a platform. If yes, move left toward a VPS.

Putting the bookshop API on a platformStep 1 of 4
  1. Push the code

    You connect your Git repository. The platform builds your app, installing its dependencies.

Keep the frontend's plain files separate in your head: HTML, CSS and images need no running process, so static hosting behind a CDN is simpler and cheaper than any server.

Drills

Answer fast — trust the rule.

quick drill

You need to install a custom system package and tune the operating system. Which option fits?

quick drill

Your API works at http://localhost:8000. Can a friend on another network open that address?

quick drill

A site is only HTML, CSS and images, with no server code. What is the simplest host?

quick drill

On a platform service, who normally applies operating-system security patches?

quick drill

Your hosted API only answers when you connect from the server itself. What is the likely cause?

Remember

  • Hosting is renting a computer that is always on, reachable and looked after.
  • More management means less control and less maintenance: choose by whether you need the OS.
  • localhost and 127.0.0.1 never reach the outside world.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainChoosing a home for the bookshop

The bookshop has a static marketing site and a Python API with a database. Recommend where each part could be hosted, explain the trade-off you are making, and say why the API running on your laptop at localhost:8000 is not yet hosted.