Pre Topics

42 min readEdit on GitHub

Pre-Topics

Basics of Data

Understanding data is fundamental to any field involving computation, analytics, or decision-making. Data forms the foundation of all information systems, and it plays a critical role in helping organizations and individuals make informed decisions. Let’s explore what data is, how it differs from information, and the various types of data that exist in the digital world.

What is Data?

Data refers to raw, unprocessed facts, figures, symbols, or observations collected from various sources. It represents qualitative or quantitative attributes of a variable or set of variables. Data by itself may not have any context or meaning — it is essentially the input that requires processing to become meaningful.
In simpler terms, data is a collection of facts — numbers, text, images, audio, video, or symbols — that can be recorded and stored for analysis or reference. For example:
  • A list of student marks in a class: 75, 82, 67, 90, 88
  • Temperature readings over a week: 22°C, 24°C, 23°C, 25°C
  • Customer feedback texts: “Good service,” “Average,” “Poor experience.”
These are all examples of data, but until we process and interpret them, they do not tell us much about trends, insights, or relationships.
Key Characteristics of Data:
  • Raw form: Data is not yet analyzed or interpreted.
  • Context-independent: Data has no meaning until context is added.
  • Collected from multiple sources: Data can come from sensors, surveys, transactions, logs, or user activities.
  • Various formats: Data can be numerical, textual, graphical, or multimedia.
Example:
Suppose you have a file containing customer purchase amounts:
500, 700, 300, 1000, 600.
By itself, this data doesn’t provide much insight. Once processed, it could show that the average purchase amount is 620, which is meaningful information — leading us to the next concept.

Data vs Information

While the terms data and information are often used interchangeably, they have distinct meanings in computing and data management.
AspectDataInformation
DefinitionRaw facts and figures without context.Processed, organized, and meaningful data.
NatureUnorganized and unprocessed.Structured, analyzed, and contextualized.
PurposeCollected for reference or processing.Used for decision-making or understanding.
ExampleA list of daily sales: 100, 200, 150, 300.The statement: “Average daily sales = 187.5.”
In essence:
  • Data is the input, and
  • Information is the output after processing that data.
Analogy:
Think of data as raw ingredients (like flour, eggs, and sugar), and information as the finished cake made from those ingredients. Without processing, the ingredients alone cannot provide the value that the final product delivers.
Transformation Process:
  1. Data Collection: Gathering raw facts from various sources.
  2. Data Processing: Cleaning, filtering, and organizing data.
  3. Analysis: Identifying patterns, relationships, or statistics.
  4. Interpretation: Drawing conclusions and presenting insights — this is information.

Types of Data

In modern computing and data management, data is generally categorized into three main types based on its structure and how it is stored, processed, and managed: Structured, Unstructured, and Semi-Structured data.

1. Structured Data

Definition:
Structured data refers to data that is organized in a predefined model or format — typically stored in rows and columns like in databases or spreadsheets. This kind of data follows a strict schema, which defines how the data is stored, accessed, and related.
Example:
A typical SQL database table is a perfect example of structured data.
For instance, consider a Customers table:
Customer_IDNameAgeCountryPurchase_Amount
101Alice Brown30USA500
102John Smith25Canada700
103Priya Patel29India600
Characteristics:
  • Organized in a tabular format (rows and columns).
  • Each column represents a specific attribute (e.g., Name, Age).
  • Each row represents an individual record or data instance.
  • Data types are predefined (e.g., integer, string, date).
  • Easy to store, query, and analyze using tools like SQL.
Storage and Management:
Structured data is typically stored in Relational Database Management Systems (RDBMS) such as MySQL, PostgreSQL, Oracle, or SQL Server. Querying and manipulation are done using Structured Query Language (SQL).
Advantages:
  • Easy to enter, store, query, and analyze.
  • High data accuracy and consistency.
  • Efficient indexing and retrieval due to its fixed schema.
Limitations:
  • Lacks flexibility for handling diverse or rapidly changing data formats.
  • Not suitable for multimedia, logs, or text-based data without clear structure.

2. Unstructured Data

Definition:
Unstructured data refers to information that doesn’t follow a specific data model or structure. It doesn’t fit neatly into tables or predefined fields. This type of data is often qualitative and cannot be easily stored in traditional relational databases.
Examples:
  • Text documents, emails, and social media posts.
  • Images, audio files, and videos.
  • Sensor readings, satellite imagery, or chat transcripts.
Example in Context:
Imagine a folder containing customer feedback:
  • “Great product, very fast delivery!”
  • “The quality could be better.”
  • “Excellent packaging and service.”
This is unstructured data because it cannot be directly quantified or represented in rows and columns without further processing such as text mining or natural language processing (NLP).
Characteristics:
  • No fixed format or schema.
  • Complex and often large in size.
  • Difficult to search or analyze without specialized tools.
  • May contain hidden patterns or sentiments that require advanced processing techniques.
Storage and Management:
Unstructured data is usually stored in data lakes, NoSQL databases, or distributed storage systems like Hadoop, MongoDB, or Amazon S3.
Processing Tools:
To analyze unstructured data, organizations use technologies such as:
  • Natural Language Processing (NLP) for text.
  • Computer Vision for images and videos.
  • Speech Recognition for audio data.
Advantages:
  • Captures real-world complexity and human context.
  • Rich source of insights through advanced analytics and AI.
Limitations:
  • Difficult to store, organize, and search.
  • Requires more computational power and advanced tools to process.

3. Semi-Structured Data

Definition:
Semi-structured data lies between structured and unstructured data. It doesn’t have a rigid structure like a relational table but contains some organizational elements (tags, markers, or key-value pairs) that make it easier to analyze than purely unstructured data.
Examples:
  • JSON (JavaScript Object Notation)
  • XML (eXtensible Markup Language)
  • YAML files
  • Email messages (with structured fields like “To,” “From,” “Subject,” but unstructured message bodies)
