What is a Database?
Imagine you're building an online shopping website.
You need to store information such as:
- User accounts
- Products
- Orders
- Reviews
- Shopping carts
- Payments
Where should all this information be stored?
You cannot simply keep it inside your application's code because the data changes constantly. New users sign up, products are added, orders are placed, and prices change every day.
This is where databases come in.
A database is a system used to store, organize, retrieve, update, and manage data efficiently.
Almost every modern application uses one or more databases.
Whether you're using a website, mobile app, desktop application, or even a smart TV application, there is usually a database working behind the scenes.
Why Do We Need a Database?
Imagine a social media application with millions of users.
Every second, people are:
- Creating accounts
- Posting photos
- Sending messages
- Writing comments
- Following other users
- Liking posts
All of this information must be stored safely and retrieved whenever needed.
A database is designed specifically for handling these kinds of tasks.
Without databases, modern applications would not be possible.
What Kind of Data Can a Database Store?
A database can store almost any kind of information.
For example:
- User information
- Passwords (stored securely)
- Product details
- Customer information
- Orders
- Transactions
- Blog posts
- Comments
- Videos
- Images
- Chat messages
- Medical records
- Employee details
In simple words, if an application needs to remember something, it usually stores it in a database.
How Does a Database Work with the Backend?
Users do not communicate directly with a database.
Instead, the backend acts as a bridge.
The process usually works like this:
- A user performs an action.
- The frontend sends a request to the backend.
- The backend processes the request.
- The backend reads or updates the database.
- The database returns the requested data.
- The backend sends the response to the frontend.
- The frontend displays the result to the user.
This approach improves both security and organization because users never access the database directly.
Types of Databases
There are many kinds of databases, but the three most common categories are:
- SQL Databases
- NoSQL Databases
- Graph Databases
Let's understand each one.
SQL Databases
SQL databases are also known as relational databases.
They organize data into tables.
Each table stores one type of information.
For example, an online shopping application might have separate tables for:
- Users
- Products
- Orders
- Categories
Each table consists of rows and columns.
A row represents one record.
A column represents one piece of information about that record.
For example, a Users table might contain:
- User ID
- Name
- Phone Number
- Password
Every user would occupy one row in the table.
One of the biggest advantages of SQL databases is that relationships can be created between tables.
For example:
- An order belongs to a user.
- A review belongs to a product.
- A product belongs to a category.
These relationships make SQL databases very powerful for applications where data is highly structured.
Some popular SQL databases include:
- MySQL
- PostgreSQL
- Microsoft SQL Server
- Oracle Database
- SQLite
SQL databases are commonly used for:
- Banking systems
- E-commerce websites
- Enterprise software
- Hospital management systems
- School management systems
- Accounting applications
What is NoSQL?
As applications became larger and started handling huge amounts of different kinds of data, developers realized that storing everything in tables wasn't always the best solution.
This led to the development of NoSQL databases.
Unlike SQL databases, NoSQL databases do not always organize data into tables.
Instead, they can store data in several different formats depending on the application's needs.
Some common NoSQL database models include:
- Document databases
- Key-value databases
- Column-family databases
The most popular type is the document database.
In document databases, information is usually stored as documents.
A document can contain many fields and can easily store nested information without requiring multiple related tables.
This makes NoSQL databases flexible and easy to scale for many modern applications.
Some popular NoSQL databases include:
- MongoDB
- Cassandra
- Redis
- CouchDB
- Amazon DynamoDB
NoSQL databases are commonly used for:
- Social media platforms
- Content management systems
- Real-time applications
- Chat applications
- IoT systems
- Large-scale web applications
SQL vs NoSQL
Both SQL and NoSQL databases are excellent choices.
The right choice depends on the application's requirements.
SQL databases are generally preferred when:
- Data has a fixed structure.
- Relationships between data are important.
- Strong consistency is required.
- Complex queries are common.
NoSQL databases are often preferred when:
- Data structure changes frequently.
- Applications need to scale quickly.
- Large amounts of unstructured or semi-structured data are stored.
- High-speed data processing is important.
Neither is universally better.
Modern companies often use both SQL and NoSQL databases together, choosing the right tool for each specific task.
What is a Graph Database?
Some applications focus less on storing records and more on understanding relationships between data.
For these applications, graph databases are often the best choice.
Instead of storing information mainly in tables or documents, graph databases store:
- Nodes
- Relationships (also called edges)
A node represents an object.
A relationship connects two nodes.
For example, in a social networking application:
- Alice is a node.
- Bob is another node.
- "Alice follows Bob" is a relationship.
Similarly, in a professional networking platform:
- People are connected to companies.
- Companies are connected to jobs.
- Jobs are connected to required skills.
- People are connected to other people.
A graph database makes it very efficient to explore these connections.
Popular graph databases include:
- Neo4j
- Amazon Neptune
- ArangoDB
- TigerGraph
Graph databases are commonly used for:
- Social networks
- Recommendation systems
- Fraud detection
- Knowledge graphs
- Network analysis
- Route planning
Can One Application Use Multiple Databases?
Yes.
Large applications often use multiple databases at the same time.
For example, an e-commerce application might use:
- A SQL database to store orders and payments.
- A NoSQL database to manage product catalogs.
- A Graph database to recommend similar products based on customer behavior.
- A Redis database to cache frequently accessed information and improve performance.
Each database is chosen because it is well suited for a particular type of problem.
This approach is called polyglot persistence, where different databases work together within the same application.
How Do Developers Access a Database?
Backend applications communicate with databases.
Developers typically perform four basic operations:
- Create new data.
- Read existing data.
- Update existing data.
- Delete data.
These four operations are commonly known as CRUD operations.
Almost every backend application performs CRUD operations many times every day.
Summary
A database is a system used to store, organize, manage, and retrieve data efficiently.
Instead of saving information directly inside an application, data is stored in a database and accessed through the backend.
The three major types of databases are:
SQL Databases
Store structured data in tables with relationships between records. Examples include MySQL, PostgreSQL, Microsoft SQL Server, Oracle Database, and SQLite.
NoSQL Databases
Store flexible and scalable data using documents, key-value pairs, columns, or other models. Examples include MongoDB, Cassandra, Redis, CouchDB, and DynamoDB.
Graph Databases
Store data as nodes and relationships, making them ideal for applications that need to analyze connections between data. Examples include Neo4j, Amazon Neptune, ArangoDB, and TigerGraph.
Each type of database has its own strengths, and modern applications often use multiple databases together to build scalable, reliable, and high-performance systems.
In the next article, we'll learn about APIs and understand how the frontend and backend communicate with each other.
Learn more:
If you'd like to understand how a request travels from your browser to a server over the Internet, check out our Internet Basics series, where these networking concepts are explained in detail.