Step 6 of 23
filing cabinet analogy, relational vs NoSQL, choosing the right type
Database คือตู้เอกสารดิจิทัล — ทำไมต้องมี แบบไหนเหมาะกับอะไร
A database is a structured digital filing cabinet. It stores information so you can find it, update it, and analyze it later.
Think of a physical filing cabinet:
| Database Concept | Filing Cabinet Analogy |
|---|---|
| Table | A folder in the drawer |
| Row | One document inside the folder |
| Column | A specific field on the document (name, date, amount) |
A "Customers" table has one row per customer. Each row has columns for name, email, sign-up date, and last purchase. A "Orders" table has one row per order. Each row has columns for order ID, customer ID, amount, and status.
When your app shows "Welcome back, Sarah" or "Your order #4521 has shipped," it queried the database to find that information.
Like a filing cabinet with strict rules: every document must have the same fields, in the same order, with the same format. Dates must be dates. Amounts must be numbers. Everything cross-referenced and consistent.
Examples: PostgreSQL, MySQL, SQL Server.
Best for: Financial transactions, inventory management, any data where accuracy and consistency are non-negotiable.
Trade-off: Rigid. Adding new fields or changing the structure requires planning and coordination.
Like a box where you toss documents of different shapes. One document might have five fields, the next might have twelve. No strict rules about format.
Diagram: Comparison of relational (SQL) databases with strict table structure versus NoSQL databases with flexible document storage.
Loading diagram...
Examples: MongoDB, DynamoDB, Cassandra.
Best for: Rapidly changing data, content management, logging, applications where the data structure evolves frequently.
Trade-off: Less consistency guarantees. Harder to run complex queries across multiple dimensions.
| Question | Relational | NoSQL |
|---|---|---|
| Does the data structure change often? | No | Yes |
| Do you need strict accuracy (financial, legal)? | Yes | Possibly not |
| Do you need complex queries and reports? | Yes | Limited |
| Is speed of iteration more important than consistency? | No | Yes |
Most organizations use both. Financial records go in a relational database. Session logs and feature flags go in NoSQL.
The type of database a system uses affects:
When a vendor says "our database handles millions of records," that tells you nothing useful. The right question is: "What type of database is it, and is that type appropriate for how we will use the data?"