Ordersloading…tea×2cake×1juice×3webapp1fetch("/api/orders")2 .then(r => r.json())3 .then(showOrders)1@app.get("/api/orders")2def orders():3 rows = db.execute(SQL).fetchall()4 return {"orders": rows}GET /HTMLCSSJSGET /api/ordersSELECT3 rows{"orders":[…]}
Back row: the browser (front end), then the web server, app server and database (back end)Front row: app.js runs in the browser, app.py runs on the app serverEnvelopes: HTTP requests and SQL · tiles: files, rows and JSON coming backThe browser at the back left is the front end; the web server, app server and database are the back end. The cards in front are the code each side runs. GET / brings back three static files; then fetch("/api/orders") travels to the web server, on to the app server, whose code asks the database and sends JSON back for the page to show without reloading. The web server, app server and database are drawn as three machines. In practice they are three programs (for example NGINX, a Python app run by a server such as Gunicorn, and PostgreSQL) that may share one computer or be spread over many.

Two halves

  1. A web app is split in two. The front end runs in your browser and draws what you see. The back end runs on servers far away: it keeps the data and does the work. They talk over HTTP.

Loading the page

Asking for data

Where code runs

What happens

;; step 1/11 · two-halves
front end   runs in the browser, on your device
            HTML, CSS and JavaScript
back end    runs on servers
            web server, app server, database
between     HTTP requests and responses

The web server, app server and database are drawn as three machines. In practice they are three programs (for example NGINX, a Python app run by a server such as Gunicorn, and PostgreSQL) that may share one computer or be spread over many. Each HTTP request and response is shown as one envelope. Underneath, they travel over a TCP connection (or QUIC with HTTP/3), usually encrypted with HTTPS; the HTTP and HTTPS lessons in the Networking course show how.