A database is a system used to store, manage, and retrieve data. Articles on a website, product information, and forms submitted by users are ultimately stored in a database.
Core concepts
Regardless of the type of database, they all address the same set of issues: how data is organized, how to ensure accuracy, and how to quickly retrieve the needed portion.
- Data model: describes how data is organized. Common ones include table-centric, document-based, represented by nodes and relationships, and stored as key-value pairs.
- Management system: software for operating a database, responsible for defining structures, reading and writing data, and access control.
- Integrity constraints: ensure that data conforms to rules, such as primary keys not duplicating, field formats being correct, and associations between tables not containing dangling references.
- Transaction: treats a group of operations as a whole, either all completed or all discarded, to avoid data being in an intermediate state.
Two major categories of databases
Relational
Data is placed in tables, with rows as records and columns as fields, and complex information is organized through associations between tables. It is suitable for data with a clear structure and many relationships, such as orders, users, and products, which require strict consistency, and is also the most common choice in enterprise systems.
Non-relational
It does not necessarily use a table structure and is more flexible in form. It is suitable for scenarios where data forms are not fixed and large-scale data needs to be stored in a distributed manner, such as logs, caches, and content fragments. It does not replace relational databases, but rather serves as a supplement in specific scenarios.
Several considerations in design and management
- Reduce redundancy: split repeated data into related tables to lower the risk of inconsistency.
- Create indexes: creating indexes on fields often used in queries can significantly improve retrieval speed, but too many indexes can also slow down writes.
- Backup and recovery: back up regularly and confirm that backups are usable—an unverified backup does not count as a backup.
- Access control: assign read and write permissions by role, and avoid using the highest-privilege account for all operations.
What to look at when selecting a database
Mainly look at the structure and scale of the data, read/write pressure, whether strict consistency is required, and whether the team has the corresponding maintenance capabilities going forward. When selecting a database, there is no need to pursue the latest; stability, long-term support, and compatibility with existing systems are often more important than technical advancement.
