Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
How a Full-Stack App Fits Together  ›  Lesson

The Round Trip: Browser to Database and Back

JavaScript 14 minA request travels from a browser event through the network, the server's routing, identity check and handler, down to the database and back as JSON that the client renders, and debugging means finding the first hop where the data goes wrong.

The Round Trip: Browser to Database and Back

Open Sprout's "My plants" screen and a list appears in a fraction of a second. In that time a request crosses the internet, runs your server code, questions the database and travels all the way back. When something goes wrong, knowing each hop tells you exactly where to look.

The rule

Out through the server, down to the data, back as JSON, onto the screen.

Here is the whole trip for Sprout's plant list:

  1. Trigger. The screen appears and its JavaScript calls fetch('/api/plants').
  2. Network. The browser finds the server's address (DNS), opens a secure connection (TLS) and sends the request, with the user's login cookie attached.
  3. Routing. The server matches the method and path, GET /api/plants, to a handler function.
  4. Identity. Before the handler, a check reads the cookie and works out which user is asking.
  5. Query. The handler asks the database for that user's plants.
  6. Rows to JSON. The database returns rows. The server turns them into JSON and picks a status code.
  7. Response. The answer travels back over the same connection.
  8. Render. JavaScript parses the JSON, stores it and redraws the list.

What actually crosses the network is plain text:

GET /api/plants HTTP/1.1
Host: sprout.example.com
Cookie: token=eyJhbGciOi...
HTTP/1.1 200 OK
Content-Type: application/json

[{"id": 7, "name": "Fern", "water_every_days": 3, "last_watered": "2026-09-24"}]

Notice that each layer only speaks to its neighbour. The browser never sees SQL, and the database never sees HTTP. The server is the translator between the two.

The shortcut

When something is wrong, walk the trip and find the first hop where the data is wrong. The browser's developer tools (the Network tab) show the request and response in the middle of the trip, so start there:

  • Response correct, screen wrong: the bug is in the client.
  • Response wrong: go down to the server's handler and its query.
  • No response at all: the network or the server process is down.
  • A 4xx status says the request was refused; a 5xx says the server failed.
Debugging a missing plantStep 1 of 4
  1. The symptom

    Asha added "Basil", but it is not in her list.

Guessing from the screen alone would have sent you into the React code. Checking the middle hop first cut the search in half.

Drills

Answer fast — trust the rule.

quick drill

In Sprout's round trip, which layer turns database rows into JSON?

quick drill

The Network tab shows the right five plants in the JSON, but only four appear on screen. Where is the bug most likely?

quick drill

Which step happens before the server's handler code runs?

quick drill

A request comes back 500 Internal Server Error. Where do you look first?

Remember

  • Out through the server, down to the data, back as JSON, onto the screen.
  • Shortcut: walk the trip and find the first wrong hop; the Network tab shows the middle.
  • Trap: guessing from the screen alone. A wrong list can start in the handler, the query or the data.

Practice — level up

0/1 solved

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

ExplainThe rename that did not stick

A user reports: 'I renamed my Fern to Boston Fern, the screen showed the new name, but after I refreshed it was Fern again.' Walk the round trip and explain where you would look, in what order, and what each finding would tell you.