Example of JSON Data:
hljs json
{
 "employee": {
 "id": 101,
 "name": "Alice Brown",
 "department": "Sales",
 "skills": ["Negotiation", "CRM", "Communication"]
 }
}
This data is not stored in a rigid table, but it has an identifiable hierarchy and structure through key-value pairs.
Characteristics:
  • Partially structured with organizational tags or attributes.
  • Flexible and easy to extend — new fields can be added without altering the entire dataset.
  • Can represent complex relationships like nested data or arrays.
  • Easier to parse than unstructured data but less rigid than structured data.
Storage and Management:
Semi-structured data is typically stored in NoSQL databases like MongoDB, Cassandra, or CouchDB. These systems are designed to handle flexible schemas and allow efficient querying using document-based or key-value storage models.
Advantages:
  • Balances flexibility with structure.
  • Easier to scale and adapt for diverse data sources.
  • Ideal for modern web applications and APIs.
Limitations:
  • Not as standardized as structured data.
  • Requires special parsing tools to analyze.
  • May have inconsistent formatting across different datasets.

What Are Databases?

In the modern digital era, data is generated, collected, and processed at an unprecedented rate. Every website you visit, every online transaction you make, and every app you use generates and stores data. Managing this vast amount of data efficiently, securely, and reliably is only possible through databases. Understanding databases is fundamental to understanding how modern software systems function.

What is a Database and Why Do We Need Them?

Definition:
A database is an organized collection of structured information, or data, typically stored electronically in a computer system. The data in a database is usually managed by a Database Management System (DBMS), which provides tools for defining, creating, querying, updating, and administrating databases.
In simpler terms, a database is like a digital filing cabinet that stores and manages data efficiently, allowing multiple users and applications to access and manipulate it simultaneously.
Formal Definition (by C.J. Date):
A database is a shared collection of logically related data (and a description of this data) designed to meet the information needs of an organization.

Why Do We Need Databases?

Before databases, data was stored in traditional file systems, which were simple but inefficient for complex data management. As systems evolved, the need for more structured, scalable, and consistent data management gave rise to databases.

Key Reasons We Need Databases:

  1. Efficient Data Management
Databases allow efficient storage, retrieval, and manipulation of large volumes of data. They provide indexing, caching, and query optimization, which make operations faster compared to manual file searching.
  1. Data Integrity and Accuracy
Databases enforce rules and constraints (like primary keys, foreign keys, and data types) to maintain accuracy and consistency in data. For example, a database can ensure that no two customers have the same ID or that an order cannot exist without a customer.
  1. Security and Controlled Access
Databases provide authentication, authorization, and encryption features to protect sensitive data. Users can be granted specific permissions — for example, an employee may only view data while an administrator can modify or delete it.
  1. Concurrent Access
Databases allow multiple users to access and work with data simultaneously without conflicts. Transaction control mechanisms like locking and commit/rollback ensure data consistency even when many users are working at once.
  1. Scalability
Databases can handle vast amounts of data and users efficiently. They can scale both vertically (more powerful hardware) and horizontally (adding more servers).
  1. Data Relationships and Complex Queries
Databases can easily represent relationships between data entities (such as customers and orders) and allow complex queries to retrieve related information efficiently.
  1. Data Recovery and Backup
Modern databases offer automatic backup, recovery, and fault-tolerance mechanisms. In case of system failure, data can be restored without losing integrity.
  1. Reduced Data Redundancy
Using normalization and relational structures, databases minimize duplication, ensuring data consistency and efficient storage.
Example Scenario:
Imagine a small business storing customer and order data.
Without a database, they might keep this data in spreadsheets or text files. Over time, files become large, redundant, and inconsistent. Searching or updating customer information becomes slow and error-prone.
With a database, all this data can be stored in related tables (Customers, Orders, Products), enabling easy querying — such as “find all orders placed by a specific customer” — with a single command.

Difference Between File System vs Databases

Before the evolution of databases, traditional file systems were the primary way to store data. While simple, file systems lacked the ability to handle large, complex, and interrelated data efficiently.
Let’s understand the differences between the two:
FeatureFile SystemDatabase System
DefinitionA file system manages data as individual files stored on a disk.A database system manages data through structured storage with relationships, managed by a DBMS.
Data StorageData stored in separate files, often in plain text, CSV, or binary format.Data stored in structured tables or collections, following a schema.
Data RedundancyHigh redundancy (same data stored in multiple places).Low redundancy due to normalization and relational design.
Data IntegrityDifficult to enforce; consistency relies on manual effort.Enforced automatically using constraints and relationships.
Data AccessAccess through programming logic or manual reading.Access via powerful query languages like SQL.
Concurrent AccessLimited — simultaneous edits can corrupt data.Supports multiple concurrent users with transaction control.
SecurityBasic file-level security (read/write permissions).Fine-grained security with user roles, authentication, and encryption.
Backup and RecoveryManual and time-consuming.Automated and reliable backup and recovery systems.
Data RelationshipsHard to represent or maintain relationships between data.Easily supports relationships using keys and joins.
PerformanceSlower for large datasets and complex queries.Optimized for high-speed querying and large data handling.
ExampleText files, spreadsheets, CSV files.MySQL, PostgreSQL, Oracle, MongoDB.
Illustration:
  • File System Example:
You might have three separate text files:
  • customers.txt (list of customers)
  • orders.txt (list of orders)
  • products.txt (list of products)
To find all orders by a specific customer, you’d have to manually cross-reference the data across files — a time-consuming and error-prone process.
  • Database Example:
