This episode compares relational and NoSQL databases in the context of a Node.js application: SQL characteristics with ACID transactions, the flexible NoSQL document model, and considerations for choosing based on data shape and application access patterns.

Real applications almost always store data, and Node.js can talk to nearly any database. The first question to answer before writing code: which database is right for this problem? The answer is rarely single — many applications use more than one type of database.
Episode 13 builds a framework for choosing: the characteristics of relational databases based on SQL with ACID transactions, the characteristics of NoSQL databases with a flexible document model, and practical considerations when both are used from a Node.js application. We're not writing connections yet — that's the job of episode 14.
Relational databases store data in tables with rows and columns, connected to each other through foreign keys. PostgreSQL, MySQL, and SQLite are the most common examples. Their main strength is integrity: the structure is defined first, and the database enforces its rules.
psql -U postgres -d app_db -c "CREATE TABLE pengguna (id SERIAL PRIMARY KEY, email TEXT UNIQUE NOT NULL, nama TEXT NOT NULL);"The psql command above creates a pengguna table with the columns id, email, and nama — the UNIQUE NOT NULL constraints ensure there are no duplicate or empty emails. This is the relational hallmark: data can't get in if it violates the schema.
The main strength of relational databases is transactions with ACID properties:
Consider a money transfer: the deduction in one account and the addition in another must happen together. This property keeps relational databases the primary choice for financial systems, orders, and data that must be consistent.
NoSQL databases come in several forms: document (MongoDB), key-value (Redis), wide-column (Cassandra), and graph (Neo4j). The one most often used with Node.js is the document database because it stores JSON naturally:
const pengguna = {
nama: "Arman",
email: "arman@contoh.com",
alamat: { kota: "Bandung", negara: "Indonesia" },
hobi: ["coding", "membaca"],
};Notice the difference from a table: documents can have different structures, including nested fields like alamat and arrays like hobi. Because Node.js speaks JSON, data can be stored and read with almost no conversion — this is why MongoDB has long been popular in the Node.js ecosystem.
NoSQL suits data whose schema changes rapidly, whose shape is irregular, or whose write volume and speed are very high. Examples: event logs, user profiles with dynamic attributes, product catalogs with varying specifications, and real-time data.
A database decision doesn't come from trends, but from needs. Ask three things:
Honest answers to these three questions almost always point to the right choice. It's very common to see Node.js applications using PostgreSQL as the source of truth and Redis as a cache — both for different tasks.
The boundary between relational and NoSQL is increasingly blurred. PostgreSQL now supports the jsonb type for semi-structured data, while MongoDB supports multi-document transactions and secondary indexes. The best choice is often a combination — what matters is that you understand the basic strengths of each.
Drivers and ORMs make the difference between the two barely noticeable when writing code. SQL queries are sent through drivers like pg, while MongoDB is used through the official mongodb client — both are called from the same JavaScript language:
import pg from "pg";
const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });
const hasil = await pool.query("SELECT * FROM pengguna WHERE id = $1", [1]);
console.log(hasil.rows[0]);pool.query("SELECT * FROM pengguna WHERE id = $1", [1]) sends a parameterized query to PostgreSQL. Notice the $1 placeholder, which prevents injection — a pattern we'll maintain in episodes 14 and 20.
What matters in this episode isn't the driver syntax, but the architectural decision behind it: choosing relational or NoSQL determines the schema shape, query approach, and scaling strategy. This decision should be made before writing much code, because switching databases mid-way is very expensive.
In episode 14 we'll take PostgreSQL as an example and connect it to a Node.js application. The patterns used — connection strings, pooling, and queries — apply to almost all drivers.
Here's what to take away:
jsonb and MongoDB with transactions blur the boundary.In the next episode, episode 14, we'll discuss database connections with drivers or ORMs — using the pg driver with a connection pool, comparing it with the Prisma ORM, managing connection strings via the environment, and running migrations. You'll connect Node.js to a real database.