← Module 2: Programming for the Web
Inquiry Question 1: How are secure web applications developed?
Describe the client-server architecture of the web, including the roles of the browser, web server, application server and database
A focused answer to the HSC Software Engineering Module 2 dot point on web architecture. Browser, web server, application server, database, the request-response cycle, the worked three-tier example, and the traps markers look for.
Have a quick question? Jump to the Q&A page
What this dot point is asking
NESA wants you to describe how a modern web application is split across several tiers - browser, web server, application server, database - and explain what each does. The request-response cycle is the canonical worked example.
The answer
A modern web application is split across four tiers, with the browser on the user's device and the other three on the server side. The diagram shows the path of one request and response.
The four tiers
Most web applications follow a three- or four-tier architecture:
- Client (browser): runs HTML, CSS, JavaScript. Displays the UI. Sends HTTP requests in response to user actions.
- Web server: handles HTTPS termination, serves static files, routes dynamic requests to the application server. Examples: Nginx, Apache, Caddy.
- Application server: runs the business logic. Reads input, applies authorisation, queries the database, formats output. Examples: a Python Flask app, a Node.js Express server, a Java Spring service.
- Database: persistent storage. Relational (PostgreSQL, MySQL, SQLite) or NoSQL (MongoDB, DynamoDB). Only the application server connects to it directly.
Some setups split or merge these tiers (single-page apps with a separate API tier, serverless functions that combine web and application server, monoliths that bundle web and application server).
The request-response cycle
- The user clicks "Add to cart".
- The browser issues a POST request:
POST /api/cart HTTP/1.1 Host: shop.example.com Content-Type: application/json Body: {"product_id": 42}. - The web server receives the request, terminates HTTPS, and forwards it to the application server.
- The application server authenticates the session token, validates the product ID, and runs the handler.
- The handler calls the database:
INSERT INTO cart_items (user_id, product_id) VALUES (?, ?). - The database executes the query and returns success.
- The handler returns a 201 response with the new cart contents as JSON.
- The web server forwards the response to the browser.
- The browser updates the UI based on the JSON response.
Most pages involve multiple requests: the initial HTML, several CSS and JavaScript files, images, fonts, and any AJAX calls JavaScript makes.
A worked code example
A minimal three-tier slice in Python with Flask:
from flask import Flask, request, jsonify
import sqlite3
app = Flask(__name__)
def db():
return sqlite3.connect("shop.db")
@app.post("/api/cart")
def add_to_cart():
user_id = authenticate(request.headers.get("Authorization"))
if not user_id:
return jsonify(error="unauthenticated"), 401
data = request.get_json()
product_id = int(data["product_id"])
with db() as conn:
conn.execute(
"INSERT INTO cart_items (user_id, product_id) VALUES (?, ?)",
(user_id, product_id),
)
return jsonify(status="ok"), 201
In front of this app, Nginx (web server) handles HTTPS and serves static files. Behind it, SQLite (database) stores cart data.
Why split into tiers
- Separation of concerns: each tier has a focused job and uses tools optimised for that job.
- Scalability: each tier can scale independently. If the database is the bottleneck, scale the database. If application logic is the bottleneck, run more application server instances.
- Security: only the application server reaches the database. The database is not exposed to the internet.
- Maintainability: changes to the UI (browser tier) do not force changes to the database schema.
Past exam questions, worked
Real questions from past NESA papers on this dot point, with our answer explainer.
2024 HSC5 marksExplain the roles of the browser, web server, application server and database in a typical web application. Trace the path of a single user request from click to displayed page.Show worked answer →
The four roles in a typical three-tier web app:
Browser (client): renders HTML, runs JavaScript, sends HTTP requests, displays responses. The user's window into the system.
Web server: terminates HTTPS, serves static assets (HTML, CSS, JavaScript, images), and forwards application requests to the application server. Examples: Nginx, Apache.
Application server: runs the business logic (the developer's code in Python, Node, Ruby, Java). Reads and writes the database, applies validation and authorisation, returns dynamic responses.
Database: stores persistent data. Relational (PostgreSQL, MySQL) or NoSQL (MongoDB). Only the application server talks to it.
Trace of one request:
- User clicks a link. The browser issues a GET request over HTTPS.
- The request reaches the web server, which serves the page shell or forwards the call to the application server.
- The application server authenticates the request, runs the handler, queries the database with a parameterised SELECT.
- The database returns the rows.
- The application server renders the response (HTML or JSON) and returns it to the web server.
- The web server forwards the response to the browser.
- The browser parses HTML, fetches CSS/JS/images, runs JavaScript, displays the page.
Markers reward all four roles, named tiers in the right order, and an end-to-end trace including the database round trip.
Related dot points
- Explain the HTTP protocol, including request methods, status codes and headers, and the role of HTTPS in securing web traffic
A focused answer to the HSC Software Engineering Module 2 dot point on HTTP. Request methods, status codes, headers, the role of HTTPS and TLS, the worked example, and the traps markers look for.
- Implement server-side programming, including routing, handling requests, generating responses and integrating with a database
A focused answer to the HSC Software Engineering Module 2 dot point on server-side programming. Routing, handlers, response building, database integration, the worked Flask example, and the traps markers look for.
- Design a relational database schema and write SQL statements to create tables, insert data, query with joins, and update or delete rows
A focused answer to the HSC Software Engineering Module 2 dot point on relational databases. Schema design, primary and foreign keys, SELECT with JOIN, INSERT, UPDATE, DELETE, the worked example, and the traps markers look for.