Databases behind apps
Almost every app you use needs to remember things: your username, your settings, your messages, your scores. It stores those things in a database. When you open the app, it asks the database for the data it needs and shows it to you.
Even a simple to-do list has a database. Each to-do is a row with a title, a done/not-done flag, and maybe a due date. The app reads and updates that table every time you check something off.
APIs and ORMs
Most apps do not write raw SQL directly from the user interface. Instead, the app talks to the database through an API or an ORM.
An API is a set of endpoints that the frontend calls. The backend then runs SQL on the database and returns the result. An ORM, or Object-Relational Mapper, lets programmers work with database rows as if they were objects in their programming language. Both make it safer and easier to avoid mistakes.
Example: A social media app might have an endpoint like /api/posts. The frontend requests it, the backend runs SELECT * FROM Posts, and the database sends back the data.
SQL vs NoSQL
Relational databases are not the only option. NoSQL databases store data in other ways, such as documents, key-value pairs, or graphs. They are often chosen when data is flexible or very large.
MongoDB stores documents that look like JSON. Redis stores key-value pairs very fast, often for caching. Graph databases store relationships between people or things. The right choice depends on the app.
Privacy and responsibility
When you store data about people, you have a responsibility to protect it. Personal information like names, emails, addresses, and passwords should be stored securely. Passwords should never be saved as plain text; they should be hashed using a one-way function.
You should also only collect the data you actually need. This is called data minimization. It lowers the risk if a breach ever happens and builds trust with your users. Always follow privacy laws and your school's or organization's policies.
Good habit: back up your database regularly and test restoring from the backup. Losing user data is one of the worst failures a project can have.
App stack explorer
Press the buttons below to see how a request travels from a user click, through an API, to the database, and back. Notice what each layer does.
Reading a CSV file
Much real-world data starts as a CSV file. This Python program reads a CSV, filters the rows, and prints a small report.
Check yourself
Pick an app you use. Name one piece of data it probably stores in a database and one thing it might need to keep private.
Your answer:
Sample answer: A messaging app stores messages, contacts, and passwords. Passwords and private messages must be protected with encryption or hashing.
Quick quiz
1. What does an ORM do?
2. Why should passwords be hashed?
3. When might you choose NoSQL?
Keep learning
You have finished the Data and Databases series. Next, explore how computers talk to each other over networks.
Last tutorial in the Data and Databases series.