QA Interview Hub · Knowledge base · Quizzes · Українська

API › Client-server and REST

Client and server: who is responsible for what

The client builds the request and shows the result; the server holds the business logic, checks permissions and alone talks to the database. The split serves security, single-place rules and independent client evolution. A bug is located by stage: what the client sent (Network), whether the request arrived (DNS, TLS, load balancer), what the server answered and the state afterwards. With asynchronous processing the final state is checked by a separate request.

API · Client-server and REST

The Transfer button spins and no money moves. Where is the cause: the UI, the network or the server?

A user taps "Transfer", the spinner keeps spinning, and no money has moved. In a complaint this reads as "it is broken", but between the button and the database there are several places where something can go wrong. A tester who knows this path can say within a minute at which stage the problem is, instead of "it does not work". This article is about who is responsible for what in the client-server pair and how that turns into locating a bug.

The roles and why they are separated. The client (a browser, a mobile app, Postman, another service) builds the request and shows the result. The server holds the business logic, checks permissions and talks to the database itself. The client never goes to the database directly, for three reasons:

  • Security. The user controls the browser and the phone. Database credentials that reach the client reach everyone.
  • Rules in one place. The transfer limit is checked by the server, not by copies of the logic in the web app, on iOS and on Android: then a rule cannot be "forgotten" in one of the clients.
  • Independent evolution. Old mobile app versions live for weeks, the server is updated in minutes. The API contract has to survive that. This is Fielding's first REST constraint: separation of client and server.

The path of a request from the button to the database

1 Clientmethod, URL, headers, request body 2 DNS, TCP, TLSdomain, connection, certificate 3 Load balancer / gatewaywhich instance got the request 4 Servertoken, validation, business logic 5 Databasetransaction: all or nothing
Figure 1. The request goes down, the response comes back the same way. A problem can sit at every step, and each looks different.

Each stage breaks in its own way, and the symptom tells where to look:

StageWhat can be wrongHow to notice
ClientA wrong request, or a wrong display of a correct responseNetwork tab: what was sent and what came back
DNS, TLSThe domain does not resolve, the certificate is expiredThe request never arrives: net::ERR_CERT_DATE_INVALID in the browser, "certificate has expired" in curl
Load balancerOne instance runs an old version, a backend is down502, 503, 504 or responses that "flip" between two behaviors
ServerWrong authorization, validation or business ruleThe request is right, the status or the body is not
Database, transactionHalf of the data is saved, a lock, a raceThe response is an error, but part of the changes is already saved: the next GET shows it

Example: the UI says "Insufficient funds" although there is money. The complaint: the account has 5000, a transfer of 1200 fails. The first thing a tester does is not open the code but open Network and see what the client actually sent:

POST /api/transfers HTTP/1.1
Authorization: Bearer eyJ…
Content-Type: application/json

{"fromAccount":"acc-1","toAccount":"acc-2","amount":1200}
HTTP/1.1 422 Unprocessable Content
Content-Type: application/json

{"code":"insufficient_funds","message":"Insufficient funds"}

How to read it. The request is right: the same accounts and the amount the user typed. So the frontend is not at fault, the message on the screen only shows what the server returned. The second step: ask for the balance separately, without the UI.

curl -s -H "Authorization: Bearer $TOKEN" $BASE/api/accounts/acc-1
{ "id": "acc-1", "balance": 5000 }

The account shows 5000, while the transfer check believes there are no funds. Hence the wording that goes to the developer: "the request is correct, GET /accounts/acc-1 returns 5000, POST /transfers returns 422 insufficient_funds: the server-side check uses a different balance value". The bug reaches the backend team at once, with a reproduction in two curl commands.

Two reports about the same bug

Typical

"The transfer fails in the UI"

It is unknown whether this is the frontend, the network or the server. The developer starts from scratch, and the bug may go to the wrong team.

Better

Request, response and a control GET

It shows that the client sent the right thing and the server answered wrongly. It reproduces with one curl, without the app.

Figure 2. The same bug, two reports. The second names the stage of the path where the data went wrong.

Limits of the model. The picture "a request arrives, a response returns" is simplified:

  • Not everything is synchronous. The server can answer 202 Accepted and run the transfer later while the client polls the status. Then a successful response does not mean the transfer is finished.
  • There are caches between client and server. A browser or CDN can return an earlier response, and the server never sees the request.
  • Several services can sit behind a gateway. The error the client sees sometimes came from a deeper service, and its text says nothing about which failure it was.
  • The client is not always the UI. Integrations, other services and autotests call the same endpoints, so the API has to be right on its own.

Common mistakes.

  • Starting from the code or server logs without looking at the request in Network: wasted time if the problem is on the client.
  • Treating the message on the screen as "the server's response": the frontend builds it and may rewrite the text.
  • Checking only the response and not the state after it: a business operation may have partly run.
  • Testing only through the UI: whatever the UI does not let you type stays unverified.

Check yourself

The request in Network is correct, the server returned 500, and the database has a half-created transfer. At which stage of the path do you look for the cause, and what does it say about the transaction?

Answer

At the server and database stage: the client sent a correct request. Half-saved data means several writes ran without a shared transaction, or the transaction was not rolled back after the error. A transaction should give "all or nothing".

After a deploy some requests behave in the new way and others in the old way, although you send them identically. Which link of the path is likely?

Answer

The load balancer: some requests reach an instance with the old version and some the new one. Repeating the same request several times and comparing responses (some services return the version in a header) helps confirm it.

In an interview. Junior: The client sends an HTTP request, the server checks authorization and data, runs the business logic, works with the database and returns a response with a status. The client never goes to the database directly. Middle/Senior: I go through the path stage by stage: what the client sent (Network), whether the request arrived (DNS, TLS, load balancer), what the server answered and what the state is afterwards. That way the bug reaches the right team with a curl reproduction. I add that a response is not always final: with asynchronous processing I check the final state with a separate request.

More articles in this chapter