Introduction to databases and persistence

The Relational Model

SQL Basics, DDL, and DML

Querying Data

Advanced Concepts

Sqlite

Glossary of Database Terms

Practice

Assignment

Core program

What is a Database?

At its simplest, a Database is an organized collection of data. It is usually stored electronically on a computer system.

Databases can be simple, like a contact list on your phone. They can also be complex, like the systems powering Facebook or your bank.

The Concept of Persistence

Persistence means that data survives after the program finishes.

Without persistence, data only lives in your computer's RAM (temporary memory). If you turn off the computer or close the program, that data is lost.

Why do we need persistence?

Your notes had a great example about wolves marking territory or humans making cave paintings. Here is a technical summary:

  1. **Durability:** Data must survive if the computer crashes or the power goes out.
  2. History: We need to keep records of the past (like bank transactions).
  3. Sharing: Many users need to look at the same data at different times.

<aside> πŸ’‘

An aside: Humans are not the only ones that use persistence on purpose.

These are pretty basic uses of persistence, but it shows that persistence has been around for a long time πŸ™‚

</aside>

<aside> πŸ’‘

Another aside:

Persistence existed before there was written language (but there was spoken language). The database was the lessons and rules of your tribe or cultural group, and the persistence layer were story tellers.

For centuries, information that was important to a group was told to everyone through stories by story tellers, who held a very important position in the group as the holder of the group’s wisdom. They would then have apprentices who would learn the stories and collected wisdom and tell it to the next generation. Eventually, these stories were written down.

We also see persistence in the form of drawings in the ancient cave paintings. They would communicate important information. And here we are thousands of years later and their information is still to be seen.

</aside>

In the physical world, we, now, use paper or books to persist information. For hundreds of years libraries were our databases, and books and magazines our way of keeping information safe for later use. In the digital world, we use Filesystems.

The Filesystem: The Foundation

Almost all databases store their data on a Filesystem (like the hard drive on your laptop).

The filesystem manages how data is written to the physical disk. A DBMS (Database Management System) is a specialized program. It manages these files efficiently for you.


Types of Database Systems

There is no "one size fits all" solution. Different problems need different databases.

Type Description Best For Examples
Relational (RDBMS) Data is stored in Tables with rows and columns. Relationships are strict. Uses SQL. Financial systems, user accounts, inventory. SQLite, PostgreSQL, MySQL
Document Store (NoSQL) Data is stored as documents (similar to JSON). The structure is flexible. Content management, fast prototyping. MongoDB, CouchDB
Key-Value Store Simple "dictionary" storage (Key -> Value). Very fast. Caching (temporary storage), session management. Redis, Memcached
Graph Database Stores data as nodes (dots) and edges (lines). Great for connecting things. Social networks, friend recommendations, navigation routing Neo4j, Amazon Neptune
Search Engine Optimized for searching text. Search bars, analyzing logs. Elasticsearch, Solr
Time Series Optimized for measuring change over time. Sensor data, stock market prices. InfluxDB, Prometheus

Why focus on Relational Databases (SQL)?

Even with many new types of databases, Relational Databases are still the standard for most businesses.


Key Terms Summary

Term Definition
Database An organized collection of information.
DBMS Database Management System. The software that manages the database (e.g., PostgreSQL).
Server A program that runs in the background and listens for requests.
Client The program that connects to the server (e.g., your Node.js app).
Query A request for data from a database.

The HackYourFuture curriculum is licensed underΒ CC BY-NC-SA 4.0

CC BY-NC-SA 4.0 Icons

*https://hackyourfuture.net/*

Found a mistake or have a suggestion? Let us know in the feedback form.