Relational Databases
Master the fundamental concepts of relational databases and discover why they're the backbone of modern applications
Learn about relational databases, properties, and why they're crucial for building reliable systems
EXERCISE
1Your Database is the Backbone of Your App
Discover why databases are the foundation that everything else depends on in system architecture.
"Your Database: The Unsung Hero of Your App"
Imagine you’ve built an app people like. The design is on point, the are smooth, and everything’s running fast.
But then—bam, your crashes. Suddenly, everything’s broken, and your app becomes useless.
This is why engineers say: “The database is the weakest link in any system.”
It’s not just a place to store stuff, it’s the foundation of everything your app does.
When the database goes down, it doesn’t just mess with one thing. It brings down:
- Login systems (users can’t sign in)
- Content (no posts, products, or data)
- Analytics (no tracking, no insights)
Pretty much everything stops working.
Think of it like the foundation of a building. It doesn’t matter how beautiful the top floors are—if the foundation cracks,
the whole thing’s in trouble.
Understand your database, and you’ve already solved a huge chunk of the problem. Most app slowdowns, crashes, and errors often start there.****
EXERCISE
2Why Databases look like Excel Spreadsheets
Uncover the fascinating origin story of why databases look exactly like Excel spreadsheets.
Ever wondered why databases are set up like spreadsheets with rows and columns?
Here’s an interesting story: the origins of modern-databases are tied to accounting.
When computers were first invented, the first programs were used for—guess what?
Accounting! Back in the day, bookkeepers were already working with rows and columns on paper
sheets to track finances.
Sound familiar?
Fast forward to today, and we see the same pattern repeating with new technologies. Think about it:
- When the internet emerged, what was one of the first things people built?
- Online banking and payment systems.
- When blockchain came around, what took off first? Cryptocurrency.
Financial systems were the early adopters of new tech because money can’t afford mistakes.
That’s why relational databases store data in rows and columns
—they’re basically the digital version of old-school accounting ledgers. In fact,
accountants from the 1960s would feel right at home looking at a modern database table.
Relational databases didn’t come out of nowhere—they reflect centuries of tried-and-true methods for tracking money.
EXERCISE
3Understanding A.C.I.D Properties
Understand the critical properties that make databases reliable enough to handle your money .
Why Your Money (and Data) Never Gets Lost
Imagine you’re sending $1000 to a friend. The money leaves your account—but before it reaches theirs,
the system crashes.
What happened to your money?
This kind of nightmare is why databases use ACID properties—four rules that make sure digital transactions are safe and reliable:
- Atomicity — It’s all or nothing. Either the whole transaction happens, or none of it does.
- Consistency — The data always stays accurate and valid.
- Isolation — Each transaction happens privately, without messing with others.
- Durability — Once a transaction is done, it’s permanent, even if the system crashes.
These aren’t just fancy words.
They’re the reason you can trust online banking, shopping, and any app that saves your important data.
Without ACID, digital business wouldn’t work. Every purchase, message,
or saved file depends on these rules working perfectly—millions of times every day.
ACID is what makes a real database more reliable than a simple spreadsheet. It keeps your data safe no matter what.
EXERCISE
4Atomicity in Action
Learn how atomicity prevents your data from getting stuck in impossible states.
Let's say you're building Instagram and a user posts a photo. Behind the scenes, your system needs to:
- Save the photo to the posts table
- Update the user's post count in the statistics table
What happens if the system crashes after step 1 but before step 2?
Without atomicity: The photo exists but the count is wrong.
User's profile shows "5 posts" but when you scroll, you find 6 photos. This inconsistency breaks user trust.
With atomicity: Either both operations succeed, or neither happens. It's impossible to have partial updates.
START TRANSACTION;
INSERT INTO posts (user_id, photo_url) VALUES (123, 'selfie.jpg');
UPDATE user_stats SET post_count = post_count + 1 WHERE user_id = 123;
COMMIT; -- Only now do both changes take effect
Atomicity means your database never gets "stuck in the middle" of an operation.
Atomicity like a light switch - it's either completely on or completely off, never halfway.
"Atomicity ensures that your database never tells a half-truth - operations either complete entirely or never happened at all."
EXERCISE
5Consistency in Databases
Discover how consistency rules prevent impossible data scenarios before they happen.
Consistency: Ensuring Reliable and Valid Data, Always
In database systems, consistency means that data remains accurate, valid, and follows defined rules—before and after every operation.
Without consistency, your system can break in serious ways:
- Transferring $200 from an account with only $100
- Creating two users with the same email
- Deleting a user while their associated data (like posts or orders) still remains
These aren't minor bugs—they're signs of a system that can't be trusted.
With consistency: Your database moves from one valid state to another valid state, always.
Databases use constraints to ensure every change respects the structure and logic of your system:
- Check constraints: e.g.
balance >= 0 - Unique constraints: e.g. no duplicate email addresses
- Foreign key constraints: e.g. every order must belong to an existing user
- Cascades: e.g. deleting a user also deletes their posts to avoid orphan records
Every one of these prevents invalid or broken states in your data.
It's like having a smart assistant that stops you from making mistakes:
"Sorry, you can't do that because it would break the rules."
A consistent database always moves from one valid state to another valid state—never halfway, never broken in between.
It protects the system from errors, bad input, and unintended side effects.
That’s why consistency is non-negotiable in systems where data integrity matters—finance, healthcare, authentication, commerce, and more.
Consistency constraints are not just technical rules—they are safeguards that keep your data trustworthy, enforce business logic, and protect your application from silent failure
EXERCISE
6Isolation in Databases
Understand how multiple database operations can happen simultaneously without interfering with each other.
Isolation: Keeping Transactions Independent and Reliable
Think of a busy restaurant kitchen during peak hours. Multiple chefs are preparing different dishes at the same time. For the kitchen to run smoothly, each chef needs to work without being affected by what others are doing.
This is what isolation provides in a database: Each transaction runs in its own space, protected from the incomplete work of others.
What goes wrong without isolation?
Let’s say:
- Transaction A is updating a user’s account balance to $500.
- Before A finishes and commits,
- Transaction B reads the new balance of $500, assuming it's valid.
But if Transaction A fails and rolls back, B has acted on data that never truly existed. That’s called a dirty read—and it's a dangerous bug in critical systems.
With proper isolation:
Each transaction sees only committed data. Unfinished work is hidden.
Changes made inside a transaction become visible to others only after a successful commit.
Example:
-- Transaction A
START TRANSACTION;
UPDATE accounts SET balance = 500 WHERE user_id = 123;
-- Other transactions can’t see this change yet
COMMIT;
-- Transaction B
SELECT balance FROM accounts WHERE user_id = 123;
-- Sees old balance until A commits
Isolation ensures that transactions don’t interfere with each other. It’s how databases maintain order when everything runs at the same time.
EXERCISE
7Durability in Databases
Learn why committed data survives crashes, power outages, and system failures.
You just bought something online and received a confirmation email: "Your order has been processed."
Then the power goes out. Is your order really confirmed, or did it vanish into digital limbo?
This is where durability becomes your hero. When a database says "COMMIT" (transaction complete), it's making a promise: "This data will survive whatever disaster comes next."
Here's what durability guarantees:
- ✅ Power outage? Your data survives.
- ✅ System crash? Your data survives.
- ✅ Software bug? Your data survives.
- ✅ restart? Your data survives.
The only way you lose committed data is if the physical storage device is destroyed (and even then, you should have backups!).
START TRANSACTION;
INSERT INTO orders (user_id, product_id, amount) VALUES (123, 456, 99.99);
COMMIT; -- At this moment, the order is permanently saved
-- Even if the server explodes right now, this order exists!
Durability is why you can trust digital receipts, why your photos don't disappear from cloud storage, and why online banking actually works.
Durability is the database's way of saying 'I've written this in permanent ink' - once committed, your data has officially happened.
EXERCISE
8Mastering Databases Through Practice
Get hands-on with practical exercises to truly understand how relational databases work.
You’ve learned the core principles—Atomicity, Consistency, Isolation, and Durability (ACID).
But knowing them in theory isn’t enough.
You don’t learn databases by reading. You learn by doing. Just like swimming—you only get it once you jump in.
Here’s your step-by-step roadmap to turn theory into real understanding:
Phase 1: Set Up Your Environment
- Install MySQL or PostgreSQL
- Create a simple project (e.g. a social media app)
- Define tables:
users,posts,profiles,followers - Design relationships: one-to-many, many-to-many
Phase 2: Add Real-World Constraints
- Set foreign key relationships (e.g. every post belongs to a user)
- Add check constraints (e.g. age must be positive)
- Use unique constraints (e.g. emails must be unique)
- Set cascade deletes (e.g. deleting a user also deletes their posts)
Phase 3: Break Things on Purpose
- Start a transaction, insert partial data, and crash the database
- Restart and observe: what survived? What rolled back?
- Try inserting invalid data—watch how the DB enforces rules
- Manually violate constraints and learn from the errors
Phase 4: Explore Isolation in Action
- Open two database sessions
- Run parallel transactions
- Test how isolation levels (Read Committed, Repeatable Read, Serializable) affect visibility
- See how dirty reads, phantom reads, and other anomalies appear—or don’t
Pro Tip: You only truly understand databases when you see how they behave under pressure. That’s when ACID shows its real value.
Final Tip:
Treat this like a lab. Don’t be afraid to break your database—this is where the real learning happens.