In a relational database, you can simply execute an SQL query:
hljs sql
SELECT * FROM Orders
WHERE CustomerID = 101;
This instantly retrieves all orders placed by the customer with ID 101.
Conclusion:
Databases provide structure, integrity, scalability, and reliability that file systems cannot offer for complex data management.

What is a DBMS (Database Management System)?

Definition:
A Database Management System (DBMS) is software that manages and controls access to a database. It provides an interface between the database, the users, and application programs to ensure that data is consistently organized and remains easily accessible.
In simple terms, a DBMS is the software layer that enables you to create, read, update, and delete data in a database efficiently while maintaining security, integrity, and consistency.
Example DBMSs:
  • Relational DBMS (RDBMS): MySQL, PostgreSQL, Oracle, Microsoft SQL Server.
  • NoSQL DBMS: MongoDB, Cassandra, Redis, CouchDB.
  • In-memory DBMS: Redis, Memcached.
  • Graph DBMS: Neo4j, ArangoDB.

Functions of a DBMS

  1. Data Storage and Retrieval:
Provides efficient methods to store large datasets and retrieve them quickly using query languages (e.g., SQL).
  1. Data Definition:
Allows users to define data structures, schemas, and relationships using Data Definition Language (DDL).
  1. Data Manipulation:
Enables insertion, deletion, updating, and querying of data using Data Manipulation Language (DML).
  1. Transaction Management:
Ensures that all database transactions follow the ACID properties (Atomicity, Consistency, Isolation, Durability) to maintain reliability and integrity.
  1. Concurrency Control:
Manages simultaneous access by multiple users to ensure that one user’s operations don’t interfere with another’s.
  1. Security Management:
Controls access through user authentication, roles, and permissions to prevent unauthorized data usage.
  1. Backup and Recovery:
Maintains data safety by automatically backing up data and restoring it in case of failure.
  1. Data Integrity Enforcement:
Enforces rules like primary keys, foreign keys, and constraints to ensure data correctness and consistency.
  1. Data Independence:
Separates data storage from application logic so that changes in database structure do not affect the application code.

Advantages of a DBMS

  • Centralized Control: All data is managed from a central system.
  • Data Sharing: Multiple users and applications can share the same data.
  • Data Security: Controlled access prevents unauthorized usage.
  • Reduced Redundancy: Normalization minimizes data duplication.
  • Consistency and Integrity: Constraints and relationships maintain accuracy.
  • Backup and Recovery: Protects data from failures or corruption.
  • Scalability and Performance: Optimized for handling large-scale data efficiently.

Example to Understand DBMS in Action

Suppose you’re building an e-commerce application. You’ll need to manage:
  • Customer details
  • Product inventory
  • Orders and payments
A DBMS like MySQL can manage these entities using related tables such as:
  • Customers (CustomerID, Name, Email)
  • Products (ProductID, Name, Price)
  • Orders (OrderID, CustomerID, ProductID, Quantity)
The DBMS ensures:
  • Only valid customers can place orders.
  • Product quantities update automatically after each order.
  • Administrators can query, update, or analyze data easily.

Relational Databases (SQL)

Relational databases form the foundation of most traditional data storage and management systems. They are built on the concept of organizing data into structured, interrelated tables. The Structured Query Language (SQL) is used to define, manipulate, and retrieve data from these databases. Relational databases are known for their reliability, consistency, and ability to maintain data integrity — which is why they have been dominant in enterprise systems for decades.

Core Concepts

Relational databases are based on a mathematical concept called the relational model, proposed by Edgar F. Codd in 1970. This model represents data as relations (tables), where each table consists of rows (records) and columns (fields). The power of the relational model lies in its ability to maintain relationships among data efficiently while ensuring consistency.
Let’s explore the core components of a relational database.

1. Tables

A table is the primary structure in a relational database. It represents a specific entity (like customers, products, or orders) and stores data in a structured format with rows and columns.
Each table contains:
  • Columns (fields) that define the type of data stored.
  • Rows (records) that hold the actual data entries.
Example:
Consider a simple Customers table:
Customer_IDNameEmailCountry
101Alice Brownalice@example.comUSA
102John Smithjohn@example.comCanada
103Priya Patelpriya@example.comIndia
In this table:
  • The table name is Customers.
  • Each column represents an attribute (Customer_ID, Name, Email, Country).
  • Each row represents a record of one customer.
Key properties of tables:
  • Each table has a unique name.
  • All rows in a table have the same columns (schema).
  • Tables are linked through relationships using keys (explained below).

2. Rows

A row (also called a record or tuple) represents one instance of data within a table.
For example, in the Customers table, the row:
text
101 | Alice Brown | alice@example.com | USA
is a single record that holds all details about one customer.
Each row corresponds to a real-world entity and contains data values for each column defined in the table.

3. Columns

A column (also known as a field or attribute) defines a specific piece of information stored in the table. Each column has:
  • A name (e.g., Customer_ID, Email)
  • A data type (e.g., integer, varchar, date, boolean)
  • Constraints (e.g., NOT NULL, UNIQUE)
For example, in the Customers table:
  • The Customer_ID column may be of type INTEGER and marked as a Primary Key.
  • The Email column might have a UNIQUE constraint to prevent duplicate emails.

Relationships in Relational Databases

The true power of relational databases lies in how tables are related to each other. Relationships enable data stored in different tables to be connected logically, reducing redundancy and maintaining consistency.
There are three main types of relationships:
  • One-to-One (1:1)
  • One-to-Many (1:N)
  • Many-to-Many (M:N)
Let’s understand the two key elements that define these relationships: Primary Keys and Foreign Keys.

Primary Key

