Computer Science • Networking • 9 min read

What Is a Server?

Summary

A server is a program, or the computer running it, that waits for requests from other programs called clients and sends back a response. The word describes a role, not a special kind of machine. Any computer can act as a server if it runs software that listens for requests.

A server is a program that waits for requests and responds to them. The word also describes the computer that runs such a program. The program that sends requests is called a client.

When you open a website, your browser is the client. It asks a web server for a page. The server finds or builds the page and sends it back. This arrangement is called the client-server model, and most of the internet works this way.

The model exists because sharing is efficient. One server can hold data or perform work that thousands of clients need. Clients do not have to store everything or do everything themselves.

How It Works

Server Means a Role

“Server” has two common meanings, and both are correct:

  • Software: a program that listens for requests, such as a web server or a database server.
  • Hardware: a computer that is set up to run such programs, usually continuously.

A server is defined by what it does, not by what it looks like. A laptop that runs a web server program is a server while that program runs. Dedicated server machines are built for reliability. They typically have more memory, redundant power supplies, and no screen or keyboard.

Client and server are also roles. One program can be both. A web server that asks a database server for data is a client of the database while it is a server to your browser.

The Request and Response Cycle

A server follows the same basic loop:

  1. Listen. The server program waits for incoming connections on a specific network address and port.
  2. Accept. When a client connects, the server accepts the connection.
  3. Read. The server reads the client’s request.
  4. Process. The server does the work: reading a file, querying a database, or running calculations.
  5. Respond. The server sends the result back to the client.
  6. Repeat. The server returns to listening. It does not stop after one request.

This is why a server is described as long-running. It starts, then keeps running until someone stops it.

Addresses and Ports

A client needs two things to reach a server:

  • An IP address, which identifies the machine on the network. People usually type a domain name, and DNS translates it into an IP address.
  • A port number, which identifies the specific program on that machine.

One machine can run many servers at once. Each one listens on a different port. The port tells the operating system which program should receive the incoming data.

PortCommon use
22SSH (secure remote login)
25SMTP (sending email between servers)
53DNS (name lookups)
80HTTP (web pages)
443HTTPS (encrypted web pages)
3306MySQL (database)
5432PostgreSQL (database)

Common Types of Servers

The type depends on the service the software provides.

TypeWhat it does
Web serverDelivers web pages and files over HTTP or HTTPS.
Application serverRuns the business logic of an application.
Database serverStores data and answers queries.
File serverStores and shares files across a network.
Mail serverSends, receives, and stores email.
DNS serverTranslates domain names into IP addresses.
Game serverKeeps the shared state of an online game.

A single machine can run several of these. Large systems usually split them across many machines.

Serving Many Clients at Once

A server rarely has just one client. If it handled requests strictly one at a time, every client would wait for all earlier clients to finish. Servers avoid this in three common ways:

  • Process per connection: each client gets its own process. This isolates clients from each other but uses more memory.
  • Thread per connection: each client gets a thread inside one process. This uses less memory but needs care with shared data.
  • Event loop: one thread watches many connections and handles each one only when it has data ready. This works well when most time is spent waiting on the network.

The operating system limits how many connections a server can hold open, and the hardware limits how much work it can finish per second.

Code Example

This Python program is a complete, working web server. It uses only the standard library.

from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer

class Handler(BaseHTTPRequestHandler):
    def do_GET(self):
        body = b"Hello from the server"
        self.send_response(200)
        self.send_header("Content-Type", "text/plain")
        self.send_header("Content-Length", str(len(body)))
        self.end_headers()
        self.wfile.write(body)

server = ThreadingHTTPServer(("127.0.0.1", 8000), Handler)
print("Listening on http://127.0.0.1:8000")
server.serve_forever()

Run it, then open http://127.0.0.1:8000 in a browser. The page shows the text “Hello from the server.”

