What a Database Is and Why You Need One
Almost any application stores something for the long term: users, orders, messages. The first idea is to keep them in a familiar Python list. Let's see where that idea breaks down.
Why not keep the data in a Python list
Python 3.13users = [ {"id": 1, "name": "Anna", "email": "anna@example.com"}, {"id": 2, "name": "Peter", "email": "petr@example.com"}, # ... imagine a million users here ] def find_user_by_email(email): for user in users: # scanning the whole list if user["email"] == email: return user return None
With a thousand users everything works. Then the problems begin:
- Slow search — "find by email" walks through the records one by one, and at a million that's a noticeable delay.
- Everything in RAM — the data must fit into memory entirely.
- Data lives until restart — the program exits, and the list is gone.
- Concurrent access — two people change the data at the same moment, and a list isn't ready for that.
What a database is
These are exactly the problems a database solves: fast search by the field you need, storage on disk between runs, and concurrent access without confusion.
A simple analogy: a database is a smart warehouse. Every "shelf" has its own address, and the "warehouse robot" (the DBMS) quickly finds and hands over whatever is needed.
The main types of databases
There are many kinds of databases, but in practice three keep coming up:
The most common DBMSs
Relational databases are what you'll encounter most: PostgreSQL and MySQL on servers, SQLite — inside phones, browsers and Python itself. Of the rest, Redis (key-value: caches and sessions) and MongoDB (documents) come up regularly.
The next three chapters are about relational databases, so from here on we talk only about them.
Understanding check
Why do applications store their users in a database rather than a plain list in memory?
In the next article we start practicing with SQLite — a database that's ideal for learning and already built into Python: we'll create our first DB and work with real data.