A Primary Key is a column (or set of columns) that uniquely identifies each row in a table.
It ensures that no two rows have the same value in the primary key column(s) and that every row has a valid (non-null) identifier.
Example:
In the Customers table, Customer_ID can serve as the Primary Key.
Customer_IDNameEmailCountry
101Alice Brownalice@example.comUSA
102John Smithjohn@example.comCanada
103Priya Patelpriya@example.comIndia
Here:
  • Each Customer_ID is unique.
  • No two customers share the same ID.
  • The ID field cannot be empty (NULL).
Purpose of Primary Key:
  • Ensures each record is unique.
  • Used to establish relationships with other tables.
  • Enables fast searching and indexing.

Foreign Key

A Foreign Key is a column in one table that refers to the Primary Key of another table.
It establishes a relationship between the two tables, ensuring referential integrity — meaning that data in one table must correspond to valid data in another.
Example:
Let’s introduce another table — Orders:
Order_IDOrder_DateCustomer_IDAmount
5012025-10-01101500
5022025-10-02103700
5032025-10-03101300
Here:
  • Customer_ID in the Orders table is a Foreign Key.
  • It references Customer_ID in the Customers table.
This means that each order must be associated with a valid customer.
If someone tries to insert an order with Customer_ID = 999 (which doesn’t exist in the Customers table), the database will reject it — preserving data integrity.
Benefits of Foreign Keys:
  • Maintain referential integrity.
  • Prevent orphan records (data without a valid parent).
  • Enable data linkage between tables.
Relational databases are managed by systems known as RDBMS (Relational Database Management Systems). These systems implement the relational model, providing features for creating, managing, and querying relational data using SQL (Structured Query Language).
Below are some of the most popular RDBMS platforms:

1. MySQL

  • Overview: One of the most popular open-source relational databases, widely used in web applications.
  • Developed by: Oracle Corporation.
  • Features:
  • Supports ACID compliance and transactions.
  • Highly compatible with web frameworks (e.g., PHP, Django).
  • Uses SQL for querying.
  • Scalable and fast for small to medium applications.
  • Use Cases: E-commerce sites, blogs, web apps (e.g., WordPress, YouTube).

2. PostgreSQL

  • Overview: A powerful, open-source object-relational database system.
  • Developed by: PostgreSQL Global Development Group.
  • Features:
  • Fully ACID-compliant.
  • Supports advanced features like JSON data types, indexing, and full-text search.
  • Extensible — developers can create custom functions and data types.
  • Highly reliable and secure.
  • Use Cases: Data analytics, scientific applications, and systems requiring high reliability.

3. Oracle Database

  • Overview: A commercial enterprise-level RDBMS known for scalability, robustness, and performance.
  • Developed by: Oracle Corporation.
  • Features:
  • Supports massive enterprise workloads.
  • Advanced transaction control, clustering, and high availability.
  • Strong security and backup features.
  • Multi-model support (relational, JSON, spatial, etc.).
  • Use Cases: Banking, telecom, enterprise resource planning (ERP) systems, and mission-critical applications.

Limitations of SQL Databases

While relational databases are extremely powerful for structured data and transactional systems, they are not without limitations — especially in the era of big data, real-time analytics, and unstructured information.
Let’s explore their main limitations:

1. Vertical Scaling (Limited by Machine Resources)

Relational databases typically scale vertically, meaning to handle more data or users, you must upgrade the existing server — adding more CPU, memory, or storage.
  • This becomes expensive and limited by hardware capacity.
  • It’s difficult to scale beyond a single powerful machine.
  • In contrast, modern NoSQL databases support horizontal scaling, distributing data across multiple servers.
Example:
A large social media platform generating millions of transactions per second would quickly outgrow the limits of a single SQL server.

2. Fixed Schema (Rigid for Evolving Data)

SQL databases use a fixed schema, meaning the structure of tables (columns and data types) must be defined in advance.
  • Any change in structure (adding a new column or changing a data type) requires altering the schema, which can be complex and time-consuming.
  • This rigidity makes it hard to adapt to evolving or unpredictable data.
Example:
If a company wants to start tracking an additional attribute, like “Preferred Payment Method,” they must modify the table schema — potentially affecting existing applications.
In contrast, NoSQL systems like MongoDB allow flexible, schema-less data models.

3. Not Suitable for Large-Scale Real-Time Systems

Relational databases are excellent for transactional consistency (ACID properties) but struggle with:
  • Massive concurrent writes.
  • Real-time analytics on streaming data.
  • Distributed or global-scale systems.
For instance, real-time recommendation engines, social media feeds, or sensor data from IoT devices often require high availability and horizontal scaling, which SQL databases find challenging.

4. Struggles with Unstructured and High-Volume Data

Relational databases are designed for structured, tabular data — not unstructured content like images, videos, logs, or social media text.
As modern applications generate large volumes of unstructured or semi-structured data, SQL databases become less efficient.
Example:
A video streaming service like YouTube or Netflix deals with enormous amounts of multimedia data. Managing such unstructured, massive-scale data efficiently requires specialized storage solutions or NoSQL databases, not traditional relational systems.

NoSQL Databases

In the age of big data, cloud computing, and high-speed web applications, traditional relational databases (SQL) often struggle to keep up with the demands of modern systems. The world needed databases that could scale horizontally, handle diverse data types, and provide faster performance for real-time applications. This led to the rise of NoSQL databases — a new generation of database systems designed to overcome the limitations of SQL databases.

Why NoSQL? (Solving SQL Limitations)

NoSQL stands for “Not Only SQL.” It represents a broad class of non-relational databases that can store and manage data in flexible formats other than traditional rows and columns.
Unlike relational databases, which rely on a rigid schema and structured tables, NoSQL databases are schema-less or semi-structured, allowing them to adapt to rapidly changing data requirements.
Let’s understand why NoSQL was developed — by examining the key limitations of SQL databases it was designed to solve.

1. Scalability

