Database Tutorial #13: Redis Setup and Data Types

Redis is an in-memory database. It is fast — reads and writes take microseconds. It is used for caching, sessions, rate limiting, pub/sub, queues, and leaderboards. Redis 8.0 (released May 2025) includes JSON, vector search, probabilistic data structures, and time series natively — no extensions needed. Setup with Docker docker run -d \ --name redis \ -p 6379:6379 \ redis:8 \ redis-server --save 60 1 --loglevel warning Connect with redis-cli: redis-cli # or with Docker: docker exec -it redis redis-cli Strings The most basic type. Strings can hold text, numbers, or binary data (up to 512 MB). ...

August 7, 2026 · 4 min

Database Tutorial #12: MongoDB Indexing and Performance

MongoDB reads every document in a collection if there is no index — a collection scan. At 10 million documents, that is slow. Indexes fix this. Single-Field Index // Create an index on the email field db.users.createIndex({ email: 1 }) // 1 = ascending, -1 = descending // The query now uses the index db.users.find({ email: "alex@example.com" }) // Unique index — enforces uniqueness db.users.createIndex({ email: 1 }, { unique: true }) Compound Index Index multiple fields together when you filter or sort on more than one: ...

August 6, 2026 · 4 min

Database Tutorial #11: MongoDB Aggregation Pipeline

find() gets documents. The aggregation pipeline transforms them. It is MongoDB’s answer to SQL GROUP BY, JOIN, and window functions. How the Pipeline Works Documents flow through a sequence of stages. Each stage takes the output of the previous one as input. db.orders.aggregate([ { $match: { status: "delivered" } }, // Stage 1: filter { $group: { _id: "$user_id", total: { $sum: "$amount" } } }, // Stage 2: group { $sort: { total: -1 } }, // Stage 3: sort { $limit: 10 } // Stage 4: limit ]) $match — Filter Documents // Equivalent to WHERE in SQL db.orders.aggregate([ { $match: { status: "delivered", createdAt: { $gte: ISODate("2026-01-01"), $lt: ISODate("2027-01-01") } } } ]) Put $match as early as possible. It reduces the number of documents processed by later stages. ...

August 6, 2026 · 4 min

Database Tutorial #10: MongoDB Data Modeling

MongoDB’s flexible schema is a strength and a trap. You can store anything, but bad data modeling causes slow queries and bloated documents. Good modeling matches your access patterns. The Key Question: Embed or Reference? In SQL, you normalize data into separate tables and join them. In MongoDB, you have a choice: embed related data in the same document, or store it separately and reference it. Embed when: Data is always accessed together Child data belongs to only one parent The embedded data is bounded in size Reference when: ...

August 6, 2026 · 4 min

Database Tutorial #9: MongoDB Setup and CRUD

MongoDB stores data as documents — JSON-like objects with flexible structure. No fixed schema. No joins required for embedded data. This tutorial gets you up and running with MongoDB 8.0. Setup with Docker docker run -d \ --name mongodb \ -p 27017:27017 \ -e MONGO_INITDB_ROOT_USERNAME=admin \ -e MONGO_INITDB_ROOT_PASSWORD=password \ mongodb/mongodb-community-server:8.0-ubi8 Connect with mongosh: mongosh "mongodb://admin:password@localhost:27017" mongosh Basics // Show databases show dbs // Switch to (or create) a database use myapp // Show collections show collections // Create a collection explicitly (optional — auto-created on first insert) db.createCollection("users") Documents and Collections In MongoDB: ...

August 5, 2026 · 4 min

Database Tutorial #1: SQL vs NoSQL — When to Use What

You are building a new app. You need to store data. Now comes the question: should I use SQL or NoSQL? This is one of the most common decisions in backend development. The wrong choice can hurt performance, scalability, and developer experience. The right choice makes everything simpler. This article explains both options clearly so you can make the right call. What Is SQL? SQL databases are relational databases. Data is stored in tables. Tables have rows and columns. Every row has the same structure, defined by the table schema. ...

August 3, 2026 · 6 min