What is a Database?
Software that stores data in an organized shape you can search, filter, and change directly.
What is it?
Imagine keeping all your app's data in one big text file. To find "all orders Amara placed last week," you'd have to read every line yourself, every time.
A database is software that avoids this. It stores data in organized, labeled structures (usually tables, which look like spreadsheets). It also has its own language for asking questions, like "give me every order from Amara, sorted by date." The database does the searching for you, and fast, even across millions of records.
So you don't just store data in a database. You query it.
Explain like I'm 10
A shoebox of receipts 'stores' your spending, but finding anything means digging through the whole box. A database is a filing cabinet with labeled folders, an index at the front, and a clerk who hands you the folder you ask for in seconds.
Examples
Asking a database a question directly
SELECT name, email
FROM users
WHERE signed_up_at > '2026-01-01';A real query, not pseudocode. It asks for every user who signed up after a date, and the database does the searching.
A database holds many related tables
-- A single small database might contain:
users (people who use the app)
orders (purchases people have made)
products (items available to buy)
reviews (feedback people left on products)A real database is usually a collection of related tables that together hold your app's data.
How it works
A database runs as its own program (like PostgreSQL, MySQL, or SQLite), usually separate from your app. Your app connects to it and sends a query written in SQL (Structured Query Language). The database works out the fastest way to find and return the data you asked for.
The database knows the data's structure: which columns exist, their types, and how tables relate. So it can search, filter, sort, and combine data far faster than your own code scanning everything.
Why does it exist?
Apps need data that:
- outlives a single run of the program
- many users can read and write at once
- can be searched in ways nobody predicted up front
Plain files struggle with all three. They're slow to search, concurrent writes can corrupt them, and each new question needs new one-off code. A database solves storage, search, and safe concurrent access together, with one standard query language.
When to use it
Use a database once your data must persist between runs, may be read or written by several people or processes at once, or needs searching in ways you can't fully predict.
When not to use it
For tiny, single-user, throwaway scripts (a quick calculation, a config file that never changes), a plain file or in-memory variable is simpler. A database there is unnecessary overhead.
Common mistakes
Thinking a database is just 'a place files are stored' instead of a system you query.
Writing custom search code when the database can already filter and sort for you.
Treating a spreadsheet file as a database. A spreadsheet has no query language and no safe way for several people to write at once.
Practice exercises
- Easy:
List three questions you might ask about data in a to-do list app (e.g. 'show me all incomplete tasks'). For each, name the data you'd need.
- Medium:
In your own words, explain why searching a large text file by hand is slower than asking a database.
- Hard:
Describe the tables a simple blog app would need, and a question you'd ask each one.
Interview questions
What is a database, in plain terms?
Software that stores data in an organized structure and gives you a query language to search, filter, and change it directly, instead of scanning it by hand.
Why not just store application data in a plain text file?
Plain files are slow to search (you scan the whole file every time), can be corrupted when two processes write at once, and need new custom code for every new question. A database solves all three by understanding the data's structure and offering a shared query language.
What's the difference between a database and a spreadsheet file like Excel?
A spreadsheet is a single file with no query language and no safe way for several people to write at once. 'Querying' it means filtering or scrolling by hand. A database is running software that understands the data's structure and lets many clients read and write at once through a standard language like SQL.
What does it mean to *query* a database, as opposed to just reading data from it?
You describe what you want ('every order from Amara, sorted by date') and the database works out how to find it. Your code doesn't loop through the data looking for matches.
Why can a database search millions of rows faster than application code scanning them one by one?
The database knows the data's structure (types, relationships) and can use indexes to jump to matching rows instead of checking each one. Code looping over raw data has no such shortcut unless it builds one itself.
What is SQL, and why does it matter that so many different databases understand it?
SQL (Structured Query Language) is a standard language for saying what data you want or how to change it. Most relational databases understand it (with small dialect differences), so your skills and much of your query code carry over between PostgreSQL, MySQL, and SQLite.
You're building a to-do list app. What kind of data belongs in a database rather than just in application variables?
Anything that must survive after the app closes and be found later: the tasks, their completed status, due dates. A database keeps data between runs and lets you query it ('show me all incomplete tasks'). An in-memory variable can't.
A teammate says a small app can just keep all its data in an in-memory array instead of a database. What breaks first as that app grows?
The data vanishes when the process restarts. Two requests changing the array at once can race and corrupt it. And every new question needs new search code. These are exactly the three problems databases solve.
What does it mean that a database usually runs as its own separate piece of software from your application?
Your app connects to the database (often over a network connection, even on the same machine) and sends queries. The database process owns the data files and stores, searches, and protects them, independent of any one app process's lifecycle.
Why does a plain file struggle when two processes try to write to it at the same time, but a database generally doesn't?
A plain file has no coordination, so two writes at once can interleave and corrupt it. A database manages concurrent access internally (locking, isolation), so simultaneous writers don't step on each other.
Is a database the same thing as a table?
No. A table holds one kind of record (like users). A database is the whole system, often a named collection of related tables like users, orders, and products, that you can query together.
What's the practical risk of writing your own ad-hoc 'search' logic over a JSON file instead of reaching for a real database?
You slowly rebuild what a database already does well (filtering, sorting, safe concurrent writes) without years of engineering behind it. The result is usually slower, buggier, and harder to extend.
When would a plain file or an in-memory variable actually be the right choice over a database?
For a tiny, single-user, throwaway script, like a quick calculation or a config file nobody else writes to. A database earns its keep once data must persist, be shared, or be queried flexibly.