Traditional SQL databases scale vertically — by adding more CPU, memory, or storage to a single server. This approach becomes expensive and limited.
NoSQL databases, in contrast, are built for horizontal scaling — data is distributed across multiple servers (nodes) in a cluster. This enables them to handle huge volumes of data and high traffic loads efficiently.
Example:
A social media platform with millions of users and billions of posts (like Instagram or Twitter) can easily distribute data across multiple servers using a NoSQL system such as Cassandra or MongoDB.

2. Flexible Schema

In relational databases, every table has a fixed schema. Adding or changing a column requires altering the database structure, which can cause downtime or break applications.
NoSQL databases are schema-less or flexible-schema, meaning:
  • You can store records with different structures in the same collection.
  • Fields can be added or removed dynamically.
  • JSON-like formats allow nesting of data naturally.
Example:
In MongoDB, one document might look like:
hljs json
{ "name": "Alice", "email": "alice@example.com" }
and another:
hljs json
{ "name": "Bob", "email": "bob@example.com", "age": 30, "hobbies": ["reading", "cycling"] }
Both can coexist in the same collection — no predefined schema needed.

3. Handling Unstructured and Semi-Structured Data

Relational databases are excellent for structured data but not for images, videos, sensor data, or logs.
NoSQL databases are designed to handle unstructured, semi-structured, and multimedia data efficiently. This makes them ideal for modern applications like:
  • Social media platforms
  • IoT (Internet of Things)
  • Real-time analytics
  • Recommendation systems

4. High Availability and Distributed Architecture

NoSQL systems prioritize availability and fault tolerance. Data is automatically replicated across multiple servers. If one node fails, another can immediately take over.
This distributed design supports global-scale applications with millions of users across different locations.

Categories of NoSQL Databases

NoSQL databases come in several types, each optimized for specific use cases and data models. The four main categories are:
  1. Key-Value Stores
  2. Document Stores
  3. Column-Oriented Databases
  4. Graph Databases
Let’s explore each in detail.

1. Key-Value Stores

Definition:
A Key-Value Store is the simplest type of NoSQL database. Data is stored as a collection of key-value pairs, where each key is unique and directly maps to a specific value.
This structure is similar to a dictionary or hash map in programming languages.
Example:
text
"user:101" → {"name": "Alice", "age": 30}
"user:102" → {"name": "Bob", "age": 25}
Popular Example:
  • Redis
  • Amazon DynamoDB
  • Riak
Use Cases:
  • Caching
  • Session management
  • User profiles
  • Real-time analytics
Advantages:
  • Extremely fast reads and writes
  • Simple and lightweight
  • Easy to scale horizontally
Limitations:
  • No complex querying (data is retrieved only by key)
  • Not ideal for relationships or structured data

2. Document Stores

Definition:
Document-oriented databases store data as documents, typically in JSON, BSON, or XML format. Each document contains key-value pairs, arrays, and nested objects.
Documents are self-describing and can have different structures within the same collection.
Example (MongoDB Document):
hljs json
{
 "_id": 101,
 "name": "Alice Brown",
 "email": "alice@example.com",
 "purchases": [
 {"item": "Laptop", "price": 1200},
 {"item": "Mouse", "price": 25}
 ]
}
Popular Example:
  • MongoDB
  • CouchDB
  • Firebase Firestore
Use Cases:
  • Content management systems
  • E-commerce catalogs
  • User-generated content platforms
  • Mobile and web applications
Advantages:
  • Flexible schema
  • Natural data representation for developers (JSON format)
  • Easy to store hierarchical and nested data
  • Good performance for document-based queries
Limitations:
  • Less efficient for complex joins
  • Data redundancy may occur due to denormalization

3. Column-Oriented Databases

Definition:
Column-oriented (or Column-Family) databases store data by columns rather than by rows. Data is grouped into column families, each containing rows identified by a key, and each row can have a variable number of columns.
This format is designed for large-scale, high-performance analytics and distributed storage.
Example (Cassandra):
UserIDNameCityEmail
101AliceBostonalice@example.com
102BobDelhibob@example.com
Internally, Cassandra stores each column separately — allowing fast aggregation and retrieval for analytical workloads.
Popular Example:
  • Apache Cassandra
  • HBase
  • ScyllaDB
Use Cases:
  • Big data analytics
  • Time-series data
  • Logging systems
  • IoT data storage
Advantages:
  • High write and read throughput
  • Scales horizontally across clusters
  • Ideal for analytical queries
Limitations:
  • More complex to model and manage
  • Not suited for ad-hoc querying or transactions

4. Graph Databases

Definition:
Graph databases are designed to represent and query data that is highly interconnected.
Data is stored as nodes (entities) and edges (relationships) — forming a network-like structure.
Example:
If you’re storing social media data:
  • Nodes: Users (Alice, Bob, Carol)
  • Edges: Relationships (“Alice follows Bob”, “Bob follows Carol”)
Graph databases can efficiently answer queries like:
  • “Who are Alice’s friends of friends?”
  • “What is the shortest path between two users?”
Popular Example:
  • Neo4j
  • Amazon Neptune
  • ArangoDB
Use Cases:
  • Social networks
  • Fraud detection
  • Recommendation engines
  • Knowledge graphs
Advantages:
  • Efficient handling of complex relationships
  • Natural representation of networked data
  • Powerful for queries involving connections and patterns
Limitations:
  • Requires specialized query languages (e.g., Cypher)
  • Not ideal for simple key-value or document-style data

Limitations of NoSQL

While NoSQL databases provide flexibility and scalability, they also come with trade-offs. They sacrifice some features of relational systems to gain performance and scalability.

1. Lack of ACID Guarantees (Most Use BASE Model)