The code maps directly to the cycle described above:

  • ThreadingHTTPServer(("127.0.0.1", 8000), Handler) sets the address and port to listen on.
  • serve_forever() runs the listen-accept loop and never returns on its own.
  • do_GET runs once for every GET request. It sets a status code, headers, and a body.
  • ThreadingHTTPServer handles each connection in its own thread, so one slow client does not block the others.

The address 127.0.0.1 is the loopback address. It means “this same machine,” so only programs on your own computer can reach the server.

[!NOTE] Python’s built-in server is meant for learning and quick tests. Production systems use hardened server software such as Nginx, Apache, or a framework’s production server.

Trade-offs and Alternatives

Where a Server Runs

OptionDescriptionMain benefitMain cost
Own hardwareYou buy, house, and maintain the machine.Full control.Upfront cost and maintenance work.
Virtual serverA software-created machine that shares physical hardware with others.Cheap and quick to create.Performance can be affected by neighbors.
Cloud serverA virtual server rented from a provider and billed by use.Easy to add or remove capacity.Costs can grow with usage.
ServerlessYou upload code and the provider runs it on demand.No machine management.Less control and provider-specific limits.

Scaling

When a server cannot keep up with demand, there are two options:

  • Vertical scaling: move to a more powerful machine. It is simple, but there is a ceiling on how large one machine can be, and it remains a single point of failure.
  • Horizontal scaling: add more machines and spread requests among them, usually with a load balancer. It scales further and tolerates failure, but the software must be designed to work across several machines.

Redundancy improves availability. If each server is independently running with probability pp, then with kk servers the chance that at least one is running is:

1−(1−p)k1 - (1 - p)^k

For example, if each server is running 90% of the time, two servers give 1−0.12=0.991 - 0.1^2 = 0.99. This calculation assumes failures are independent. Servers that share a power source or network switch can fail together, so real availability is lower.

[!TIP] Keep servers stateless where possible, meaning each request carries what the server needs and no request depends on memory of earlier ones. Stateless servers are easy to copy and replace, which makes horizontal scaling much simpler.

Servers vs. Peer-to-Peer

In a peer-to-peer system, every participant both requests and provides data, and no central server exists. This removes the central point of failure but makes coordination, security, and consistency harder. The client-server model remains the default because it is simpler to build, secure, and manage.

Common Misconceptions and Gotchas

“A server is a special kind of computer.” Any computer can be a server. Dedicated server hardware is built for reliability and continuous use, but the role comes from the software.

“Serverless means there are no servers.” Serverless code still runs on servers. The provider owns and manages them, so you do not.

“One machine runs one server.” A single machine often runs many server programs, each on its own port.

“Servers are always on the internet.” Servers also run on private networks and on a single machine. The loopback address 127.0.0.1 is a common way to test servers locally.

“If the server is running, clients can reach it.” A running server can still be unreachable. Firewalls, wrong ports, wrong addresses, or a program bound only to 127.0.0.1 can all block outside access.

Exposing a server by accident. Binding a server to 0.0.0.0 makes it listen on every network interface, which can expose it to the wider network.

[!WARNING] Any server reachable from the internet will receive unwanted traffic, including automated attempts to break in. Keep software updated, close ports you do not need, use HTTPS, and never leave default passwords in place.

Trusting the client. A server must check every request. Clients can send malformed or malicious data, so validation and permission checks belong on the server and not only in the client.

Key Takeaways

  • A server is a program, or the computer running it, that listens for requests and sends back responses to clients.
  • “Server” is a role. Any computer can act as one, and one program can be both client and server.
  • Servers run a continuous loop of listen, accept, read, process, and respond, and they use processes, threads, or event loops to serve many clients at once.
  • A client reaches a server through an IP address and a port number.
  • Scaling a server means a bigger machine (vertical) or more machines (horizontal). Adding machines improves capacity and availability but requires software designed for it.

Related articles in Computer Science

Image preview

Fit