Databases and data services — the interplay between frontend and data
Tables, keys, SQL, and how a web solution securely communicates with its data
A website that does not remember anything is not worth much in practice — a web shop must remember orders, a forum must remember posts and a login must remember who you are. That is the database's job. The regulations for web developer education point directly to this as a separate subject area: the student must be able to explain the interaction between database structure and frontend and use relevant data services for developing web solutions.
§The relational database – tables, rows and keys
The most widespread type of database on the web is the relational database. Data lies in tables, where each row is one record and each column is a specific field — a table of users has for example columns for name, email and creation date. Each row has a primary key, a unique ID that points precisely to that one record. Connections between tables are made with foreign keys: an orders table doesn't store the customer's name and address again, but just the customer's ID, which points back to the customers table. This is the core idea of the relational — data is divided up, but connected via keys.
§SQL and CRUD – the four basic operations
SQL (Structured Query Language) is the language used to query a relational database. Regardless of which program or framework lies between them, it almost always ends in the same four basic operations, often called CRUD.
- 01Create — create a new record (SQL: INSERT)
- 02Read – fetch one or more records (SQL: SELECT)
- 03Update—correct in an existing post (SQL: UPDATE).
- 04Delete — remove a row (SQL: DELETE)
§Normalization – avoid storing the same thing in multiple places
Normalization is the work of structuring tables so the same information is not stored in multiple places unnecessarily. If you store a customer's address on every single order, all orders must be corrected if the customer moves – and if you don't do it consistently, contradictory data arises. By instead storing the address in one place and letting orders point to it via a foreign key, the truth exists in only one place. It costs a bit more to fetch data together (you have to 'join' the tables), but gains significantly in consistency and maintenance.
§Relational or NoSQL – choose based on data, not fashion
Not all data fits equally well into fixed tables with columns. NoSQL databases (document, key/value and graph databases are the most common types) store data more flexibly, often as documents without a fixed template for each field. They are well-suited for data that varies greatly in form, or where you need to scale to very large amounts of writes. Relational databases have the advantage when data has clear relationships and you need guarantees that an action either goes through completely or not at all (transactions).
| Property | Relational database | NoSQL (e.g. document database) |
|---|---|---|
| Structure | Fixed tables with columns. | Flexible documents varying fields |
| Connections | Foreign keys and joins | Often data collected in one document |
| Best for | Data with clear relationships and consistency requirements | Data that varies in form or has very high write speed |
| Language | SQL | Varies from system to system |
§Ornithosis (parrot fever) — respiratory infection from birds, particularly relevant when keeping birds.
Instead of writing raw SQL queries everywhere in the backend code, many use an ORM (Object-Relational Mapper). It lets you work with the database's tables as ordinary objects in your programming language and translates it to SQL behind the scenes. It makes the code easier to read and less error-prone — but it is still important to understand what the ORM actually sends to the database, especially when a query becomes slow because it fetches far more data than the page actually needs.
§The data service must be secured, not just built
A data service is the layer that makes data available to the frontend — typically an API that speaks HTTP, as described in the article on web APIs. Access to data must be controlled the same way as the rest of the backend: only authenticated and authorized calls may read or modify data, the connection to the database must be protected with a login that never sits in the frontend code, and sensitive data should only be sent forward when it is genuinely necessary for the task.
“A database is not just a place data sits and waits — it is a structure that either helps you or prevents you from trusting your own data.”
— Common teaching principle in database design