Bachelors Program in Full Stack Development
Backend Frameworks (Node.js/Django)
•
Bachelor
Backend Systems and Web Foundations
Introduction
Every modern web application depends on a backend system. A user may see a page, mobile interface, or API response, but behind that visible experience are networks, protocols, servers, application logic, databases, security controls, and operational processes. Backend development is therefore more than writing code that runs on a server. It involves designing reliable communication between independent systems and managing data and computation across a network.
This chapter establishes the conceptual foundation required for later study of Node.js, Django, and other backend frameworks. It explains how browsers and applications communicate with servers, how domain names become network destinations, how HTTP messages are structured, and how backend systems maintain identity, security, and state.
A useful distinction is that a framework provides tools and conventions, whereas web foundations define the environment in which those tools operate. A Node.js application still communicates through HTTP, uses DNS and ports, serializes data, and must address authentication, errors, scalability, and security. Similarly, Django does not replace web architecture; it organizes and accelerates its implementation.
Learning Objectives
By the end of this chapter, you should be able to:
explain client–server and layered web architectures;
describe the roles of DNS, IP addresses, ports, web servers, and application servers;
trace an HTTP request–response lifecycle;
distinguish HTTP from HTTPS and explain the role of TLS;
interpret common HTTP methods, status codes, headers, cookies, and sessions;
explain serialization and compare common data formats;
distinguish stateless protocol operation from stateful application behavior;
identify major backend responsibilities, risks, and professional design practices.
The Client–Server Model
In the client–server model, a client requests a service and a server provides it. A web browser, mobile application, command-line tool, or another backend service can act as a client. A server is a program or system that listens for requests and produces responses. The terms describe roles rather than physical machines: one computer may be a client in one interaction and a server in another.
A simple interaction is:
The client identifies a destination.
It establishes network communication.
It sends a request.
The server interprets the request and performs work.
The server returns a response.
The client presents or processes the result.
The server may retrieve data from a database, call another service, validate permissions, render a page, or return a structured API result. In a distributed system, the initial server may itself become a client of several other services.
Layered Architecture
Web systems are commonly understood through layers:
Layer
Main concern
Examples
User interface
Interaction and presentation
Browser, mobile app
Application
Business rules and workflows
Node.js service, Django view
Data
Persistence and retrieval
PostgreSQL, Redis, object storage
Transport and network
Delivery between machines
TCP, IP, DNS
Physical/infrastructure
Machines and connectivity
Cloud instances, networks
Layering reduces complexity. A browser does not need to know how a database stores a row, and a database does not need to understand the visual design of a webpage. Interfaces between layers allow components to evolve independently.
Layered web request architecture
Figure: Layered web request architecture
Figure: A simplified layered model of a web request.
DNS, Addresses, and Ports
Humans generally use domain names such as example.org, while networks deliver packets to IP addresses. The Domain Name System (DNS) is a distributed naming system that maps domain names to resource records. A common address record maps a name to an IPv4 address; an AAAA record maps it to an IPv6 address. DNS can also identify mail servers, aliases, and other resources.
A DNS lookup may involve the client’s resolver, recursive DNS servers, and authoritative name servers. Results are commonly cached for a period specified by the record’s time to live (TTL). Caching improves speed and reduces query traffic, but it means that a DNS change may not be visible everywhere immediately.
An IP address identifies a network endpoint, but a machine can run many network services. A port identifies the service endpoint within a host. TCP port 80 is conventionally associated with HTTP, and TCP port 443 with HTTPS, although software can use other ports. A URL therefore combines several ideas:
Here, https is the scheme, api.example.org is the host name, 443 is the explicit port, /orders/42 is the path, and details=full is a query string. The fragment portion of a URL, if present, is normally interpreted by the client and is not sent to the server in an HTTP request.
Web Servers and Application Servers
A web server accepts network connections and handles HTTP-level concerns. It may serve static files, terminate TLS, compress responses, enforce basic access rules, and forward dynamic requests. Examples include Nginx, Apache HTTP Server, and the built-in HTTP capabilities used in some application deployments.
An application server executes application code. It applies business rules, validates input, interacts with data stores, and creates a response. In Node.js, an HTTP process may perform both web-server and application-server functions. In Django, a deployment commonly places a reverse proxy such as Nginx in front of an application server using a gateway interface such as WSGI or ASGI.
The distinction is architectural rather than absolute. A reverse proxy can distribute requests among multiple application instances, provide TLS termination, and shield internal services. Separating responsibilities can improve security, performance, and operational control, but it also adds configuration and monitoring requirements.
The HTTP Request–Response Lifecycle
HTTP is an application-layer protocol for transferring resources and representations. A request typically contains a method, target, protocol version, headers, and optionally a body. A response contains a status code, headers, and optionally a body.
A request can be represented conceptually as:
GET /products/18 HTTP/1.1
Host: shop.example
Accept: application/json
Authorization: Bearer <token>
The response might be:
HTTP/1.1 200 OK
Content-Type: application/json
{"id":18,"name":"Notebook"}
Common methods include:
Method
Typical purpose
Important property
GET
Retrieve a representation
Should not intentionally change server state
POST
Submit data or request creation/action
May create different effects on repetition
PUT
Replace a resource representation
Intended to be idempotent
PATCH
Partially modify a resource
Semantics depend on implementation
DELETE
Remove a resource
Often designed to be idempotent
HEAD
Retrieve headers without response content
Useful for metadata checks
An operation is idempotent when repeating the same request has the same intended server effect as performing it once. Idempotence does not mean that every response is identical; timestamps, logs, or counters may still differ.
Status codes communicate broad outcomes. Codes in the 2xx range indicate success, 3xx redirection or conditional behavior, 4xx client-side problems, and 5xx server-side failures. For example, 201 Created indicates successful creation, 400 Bad Request indicates an invalid request, 401 Unauthorized usually means that authentication is required or invalid, 403 Forbidden indicates that the server understood the request but refuses it, 404 Not Found indicates that the target was not found, and 500 Internal Server Error indicates an unexpected server-side condition.
A request lifecycle may include DNS resolution, connection establishment, TLS negotiation, request transmission, routing, authentication, validation, business processing, database access, response construction, and delivery. Observability tools should measure these stages because a slow response may result from DNS, network latency, application code, a database query, or a downstream service.
HTTP and HTTPS
HTTP by itself does not provide confidentiality, integrity, or reliable authentication of the communicating endpoint. HTTPS is HTTP carried over Transport Layer Security (TLS). TLS uses certificates and cryptographic protocols to authenticate a server and protect data in transit.
During a TLS connection, the client and server negotiate protocol parameters, validate the server certificate against trusted authorities, and establish session keys. Subsequent application data is encrypted and authenticated. HTTPS does not make an application automatically secure: vulnerable authorization logic, malicious input, weak passwords, and exposed secrets remain possible.
Professional systems should use HTTPS for all sensitive traffic, redirect insecure requests where appropriate, use secure certificate management, and avoid mixed content. HSTS can instruct browsers to use HTTPS for a domain, but it must be deployed carefully because it can make recovery from configuration errors more difficult.
Headers and Message Metadata
Headers carry metadata about requests and responses. Important examples include:
Host: identifies the requested host;
Content-Type: describes the media type of the body;
Content-Length: indicates body size in applicable messages;
Accept: states preferred response media types;
Authorization: carries credentials or a token scheme;
Cache-Control: controls caching behavior;
Location: identifies a redirected or newly created resource;
Set-Cookie: asks a client to store a cookie;
Origin and Referer: provide context useful to security policies, though they should not be treated as complete proof of identity.
Headers are not automatically trustworthy merely because they appear in a request. A client can construct many headers directly. Backend code must validate security-sensitive claims through trusted mechanisms.
Cookies, Sessions, and Statelessness
A cookie is a small piece of data stored by a user agent and associated with a domain and path. The server sends a cookie with Set-Cookie; the browser may return it in later requests. Cookie attributes affect security and behavior:
Secure limits transmission to HTTPS;
HttpOnly prevents ordinary client-side scripts from reading the cookie;
SameSite restricts cross-site transmission and helps reduce request-forgery risk;
Max-Age or Expires controls persistence;
Domain and Path limit where the cookie is sent.
A session is an application-level mechanism for associating multiple requests with a user or client context. In a server-side session design, the cookie contains an opaque session identifier while session data remains on the server. In a token-based design, the client stores a signed token containing claims, and the server verifies its signature and validity. Tokens are not automatically safer; storage, expiration, revocation, and leakage must be considered.
HTTP is generally described as stateless because each request contains the information needed for that request and the protocol does not require the server to remember prior requests. Applications can nevertheless implement state using cookies, sessions, databases, caches, or tokens. Statelessness improves horizontal scalability when requests can be handled by any instance, but it does not eliminate all state from a real system.
Serialization and Data Representation
Serialization converts an in-memory value into a transferable or storable representation. Deserialization reconstructs a usable value. JSON is widely used because it is readable and supported across languages:
JSON has limitations: it does not directly represent arbitrary binary data, comments, or all language-specific types such as functions. Dates and large integers require agreed conventions. Other formats include XML, form-encoded data, multipart form data, Protocol Buffers, and MessagePack. Format choice depends on interoperability, size, performance, tooling, and human readability.
Backend systems must validate both syntax and meaning. A syntactically valid JSON value may still contain an invalid email address, an unauthorized identifier, or an impossible quantity. Deserialization should also guard against excessive input size, unexpected fields, unsafe object construction, and parser vulnerabilities.
Core Backend Responsibilities
Backend responsibilities commonly include:
Routing: mapping methods and paths to handlers.
Validation: checking type, format, range, and business constraints.
Authentication: establishing who or what is making a request.
Authorization: determining what that identity may do.
Business logic: implementing domain rules consistently.
Persistence: reading and writing durable data safely.
Integration: communicating with payment, messaging, search, or identity services.
Error handling: returning useful public errors while protecting internal details.
Security: defending confidentiality, integrity, and availability.
Observability: producing logs, metrics, traces, and audit records.
Performance and reliability: managing concurrency, timeouts, retries, and capacity.
API design: maintaining clear, documented, and compatible interfaces.
A backend should fail predictably. Timeouts prevent indefinite waiting; bounded retries avoid amplifying an outage; idempotency keys can prevent duplicate effects in retryable operations such as payments. Database transactions help preserve consistency when multiple changes must succeed or fail together.
Applied Case: An Online Course Registration API
The following is an illustrative case.
Background
A university provides an API through which students search courses, view prerequisites, and register. The service is implemented as a Django application behind a reverse proxy and communicates with a relational database.
Problem
During registration periods, students report duplicate registrations, slow responses, and occasional exposure of course data belonging to other departments.
Analysis
Investigation identifies several weaknesses. The client repeats a registration request after a timeout, but the endpoint has no idempotency mechanism. A database query loads unnecessary records, increasing response time. Authorization checks occur only in the user interface, not in the backend. Finally, logs contain full session identifiers.
Approach and Solution
The team defines a resource-oriented API. GET /courses searches courses, while POST /registrations creates a registration. The registration endpoint accepts an idempotency key and stores it with the result so that a safe retry returns the original outcome rather than creating a second registration. A database uniqueness constraint on (student_id, course_id) provides a second line of defense.
Authorization is enforced in the application service, where the authenticated student identity is taken from a verified session and checked against the requested operation. Queries select only required columns and use appropriate indexes. Session identifiers are redacted in logs, and logs receive correlation identifiers that help trace a request without exposing credentials.
Outcome
Duplicate registrations are rejected consistently, response times improve, and cross-department access is blocked at the API boundary. Monitoring now distinguishes DNS, proxy, application, and database latency, making future diagnosis more efficient.
Learning Points
The case demonstrates that backend quality is cross-disciplinary. HTTP design alone cannot guarantee correctness; database constraints, authorization, observability, and retry behavior must work together. Security controls must be implemented on the server, and reliability requires planning for partial failures and repeated requests.
Challenges, Ethics, and Governance
Backend systems process personal, financial, educational, and sometimes biometric information. Developers should collect only necessary data, define retention periods, restrict access, encrypt sensitive information appropriately, and provide auditable controls. Privacy regulations may require lawful processing, transparency, correction, deletion, or breach reporting, depending on jurisdiction and context.
Security threats include injection, broken access control, cross-site request forgery, cross-site scripting, insecure deserialization, credential theft, denial of service, and accidental exposure through logs. Secure development includes dependency updates, secrets management, threat modeling, code review, automated testing, and incident response planning.
AI-enabled backend features introduce additional concerns. A service that sends user data to a model must consider data minimization, provider contracts, prompt injection, output validation, bias, explainability, and human oversight. AI-generated output should not be treated as inherently accurate or authorized to bypass established application rules.
Contemporary Developments and Best Practices
Modern backend systems increasingly use HTTP/2 or HTTP/3, containerized deployment, managed cloud services, asynchronous messaging, and service-to-service authentication. These technologies can improve performance and flexibility but also increase operational complexity. Microservices are not automatically superior to a modular monolith; architecture should reflect team capabilities, domain boundaries, deployment needs, and reliability requirements.
Practical best practices include:
design APIs around clear resources and documented contracts;
validate input at trust boundaries;
use parameterized database queries;
apply least privilege to users, services, and databases;
configure secure cookies and HTTPS;
set explicit timeouts and carefully bounded retries;
make externally visible errors useful but non-sensitive;
maintain structured logs, metrics, and distributed traces;
test authentication, authorization, failure paths, and concurrency;
version APIs when incompatible changes are necessary;
document assumptions and operational runbooks.
Chapter Summary
Web backends coordinate clients, networks, protocols, application logic, and data services. DNS maps names to network resources, while ports identify services on a host. HTTP defines request–response communication through methods, headers, bodies, and status codes; HTTPS adds TLS protection for data in transit and server authentication. Web servers manage HTTP and infrastructure concerns, whereas application servers execute domain logic, although one process may perform both roles.
Cookies provide client-held data, and sessions associate multiple requests with an application context. HTTP is protocol-level stateless, but applications can introduce state through sessions, tokens, databases, and caches. Serialization enables values to cross process and language boundaries, but deserialized data must be validated. Backend responsibilities include routing, validation, authentication, authorization, persistence, integration, security, reliability, and observability. Effective backend engineering combines protocol knowledge with sound architectural, ethical, and operational judgment.
Key Terms
Client: A system that requests a service.
Server: A system or process that provides a service.
DNS: A distributed system that maps domain names to resource records.
IP address: A network address used to identify an endpoint.
Port: A logical service endpoint associated with a host.
URL: A structured identifier for locating a resource.
HTTP: An application-layer protocol for web communication.
HTTPS: HTTP protected by Transport Layer Security.
TLS: A protocol providing encrypted and authenticated communication.
Header: Metadata carried in an HTTP request or response.
Status code: A numeric indication of the broad result of an HTTP request.
Cookie: Client-stored data sent with applicable requests.
Session: An application mechanism for associating related requests.
Serialization: Conversion of an in-memory value into a transferable representation.
Authentication: Establishing the identity of a client or user.
Authorization: Determining what an authenticated identity may do.
Idempotence: The property that repetition has the same intended effect as one execution.
Reverse proxy: An intermediary that receives requests and forwards them to backend services.
Observability: The use of logs, metrics, and traces to understand system behavior.
Review Questions
Short Answer Questions
What roles do a client and a server perform in a web interaction?
Why is DNS caching useful, and what limitation does it introduce?
What is the difference between authentication and authorization?
State two security-relevant cookie attributes and their purposes.
What is serialization, and why must deserialized input be validated?
Long Answer Questions
Explain the complete lifecycle of an HTTPS request from URL entry to response processing.
Compare the responsibilities of a reverse proxy, web server, and application server.
Explain HTTP statelessness and describe three ways an application can maintain state.
Compare GET, POST, PUT, PATCH, and DELETE, including the concept of idempotence.
Discuss the major responsibilities of a production backend and how observability supports them.
Analytical / Application Questions
Design a secure session approach for a university portal. Explain cookie settings, session storage, expiration, and logout behavior.
An API creates duplicate orders when clients retry after timeouts. Analyze the cause and propose defenses involving HTTP semantics, idempotency, and database constraints.
A backend response is slow, but application CPU is low. Develop a diagnostic plan that considers DNS, network connection, TLS, database access, and downstream services.
Multiple Choice Questions with Answers
Question 1
Which component translates a domain name into network-related resource records?
A. DNS
B. HTTP status code
C. Cookie store
D. Database transaction
Correct Answer: A. DNS
Question 2
Which HTTP method is normally used to retrieve a resource without intentionally changing server state?
A. POST
B. GET
C. PATCH
D. DELETE
Correct Answer: B. GET
Question 3
What does HTTPS primarily add to HTTP?
A. Guaranteed application correctness
B. Automatic authorization
C. TLS-based protection and server authentication
D. Permanent server-side sessions
Correct Answer: C. TLS-based protection and server authentication
Question 4
Which status code class generally indicates a client-side error?
A. 1xx
B. 2xx
C. 4xx
D. 5xx
Correct Answer: C. 4xx
Question 5
What is the main purpose of the HttpOnly cookie attribute?
A. To require IPv6
B. To prevent ordinary client-side scripts from reading the cookie
C. To compress the cookie
D. To make the cookie permanent
Correct Answer: B. To prevent ordinary client-side scripts from reading the cookie
Question 6
Which statement best describes authentication?
A. Determining what a user is allowed to do
B. Establishing the identity of a user or client
C. Converting JSON into database tables
D. Mapping a port to a URL
Correct Answer: B. Establishing the identity of a user or client
Question 7
Why is input validation still needed when a request contains valid JSON?
A. JSON automatically grants authorization
B. Valid JSON may still violate type, business, or security rules
C. JSON cannot contain strings
D. HTTP ignores JSON bodies
Correct Answer: B. Valid JSON may still violate type, business, or security rules
Question 8
Which design most directly helps prevent a retried payment request from creating a duplicate charge?
A. Removing the request body
B. Using an idempotency key with server-side enforcement
C. Changing the DNS record
D. Using a 404 response for every retry
Correct Answer: B. Using an idempotency key with server-side enforcement
Question 9
What is the primary role of a port?
A. To identify a service endpoint within a host
B. To encrypt a response body
C. To store a browser cookie
D. To serialize an object
Correct Answer: A. To identify a service endpoint within a host
Question 10
Which statement about HTTP statelessness is most accurate?
A. Applications cannot maintain any user state
B. Every HTTP request must use a different server
C. The protocol does not require the server to remember prior requests, although applications can add state mechanisms
D. Stateless systems cannot use databases
Correct Answer: C. The protocol does not require the server to remember prior requests, although applications can add state mechanisms
Backend Frameworks (Node.js/Django)
Chapter 1
of 14