Relational databases follow ACID properties (Atomicity, Consistency, Isolation, Durability) to ensure reliable transactions.
Most NoSQL databases use the BASE model instead:
  • Basically Available – System guarantees availability.
  • Soft state – Data may not be consistent across all nodes immediately.
  • Eventually consistent – Data will become consistent over time.
This means:
  • Transactions might not be immediately consistent.
  • Some reads might return outdated data temporarily.
Example:
In a distributed system, if one node is updated, another might still show old data for a short time.

2. Complex Query Limitations

NoSQL databases lack the expressive querying power of SQL.
  • There is no standard query language across NoSQL systems.
  • Queries often require programmatic logic or specific APIs.
  • Complex aggregations and joins are harder to perform.
While systems like MongoDB have query capabilities, they’re still limited compared to the full SQL syntax.

3. Difficult Joins

NoSQL systems often avoid joins to maintain speed and scalability. Data is typically denormalized — meaning related data is stored together rather than linked through relationships.
This improves performance but leads to:
  • Data redundancy (same data copied in multiple places)
  • Complex data management when relationships change
Example:
In MongoDB, user and order data might be embedded in the same document instead of separate linked tables.

4. Consistency vs Availability Trade-Offs (CAP Theorem)

According to the CAP Theorem, a distributed database can only guarantee two of the following three properties at once:
  1. Consistency (C): Every read receives the most recent write.
  2. Availability (A): Every request gets a response (even if some nodes fail).
  3. Partition Tolerance (P): System continues operating even if communication fails between parts of the system.
NoSQL databases often prioritize Availability and Partition Tolerance (AP) over strict Consistency, to maintain uptime and scalability.
This trade-off means that applications must handle eventual consistency and data synchronization on their own.

Why Data Systems Need to Scale

As organizations and applications grow, the amount of data they collect, store, and process expands exponentially. What begins as a simple system serving a few users can quickly become a massive infrastructure challenge as user numbers surge. Scalability — the ability of a data system to handle increasing loads without performance degradation — becomes not just a desirable feature, but an absolute necessity.
Modern platforms like Twitter, Instagram, and Netflix handle millions (or even billions) of users, each generating constant streams of data. To deliver seamless user experiences, these systems must scale efficiently to manage growth, maintain high availability, and ensure low latency.

1. Growth in Users = Growth in Data

Every new user added to an application contributes to data growth. Whether it’s creating an account, uploading a photo, liking a post, or sending a message — every action generates data that needs to be stored, processed, and served back to users efficiently.
Let’s break this down further.

A. Volume Growth

As the user base expands, the volume of data increases dramatically.
  • A few hundred users might generate megabytes of data daily.
  • Millions of users can generate terabytes or petabytes of data every day.
For example:
  • Each tweet on Twitter is a small text record, but at hundreds of millions of tweets per day, this results in massive data accumulation.
  • Instagram users upload millions of photos and videos daily — resulting in enormous storage needs.
The data growth rate often outpaces the growth in infrastructure if systems are not designed to scale.

B. Velocity Growth

It’s not just about how much data exists — it’s also how fast it arrives.
As applications gain popularity, the rate of incoming data (velocity) increases.
For instance:
  • A news feed system must handle thousands of new updates per second.
  • Streaming platforms like YouTube must ingest, encode, and distribute videos continuously.
  • Real-time analytics (like ad tracking or live dashboards) require systems that can process high-velocity data streams instantly.
This requires a data architecture that can scale in real-time, not just in storage but in processing power.

C. Variety Growth

As systems evolve, they start handling not just structured data (like user profiles), but also unstructured and semi-structured data such as:
  • Photos, videos, and audio clips
  • Chat messages
  • Clickstream logs
  • Sensor data (IoT)
Each type of data has unique storage, indexing, and retrieval requirements. Traditional monolithic systems are ill-suited for handling this diversity at scale — driving the adoption of scalable, distributed data systems.

2. Real-Life Examples: How Twitter and Instagram Scale

To truly understand the need for scalability, it helps to look at how real-world, large-scale systems manage their massive data and user growth.
Let’s explore two well-known examples — Twitter and Instagram.

A. Twitter

Scale Challenge:
Twitter handles hundreds of millions of users and billions of tweets each month. Every tweet generates additional data — hashtags, likes, retweets, mentions, and notifications — all of which must be processed in real-time.
Data Characteristics:
  • High volume (billions of records)
  • High velocity (tweets per second)
  • Real-time access (users expect instant updates)
  • Complex relationships (follows, mentions, hashtags)
How Twitter Scales:
  1. Distributed Storage:
Twitter uses distributed databases and caching systems to store user data and timelines across multiple servers and data centers.
Technologies like Manhattan (Twitter’s distributed database) and Cassandra ensure horizontal scalability.
  1. Sharding:
User data is partitioned (“sharded”) across multiple databases. For example, one shard might store users 1–10 million, while another stores 10–20 million.
  1. Caching for Performance:
To handle high read traffic, Twitter uses Redis and Memcached as caching layers. Frequently accessed data (like timelines) is served from cache instead of databases, reducing latency.
  1. Microservices Architecture:
Twitter broke its monolithic backend into multiple smaller services (e.g., Tweet Service, User Service, Search Service). This enables independent scaling of specific parts of the system.
Outcome:
Twitter achieves near real-time data delivery across millions of users — a feat only possible due to its scalable architecture.

B. Instagram

Scale Challenge:
Instagram serves over a billion active users who share photos, videos, reels, and messages. The platform must store, retrieve, and display this content globally in near real-time.
Data Characteristics:
  • High-volume unstructured data (images and videos)
  • Heavy read/write operations (likes, comments, follows)
  • Global access with low latency requirements
How Instagram Scales:
  1. Use of Distributed Databases:
Instagram originally used PostgreSQL, but as data grew, they moved toward a sharded relational database model and NoSQL systems like Cassandra for scalability.
  1. Content Delivery Networks (CDNs):
