Where data lives, how it is searched, and how databases scale and stay secure.
Lectures this week
- Memory Hierarchy
- Data Search
- Database Search
- SQL vs. NoSQL
- Scaling
- Security of Databases
Key points, notes and past questions
Web Architecture, Protocols & Rendering
The HTTP request cycle, statelessness, rendering location and scaling vocabulary.
- The request cycle and HTTP methods
- DNS first: the name becomes an IP address.
- Then request, response (or error code), and display.
- GET returns headers and body; HEAD returns headers only.
- MVC is a software architecture pattern; IP addresses and routes data.
- Statelessness and cookies
- Stateless: the server keeps no client state between requests.
- A cookie is stored by the browser and sent back with each request.
- Cookies let sites recognise users and remember login, language, location.
- Flask reads cookies with
request.cookiesand sets them withset_cookie.
- Server-side and client-side rendering
- SSR: the server sends complete HTML (Flask + Jinja2).
- CSR: the server sends a skeleton and JS; the browser builds the DOM.
- SSR: faster first load, better SEO.
- CSR: less server rendering work, smoother partial updates.
- Cloud models and scaling
- IaaS: machines; PaaS: platform (bring code); SaaS: finished app.
- Scale up = bigger machine (RAM); scale out = more machines.
- ACID for financial transactions; BASE for social media scale.
- Redundancy = spares for failure; replication = copies of data/service.
Notes11 past questions in this topic
System Performance, Hardware & Encoding
The numbers behind encoding, time, disks, memory and server capacity.
- Start here: units from zero
- 8 bits = 1 byte; small b is bits, capital B is bytes.
- k, M, G go up by 1000 (1024 only when stated).
- rate × time = amount; amount ÷ rate = time.
- Convert to one unit before you divide.
- Bits for a character set
- Bits per symbol = ⌈log₂ k⌉.
- The space is a symbol.
- Size = length × bits per symbol.
- Adding symbols changes only the bits per symbol.
- Running time: plug in and scale
- Given n: compute both.
- Scale: × f(n₂)/f(n₁).
- n²: square the ratio; n log n: ratio × log ratio.
- Constants decide below the break-even n.
- Memory hierarchy and disks
- Register → SRAM → DRAM → SSD → HDD: slower and bigger.
- HDD: highest latency, lowest throughput.
- rev/s = RPM ÷ 60.
- Worst delay = one turn; average = half.
- DRAM bandwidth
- 64 bits = 8 bytes.
- DDR × 2, dual channel × 2.
- Use only the factors the question states.
- Recompute when one number changes.
- Propagation and processing delay
- Time = distance ÷ speed.
- Cable 2 × 10^8 m/s, air 3 × 10^8 m/s.
- Add each leg and the server delay.
- Closer servers cut latency.
- Server capacity
- Bits = bytes × 8.
- Network limit = link ÷ bits per request.
- Answer = the smallest limit.
- Memory: peak users × memory per user.
Notes18 past questions in this topic
Databases, SQL & Flask-SQLAlchemy
Storing data and querying it from Flask.
- Start here: tables, rows and keys from zero
- Table = grid; row = one thing; column = one fact.
- Primary key: unique in every row.
- Foreign key: another table's primary key, a link.
- NULL means no value, not 0.
- Database families, graphs and indexes
- RDBMS: tables, keys, constraints, transactions.
- Key-value: one key → one value, fastest lookups.
- Graph: nodes + edges with properties; paths matter.
- Index: faster reads, slightly slower writes.
- SQL: WHERE, GROUP BY, HAVING, ORDER BY
- WHERE → GROUP BY → HAVING → SELECT → ORDER BY.
- Aggregates per group; HAVING filters groups.
- ASC = smallest first (the default).
- No aggregates in WHERE.
- SQLite's own behaviour
- Bare columns are allowed in SQLite.
- One-row group → exact value.
- Stored text keeps its case.
- LIKE ignores ASCII case; dates are text.
- Models and column options
- Every model needs a primary key.
- nullable defaults to True; mandatory = nullable=False.
- unique ≠ NOT NULL.
- Constructor: keyword arguments only.
- Default table name: snake_case of the class.
- Foreign keys and cardinality
- Key on the many side.
- Plain key → one-to-many; unique key → one-to-one.
- Association table → many-to-many.
- Key = db.Column(type, db.ForeignKey('lowercase_table.col')).
- The session: add, commit, update
- Model(k=v) → add → commit.
- first() = one object or None; all() = list.
- Change attributes, then commit, to update.
- rollback drops uncommitted changes.
- relationship(), backref, objects and ids
- Column ← id; relationship ← object.
- backref creates the other attribute; back_populates needs both sides.
- New objects have id None until written.
- uselist=False → one object, not a list.
- Queries: filter, filter_by, aggregates and dates
- filter_by: keywords, equality, AND.
- filter: expressions with &, and_(), |, or chained.
- Never Python
and/oron conditions. - Aggregates: query(func.max(col)).scalar().
- Dates: subtract in Python, not in SQLite SQL.
Notes32 past questions in this topic
Week 6: APIs & RESTWeek 8: Application FrontendAll MAD 1 topics and weeks