Data Models: The Blueprint for Your App's Brain!


Hey there, future software pros! Welcome back to simplifyingcode.com.
Last time, we chatted about the "Three Musketeers" of great software: Reliability, Scalability, and Maintainability. They're all about making sure our applications work well, handle growth, and are easy to fix.
But how do these amazing applications actually store all the information they deal with? Think of it like building a house. You need a good blueprint for the house itself (that’s Chapter 1 stuff!). But you also need a plan for how you're going to organise all your stuff inside – where the kitchen goes, where the bedrooms are, how the plumbing connects.
That's exactly what Data Models are in software! They're the blueprints for how your data is structured, stored, and how you'll ask questions to get it back. Chapter 2 of "Designing Data-Intensive Applications" breaks down these fundamental ways of organising data.
Let's look at the two big players you'll hear about constantly:
1. The Classic: Relational Databases (aka SQL Databases)
Imagine an old-school filing cabinet. Inside, you have folders, and each folder has a very specific, pre-printed form. For example, a "Customers" folder might have forms where every customer's name, address, and phone number must be filled out in specific boxes.
That's essentially how Relational Databases work. They organise data into tables, which are like those folders. Each table has columns (the pre-printed boxes, like "Name" or "Address") and rows (each customer's filled-out form).
Key Idea: They are very structured. You decide the exact columns (the "schema") before you put any data in. It's like having a strict contract: "All customer records must have a name and an address." This is called schema-on-write – you define the schema before writing data.
Good for: Data that has clear, consistent relationships (like a customer having many orders). You use SQL (Structured Query Language) to talk to them, which is like asking, "Show me all customers who live in London."
2. The Flexible Friend: Document Databases (aka NoSQL Databases)
Now, imagine instead of strict forms, you have a pile of folders, and each folder just contains a "document" about a customer. One document might have a name and address. Another might have a name, address, and their favourite ice cream flavour. A third might just have a name.
This is the idea behind Document Databases. They store data as self-contained "documents," often in a format called JSON (which looks a bit like nested lists and dictionaries in programming).
Key Idea: They are much more flexible. You don't have to define a super strict structure upfront. You can just throw in a document, and if the next one has slightly different fields, that's okay! This is called schema-on-read – you figure out the schema when you read the data.
Good for: Data that changes often, or where each item might have slightly different characteristics (like user profiles in a social media app). They also often handle lots of small, self-contained pieces of data very quickly.
So, Relational vs. Document: Which One Wins?
Neither! Just like you wouldn't use a hammer for every single job, you pick the right data model for the job you're doing.
Relational (SQL): Great when your data is highly interconnected, and you need to ensure strict consistency (like bank transactions). Think of things where you need to know that every piece of data fits a precise mould.
Document (NoSQL): Excellent when your data is less structured, or when you want to keep related information together in one place (like all the details for a single product on an e-commerce site). They often shine in situations where you're rapidly building features and need flexibility.
A Quick Word on Graph Databases
There's another cool kid on the block: Graph Databases. Imagine not just having lists of things, but also clearly defining the connections between them. Like in a social network: "Alice is friends with Bob," "Bob works at Company X." These are brilliant for data where relationships are just as important as the data itself.
Talking to Your Data: Query Languages
Finally, no matter how you store your data, you need a way to ask it questions!
SQL (for Relational): You tell the database what you want (e.g., "GET all users WHERE age > 30"). The database figures out how to get it. This is declarative.
Other languages (for NoSQL, etc.): Often, you'll use code directly (like in Python or JavaScript) to fetch and filter data, or specific query languages for that database. This can be more imperative – you specify more of the "how."
The Takeaway
Choosing the right data model is one of the most fundamental decisions you'll make when designing an application. It impacts everything from how you write your code to how your application performs. There's no single "best" option, just the right tool for the right job!
What kind of data do you think would be best stored in a relational database versus a document database? Share your thoughts in the comments!
Happy coding!
Subscribe to my newsletter
Read articles from Michael Asaad directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Michael Asaad
Michael Asaad
I’m Michael Asaad A self taught software developer of over 7 years and founder of #SimplifyingCode. I started my career in pharmacy but soon realised my passion was software development. If you are like me and are starting without any coding knowledge, it can be daunting. Over time, and with a lot of trial and error, you can discover how to make your transition into software development a success! SimplifyingCode aims to break these barriers to entry and make software development accessible for all. Head over to the blog section and start your coding journey today! Oh, and don't forget your free copy of "How to start your career as a software developer without a Computer Science degree".