To reduce latency, Instagram uses global CDNs to deliver images and videos quickly, regardless of user location.
  1. Caching Layers:
Systems like Redis and Memcached store frequently accessed content, minimizing database hits.
  1. Microservices and Cloud Scaling:
Instagram leverages Amazon Web Services (AWS) for auto-scaling, allowing the infrastructure to dynamically allocate more servers during traffic spikes.
Outcome:
Instagram maintains smooth performance for billions of media uploads, likes, and comments daily by scaling horizontally and leveraging distributed systems.

3. Need for High Availability and Low Latency

As systems scale, two key requirements emerge: High Availability (HA) and Low Latency. These are essential for providing a seamless and reliable user experience, especially in systems that operate globally and continuously.

A. High Availability (HA)

Definition:
High availability refers to a system’s ability to remain operational and accessible even when some components fail.
In large-scale distributed systems, downtime is unacceptable, as it leads to lost revenue, poor user experience, and reputational damage.
Key Aspects of HA:
  1. Redundancy:
Data and services are duplicated across multiple servers and regions. If one node fails, another immediately takes over.
  1. Replication:
Copies of data are maintained in different locations. For example, MongoDB or Cassandra automatically replicate data across clusters.
  1. Failover Mechanisms:
When a server or service crashes, traffic is automatically redirected to healthy nodes without interrupting service.
  1. Load Balancing:
Incoming requests are distributed evenly among multiple servers to prevent overload on any single node.
Example:
  • In Instagram, if a database server in the US-East region fails, requests are automatically rerouted to another data center (e.g., US-West or Europe) without affecting users.
  • Twitter ensures tweet availability by replicating data across multiple nodes.
Goal:
Achieve 99.99% or higher uptime — meaning the system can operate continuously even under hardware or network failures.

B. Low Latency

Definition:
Latency is the delay between a user’s request and the system’s response. Low latency means faster performance and better user experience.
In large-scale data systems, maintaining low latency is critical because:
  • Users expect real-time responses (e.g., loading a tweet or video instantly).
  • Delays lead to frustration, abandonment, or reduced engagement.
Techniques for Achieving Low Latency:
  1. Caching:
Frequently accessed data is stored in memory (Redis, Memcached) for faster retrieval.
  1. Data Partitioning (Sharding):
Dividing data across multiple servers reduces the load on any single database.
  1. Geographical Distribution:
Using Content Delivery Networks (CDNs) and edge servers ensures data is served from the nearest physical location.
  1. Asynchronous Processing:
Background tasks (like sending notifications or processing analytics) are handled asynchronously using message queues (e.g., Kafka, RabbitMQ), preventing delays in core functions.
  1. Optimized Data Models:
Storing data in formats that align with access patterns (e.g., key-value lookups for quick reads).
Example:
  • When a user likes a photo on Instagram, the system must update the like count, notify the photo owner, and display the change — all within milliseconds.
  • Twitter’s feed refresh must show new tweets almost instantly after posting.
Maintaining this responsiveness across millions of concurrent users requires extreme optimization and scalable infrastructure.

Distributed Systems Basics

As modern applications grow in complexity and scale, relying on a single machine or centralized database becomes impractical. Billions of users access online services simultaneously, generating massive amounts of data that must be stored, processed, and served quickly — across the globe. To meet these demands, systems are designed to distribute their workload across multiple computers that work together as a single logical unit.
Such systems are called Distributed Systems, and they form the backbone of most large-scale applications — including Google Search, Amazon Shopping, and Netflix.
Let’s explore the core ideas, reasons, scaling strategies, and the famous CAP theorem that defines how distributed systems are designed.

1. What is a Distributed System?

A Distributed System is a collection of independent computers (nodes) that appear to users as a single, unified system. These nodes communicate and coordinate their actions through a network to achieve a common goal — such as processing data, serving web requests, or storing files.
Formal Definition:
A distributed system is a system in which components located on networked computers communicate and coordinate their actions by passing messages.
Key Idea:
Instead of relying on one powerful server, a distributed system uses many interconnected machines that share resources and work collaboratively.

Example:

Imagine a search query on Google:
  1. You type a search phrase (e.g., “Best laptops 2025”).
  2. The request is sent to a data center containing thousands of servers.
  3. Each server is responsible for searching a portion of Google’s vast index.
  4. The results from multiple servers are combined and sent back — all in less than a second.
From your perspective, Google feels like one single search engine, but in reality, it’s powered by thousands of distributed servers working in parallel.

Key Characteristics of Distributed Systems:

  1. Multiple Nodes:
Consists of several independent computers (servers or nodes) connected via a network.
  1. Shared Goal:
Nodes cooperate to perform a unified function (e.g., serving web pages, processing data).
  1. Transparency:
Users see the system as one entity, even though it’s made of many machines.
  1. Fault Tolerance:
The system continues to function even if some nodes fail.
  1. Scalability:
New machines can be added to handle more data or users.
Examples of Distributed Systems:
  • Cloud storage systems (Google Drive, Dropbox)
  • Social media platforms (Facebook, Twitter)
  • Streaming services (Netflix, Spotify)
  • E-commerce platforms (Amazon)

2. Why Do We Distribute Systems?

The decision to design distributed systems comes from the need to handle large-scale workloads, ensure fault tolerance, and provide global access. Let’s explore the main reasons.

A. Scalability

As user demand increases, a single machine can’t handle all requests.
Distributed systems allow scaling out — adding more servers to share the load.
For example:
  • Amazon handles millions of orders every day.
  • Netflix streams millions of videos simultaneously.
These would be impossible on one server; distributing the workload across many servers ensures scalability.

B. Fault Tolerance and Reliability

