Day 30 of #100DaysOfCode — Introduction to Database

Published: (March 3, 2026 at 10:34 PM EST)
6 min read
Source: Dev.to

Source: Dev.to

100 Days of Code – Why Databases Matter

Over the past few days of my 100 Days of Code challenge I have:

  • Built front‑end interfaces with React
  • Styled UI components
  • Transitioned to back‑end development with Node.js and Express.js

Connecting the front‑end to the back‑end taught me how APIs send and receive requests and data. The next logical piece was a reliable way to store, retrieve, and manage that data – enter databases.


What Is a Database?

A database is an organized place to store data so it can be easily saved, found, and updated.
Think of it as a super‑powered spreadsheet that can:

  • Handle millions of rows
  • Serve multiple users simultaneously
  • Model complex relationships between data

Imagine Instagram without a database – every photo, like, and comment would disappear the moment you closed the app.

Why Applications Need Databases

ReasonWhat It Means
Remember thingsUser accounts, orders, messages
Share dataAll users see the same information
Search efficientlyFind one user out of 100 million instantly
Stay reliableData survives crashes, restarts, and updates

Without a database an app has no memory – it’s like a person with amnesia who forgets everything after sleeping.


Types of Databases

CategoryData ModelExample(s)Best For
RelationalTables with rows & columns (SQL)PostgreSQL, MySQL, SQLiteStructured data, financial systems, e‑commerce
DocumentJSON‑like documents (schema‑less)MongoDB, FirestoreContent, catalogs, user profiles
Key‑ValueSimple key → value pairsRedis, DynamoDBCaching, sessions, leaderboards
GraphNodes & edges (relationships)Neo4j, Amazon NeptuneSocial networks, recommendation engines, fraud detection
Wide‑ColumnColumns stored together (instead of rows)Cassandra, HBaseIoT data, time‑series, massive analytics
SearchFull‑text indexed documentsElasticsearch, SolrSearch bars, log analysis
Time‑SeriesTimestamp‑oriented recordsInfluxDB, TimescaleDBMetrics, stock prices, sensor data

Quick Code Snippets

SQL (Relational)

SELECT * FROM users WHERE age > 25;

JSON (Document)

{
  "name": "Ali",
  "age": 25,
  "hobbies": ["coding", "chess"]
}

When to Use Which Database?

SituationTypical Choice
Structured data with relationshipsRelational (PostgreSQL)
Flexible / nested dataDocument (MongoDB)
Need blazing speed / cachingKey‑Value (Redis)
Social graph / recommendationsGraph (Neo4j)
Logs, metrics, monitoringTime‑Series (InfluxDB)
Search functionalityElasticsearch

Most real‑world apps combine 2–3 types – e.g., PostgreSQL as the primary store, Redis for caching, and Elasticsearch for search.


Relational Concepts – Relationships

A relation connects two tables through a common field (usually a primary/foreign key).

TypeDiagramDescription
One‑to‑One (1:1)User (1) ──── (1) UserProfileEach user has exactly one profile, and each profile belongs to exactly one user.
One‑to‑Many (1:N)Customer (1) ──── (N) OrdersOne customer can place many orders; each order belongs to one customer.
Many‑to‑Many (M:N)Students (N) ──── [Enrollments] ──── (N) CoursesA junction (link) table stores the pairs of student‑course relationships.

SQL JOINs – Combining Data

Join TypeWhat It ReturnsTypical Use
INNER JOINOnly rows where the join condition matches in both tables.Most common – fetch related records.
LEFT (OUTER) JOINAll rows from the left table plus matching rows from the right; non‑matches get NULL.Keep all “primary” records even if they have no related data.
RIGHT (OUTER) JOINAll rows from the right table plus matching rows from the left; non‑matches get NULL.Mirror of LEFT JOIN.
FULL OUTER JOINAll rows from both tables; NULL where there’s no match.When you need a complete picture of both sides.
CROSS JOINCartesian product – every row of A paired with every row of B.Rare; useful for generating combinations.
SELF JOINA table joined to itself (usually with an alias).Hierarchical data (e.g., employees → managers).

Example Tables

Customers
idname
1Alice
2Bob
3Carol
Orders
idcustomer_id
11
21
399

Sample Queries

-- INNER JOIN (only matching rows)
SELECT *
FROM Customers
INNER JOIN Orders ON Customers.id = Orders.customer_id;
-- Returns Alice & Bob (Carol has no orders, order #3 has no matching customer)

-- LEFT JOIN (all customers, orders if any)
SELECT *
FROM Customers
LEFT JOIN Orders ON Customers.id = Orders.customer_id;
-- Returns Alice, Bob, and Carol (Carol’s order columns are NULL)

-- RIGHT JOIN (all orders, customers if any)
SELECT *
FROM Customers
RIGHT JOIN Orders ON Customers.id = Orders.customer_id;
-- Returns Alice, Bob’s orders, and the orphan order #3 (customer columns NULL)

-- FULL OUTER JOIN (everything)
SELECT *
FROM Customers
FULL OUTER JOIN Orders ON Customers.id = Orders.customer_id;
-- Returns Alice, Bob, Carol, and the orphan order #3

-- CROSS JOIN (Cartesian product)
SELECT *
FROM Customers
CROSS JOIN Orders;
-- 3 customers × 3 orders = 9 rows (use with caution)

-- SELF JOIN (employees & managers example)
SELECT e.name AS employee, m.name AS manager
FROM Employees e
JOIN Employees m ON e.manager_id = m.id;

Visual Summary of Joins

A ●───● B   → INNER JOIN   (intersection)
A ●───○ B   → LEFT JOIN    (all of A)
A ○───● B   → RIGHT JOIN   (all of B)
A ○───○ B   → FULL JOIN    (everything)

The INNER and LEFT joins are the ones you’ll use most often.


TL;DR

  • Databases store data reliably and make it searchable.
  • Different database types (relational, document, key‑value, graph, wide‑column, search, time‑series) solve different data problems.
  • Relationships (1:1, 1:N, M:N) link tables meaningfully.
  • SQL JOINs (INNER, LEFT, RIGHT, FULL, CROSS, SELF) let you combine related data efficiently.

These concepts form the backbone of modern software, enabling applications to handle complex datasets, retrieve information quickly, and maintain reliable connections among data across the system.

Thanks for reading. Feel free to reach out with questions or comments!

Feel free to share your thoughts!

0 views
Back to Blog

Related posts

Read more »

Stop Building API Dashboards From Scratch

Every API developer has been there. You ship an API, someone starts using it, and the questions begin: - “How many requests are we getting?” - “Who’s our heavie...

Runs vs. Threads: When to Use Which

markdown !Cover image for Runs vs. Threads: When to Use Whichhttps://media2.dev.to/dynamic/image/width=1000,height=420,fit=cover,gravity=auto,format=auto/https%...