Related tables
| ID | Name |
|---|---|
| C7 | Maya |
| ID | Customer | Total |
|---|---|---|
| O42 | C7 | 10 |
Customer ID connects the records.
| ID | Name |
|---|---|
| C7 | Maya |
| ID | Customer | Total |
|---|---|---|
| O42 | C7 | 10 |
Customer ID connects the records.
Useful order fields stay together. Decide which values to repeat and how to update them.
A shopping application must remember customers, products and orders after a server restarts. A database stores that information and provides ways to read and change it. The right choice depends on the questions the application asks and the promises each write must keep.
Relational databases organise information into tables with relationships. NoSQL is an umbrella term for several other models, including documents and key-value records. It is not one product, and it does not mean that every such database has the same guarantees.
A table stores rows with named columns. A customer row may have an ID and name; an order row may store that customer’s ID. A join combines related rows when you need their information together. This can keep one customer address in one place rather than repeating it in every order.
A document stores a group of named fields, often with nested items. Keeping an order and its line items together can make reading that order convenient. Repeated data may need extra updates when it changes. Flexible documents still need validation; the absence of one fixed table layout does not remove the need for a clear data model.
List the application’s access patterns: find an order by ID, list one customer’s orders, and total sales by date. These concrete reads and writes are more useful starting points than choosing a database because it is fashionable.
Choose an order. A scan visits records in order; the directory maps an ID to a record.
Highlighted records show what the scan inspected. The directory is a teaching map, not a model of a particular database’s index internals.
The browser example contains eight orders. A scan checks records one at a time until it finds the requested ID. A lookup directory points to the record for that ID. Send a query using each approach and compare the highlighted records and work counted.
This is a small in-memory teaching model. A real database index has its own structure and cost; one directory lookup here does not mean every indexed database query takes one operation or constant time. Real engines may choose a scan when it is cheaper.
An index is an additional structure that helps locate records for a particular query. An index on customer ID may help list that customer’s orders; it does not automatically make every report faster. It uses storage and must be maintained when indexed values change.
CREATE INDEX orders_customer_id_idx
ON orders (customer_id);This PostgreSQL example creates an index for a column used in customer lookups. Use EXPLAIN to inspect how an actual query is planned, and measure it with representative data. Read the index documentation before creating an index on a busy live table.
Measure read latency, write latency, data size and storage growth. A read improvement can carry a write and storage cost, so keep only indexes that serve useful access patterns.
Commit both, or roll back both
Buying the last available ticket may require reserving stock and recording the order together. A transaction groups changes so they commit together or are rolled back. Concurrent buyers also need an appropriate locking, conditional-write or isolation design so both cannot claim the same last ticket.
SQL versus NoSQL alone does not settle this requirement. PostgreSQL supports transactions; DynamoDB also provides transactions, with its own scope and limits. Check the product’s actual guarantees and design the write correctly. A transaction cannot make an external payment and an unrelated database write magically one atomic action.
Durability means accepted data can survive the failures covered by the database’s configured guarantees. Replication keeps additional copies; backups and tested restore procedures address other recovery needs. Neither a product label nor one healthy replica replaces a recovery plan.
Representative products and licensing sources checked 6 October 2026. No product has one universal reads/s or writes/s capacity independent of data, indexes, hardware and consistency settings.
Free software and paid hosting are separate decisions. Managed PostgreSQL is another possible operating model; managed hosting does not change tables into a different data model. Compare backup support, upgrade work, failure recovery and cost as well as query speed.
Start by evaluating PostgreSQL when relationships, coordinated changes and varied queries are central. Compare it with alternatives using the actual workload. The trade-off includes schema changes, index maintenance and the team’s operating work.
Evaluate MongoDB when an order-like document closely matches how the application reads and updates data. Consider document growth, repeated fields and cross-document changes. Choosing documents should simplify the access pattern, rather than hide relationships the application still needs.
Evaluate DynamoDB when the important requests are known and fit a deliberate key design. Managed operation can help a small team, while unfamiliar queries, uneven hot keys and usage costs need planning. “NoSQL scales” is not a substitute for designing the keys.
For each candidate, measure representative reads and writes, errors and latency during a failure. Check growth and restore requirements before making the choice.
ACID describes atomicity, consistency under defined rules, isolation and durability. Atomicity means a transaction’s changes commit together or are rolled back. It does not make a payment API call part of the database transaction. Durability depends on the actual storage and acknowledgement configuration.
Isolation determines which concurrent changes a transaction can observe and which interference is prevented. PostgreSQL Read Committed uses a new snapshot for each command; stronger isolation levels have different rules and may require retries. Product names such as SQL or NoSQL alone do not identify the isolation contract.
For the last seat in a booking, “read available, then write reserved” is unsafe if two callers can both pass the check. Use a suitable constraint, conditional write, lock or isolation strategy, and handle conflicts deliberately. Read PostgreSQL isolation documentation and continue with cross-service transactions.
A key-value store retrieves a value by a key and can fit simple access patterns. A wide-column database organizes data around partition keys and columns; designs such as Cassandra require deliberate query and partition planning. A graph database represents entities and relationships and can fit relationship traversal, such as finding connected accounts.
Relational tables can also model graphs and documents; the model alone does not decide the product. Compare the operations you need, transaction boundaries, indexing, concurrency and operating skills. Redis, Cassandra and Neo4j are examples in these families, not interchangeable recommendations.
Normalization keeps facts under clear ownership and avoids redundant copies where appropriate. Denormalization duplicates or precomputes selected facts for reads and needs an update rule. Read the indexing lesson before trading consistency work for a faster query.
Start from the information you store, the reads you need and the guarantees each write must keep. Tables and documents organise information differently; actual product features matter more than broad labels.
Indexes trade storage and write work for useful lookups. Transactions and concurrency rules protect coordinated changes. Measure realistic workloads, plan growth, and practise restoring data.
Reaching the recap and completing the quizzes are separate milestones.