Client and Server

How the app you use relates to the machine that does the work behind it.

What is it?

The app or website you see, with its screen and buttons, is the client. It usually doesn't hold the data or logic itself. It sends a request over the internet to a server, a computer elsewhere that has the data, does the processing, and sends a response back.

Client asks, server answers. Almost all software on the internet is built on this split.

Explain like I'm 10

It's like ordering at a restaurant. You (the client) don't cook. You tell the waiter what you want, the kitchen (the server) makes it, and the waiter brings it to your table.

Examples

A basic client-server exchange

// Client (browser) sends a request:
fetch("https://api.example.com/users/1")
  .then((response) => response.json())
  .then((user) => console.log(user));

// Server receives the request, looks up the data,
// and sends back something like:
// { "id": 1, "name": "Amara" }

How it works

The client sends a request over the network saying what it wants. The server does the work (looking up data, running logic) and sends a response. The client then updates the screen based on that response.

Client (app/browser)
       │  sends a request
       ▼
     Server
       │  processes it, sends a response
       ▼
Client (app/browser) — updates the screen

Why does it exist?

Many clients (phones, browsers, smart TVs) can share one server and its data, so no device has to store and manage everything itself. The server can also be updated or scaled separately from the apps that use it.

When to use it

It applies to almost any networked app (web apps, mobile apps, online games): any time one program needs data or processing that lives somewhere else.

When not to use it

A fully offline tool that never talks to another machine doesn't need it. For something tiny and local, a separate server just adds operational work with no real benefit.

Common mistakes

  • Trusting the client. Users can modify clients, so the server should always re-check anything important.

  • Forgetting that each request/response trip takes real time (network latency), which affects how responsive an app feels.

  • Putting sensitive logic or secrets in client-side code, where anyone can inspect it.

Practice exercises

  1. Easy:

    Open your browser's Network tab and find one request your favorite website sends to its server.

  2. Medium:

    Explain in your own words why a weather app needs a server instead of just knowing the weather itself.

  3. Hard:

    Describe what could go wrong if a shopping app trusted the price sent by the client instead of checking it on the server.

Interview questions

What is the client-server model?

A client sends requests to a server, which processes them and returns a response, instead of the client doing everything itself.

Why shouldn't a server trust data coming from the client?

Anyone can modify or forge client code and requests, so the server must validate anything that matters for security or business rules.

What is latency, in the context of client-server communication?

The time for a request to reach the server and the response to come back. It's a key factor in how fast an app feels.

What's the difference between a thin client and a thick (fat) client?

A thin client does little processing and relies on the server for most logic and data (e.g. a basic web page). A thick client keeps much of the logic and state locally and only calls the server to fetch or save data (e.g. a native desktop app).

Why can many different kinds of clients (web, mobile, smart TV) all share the same server?

The server exposes its data and logic through a shared protocol like HTTP, not a client-specific interface. Any client that speaks that protocol can use it, whatever device it runs on.

What is a request-response cycle, and why does understanding it matter for building responsive apps?

It's the full round trip of sending a request and getting a response. Every cycle takes real time, so an app that makes many unneeded cycles, or blocks the UI while waiting, feels slow even with a fast server.

At a conceptual level, how does a client know which physical server to talk to when it makes a request?

It resolves a human-readable address (like a domain name) to a network location via DNS, then connects to it. The client doesn't need to know which actual machine handles the request.

How should a well-built client handle a server that's slow to respond?

Don't block the whole UI, show a loading state, and set a reasonable timeout instead of waiting forever. Treat slow responses as normal, not an edge case.

Why is validating input only on the client side considered a security anti-pattern?

Client code runs on a device the user controls. It can be bypassed or skipped by sending requests directly, so any validation that matters for security or data integrity must also run on the server.

What's the difference between synchronous and asynchronous client-server communication?

Synchronous: the client waits for the response before doing anything else. Asynchronous: the client keeps working and handles the response (or a notification) when it arrives.

Can a server ever act as a client? Give an example.

Yes. When a server needs another service, it sends its own request and acts as that service's client, e.g. a backend calling a third-party payment API before replying to the original client.

Why does moving business logic from the client to the server usually improve security, even at the cost of extra latency?

Server-side logic is outside the user's control and can't be tampered with or bypassed. Anything where correctness or trust matters (pricing, permissions, validation) is safer there, even if it costs an extra round trip.

What's the difference between latency and bandwidth?

Latency is the delay before data starts arriving. Bandwidth is how much data can flow per unit of time. A connection can have low latency but low bandwidth, or the reverse, and each affects performance differently.

Why might a client cache data locally instead of requesting it from the server every time, and what's the trade-off?

Caching avoids the latency and load of repeating the same request. The risk is stale data if the server's data changes and the cache isn't refreshed.

What is a network round trip, and why do developers try to minimize how many a page or app makes?

One full request-response exchange. Each adds latency, so an app making many round trips one after another (instead of batching or running them in parallel) feels much slower than the server's actual processing time.

How does the client-server model differ from a peer-to-peer model?

In client-server, roles are fixed: clients request, servers respond, and servers are usually central. In peer-to-peer, each participant acts as both client and server, with no central authority required.

What role does the server play when multiple clients try to modify the same data at the same time?

It's the single source of truth that orders or reconciles concurrent updates (via locks, transactions, or conflict rules). Without it, clients could overwrite each other's changes inconsistently.

Why do mobile apps often need to handle network failures more gracefully than typical desktop web apps?

Mobile devices often lose or switch connectivity (Wi-Fi to cellular, low-signal areas). A mobile client should expect drops and plan for retries, offline states, or queued requests instead of assuming a stable connection.