In centralized systems, if the single server crashes, the entire application becomes unavailable.
Distributed systems replicate data and services across multiple nodes, ensuring continuity even if some nodes fail.
Example:
If one Netflix server fails, users are automatically redirected to another available server. The system remains operational — this is fault tolerance.

C. Performance and Low Latency

Distributed systems reduce latency by serving requests from servers geographically closer to users.
Example:
  • A user in India accessing YouTube is served from a nearby data center in Asia, not one in the US.
  • This reduces network delay and improves response time.

D. Resource Sharing

Different nodes can share resources — such as processing power, storage, or bandwidth — making the system more efficient and cost-effective.

E. Geographic Distribution and Availability

Modern applications operate globally. Distributed systems allow data to be stored and served from multiple regions, ensuring high availability and fast access across the world.

3. Horizontal Scaling vs Vertical Scaling

Scaling determines how a system grows to handle increasing loads. There are two primary scaling methods: Vertical Scaling and Horizontal Scaling.

A. Vertical Scaling (Scaling Up)

Definition:
Increasing the capacity of a single machine by adding more resources — CPU, memory, or storage.
Example:
  • Upgrading a server from 8 GB RAM to 32 GB RAM.
  • Adding faster processors or more powerful disks.
Advantages:
  • Simpler to implement (no need to modify the application).
  • Works well for small-scale systems.
Limitations:
  • Physical limits: There’s only so much hardware you can add.
  • Expensive hardware upgrades.
  • Single point of failure — if the machine fails, the entire system fails.

B. Horizontal Scaling (Scaling Out)

Definition:
Adding more machines (nodes) to distribute the workload across multiple systems.
Example:
  • Instead of one powerful server, you use 10 smaller ones that share the work.
  • Common in distributed and cloud-based systems.
Advantages:
  • Virtually unlimited scalability.
  • Improved fault tolerance — failure of one node doesn’t take down the system.
  • Cost-effective — easier to add commodity (cheap) servers.
Limitations:
  • Increased system complexity (data consistency, coordination, and communication).
  • Requires distributed data management and synchronization.

Comparison:

AspectVertical ScalingHorizontal Scaling
MethodAdd more power to one machineAdd more machines to the network
Scalability LimitLimited by hardwareVirtually unlimited
CostExpensive (high-end hardware)Cost-effective (commodity servers)
Fault ToleranceSingle point of failureHigh fault tolerance
ImplementationSimpleComplex (requires distributed architecture)
ExampleUpgrading one large database serverUsing multiple distributed database nodes
Most modern large-scale systems (like Google, Amazon, Netflix) rely on horizontal scaling using distributed systems to achieve scalability, fault tolerance, and performance.

4. Consistency, Availability, and Partition Tolerance (CAP Theorem)

The CAP Theorem is a fundamental concept in distributed systems that explains the trade-offs between three key properties:
  1. Consistency (C)
  2. Availability (A)
  3. Partition Tolerance (P)
Formulated by Eric Brewer in 2000, the theorem states that:
In any distributed data system, you can achieve only two of the three properties — Consistency, Availability, or Partition Tolerance — but not all three simultaneously.
Let’s understand each term in detail.

A. Consistency (C)

Every read operation receives the most recent write.
In other words, all nodes in the system return the same, up-to-date data at any given time.
Example:
If you update your Instagram profile picture, every device (mobile, web, API) should show the same image immediately.
Challenge:
Achieving strong consistency requires all nodes to synchronize — which can slow the system or reduce availability during network issues.

B. Availability (A)

Every request receives a valid response, even if some nodes are unavailable.
The system is always operational.
Example:
When shopping on Amazon, even if one data center is down, you can still browse and place orders — the system remains available.
Challenge:
To ensure availability, the system might temporarily serve slightly outdated (stale) data until synchronization occurs.

C. Partition Tolerance (P)

The system continues to operate even if communication between some nodes fails (network partition).
Example:
If a network issue separates servers in Europe and the US, both should still function independently until the connection is restored.

The Trade-Off (CAP Theorem in Action)

A distributed system must tolerate network partitions (P) — because network failures are inevitable. Therefore, designers must choose between Consistency (C) and Availability (A):
System TypeGuaranteesExample Systems
CP (Consistency + Partition Tolerance)Strong consistency, but may sacrifice availability during failures.Traditional databases like HBase, MongoDB (with consistency mode).
AP (Availability + Partition Tolerance)Always available, but may serve stale data temporarily.DynamoDB, Cassandra, CouchDB.

5. Real-World Distributed Systems Examples

Let’s look at how global companies implement distributed systems to achieve scalability, performance, and fault tolerance.
  • Challenge: Billions of search queries every day across the world.
  • Distributed Design:
  • Index data spread across thousands of servers in multiple data centers.
  • Each server handles a portion of the web index.
  • Uses load balancing to distribute incoming queries.
  • Employs caching for fast query responses.
  • Goal: Sub-second responses globally with continuous availability.

B. Amazon Shopping

  • Challenge: Millions of users, product listings, and orders worldwide.
  • Distributed Design:
  • Uses microservices architecture (independent services for product search, cart, payments, etc.).
  • Data is replicated and distributed across multiple regions.
  • Employs NoSQL databases (like DynamoDB) for high availability.
  • Uses load balancing and failover for reliability.
  • Goal: Always available, even during server or regional outages.

C. Netflix Streaming

  • Challenge: Streams billions of hours of video to users globally.
  • Distributed Design:
  • Uses Content Delivery Networks (CDNs) to serve content from servers nearest to the user.
  • Employs microservices — separate services for recommendations, billing, streaming, etc.
  • Stores massive metadata and user data in Cassandra for scalability and fault tolerance.
  • Auto-scales using AWS cloud infrastructure to meet changing traffic demands.
  • Goal: Smooth playback, minimal buffering, and uninterrupted availability.