<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Lawrence Murithi</title>
    <description>The latest articles on Forem by Lawrence Murithi (@lawrence_murithi).</description>
    <link>https://forem.com/lawrence_murithi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3713327%2Fe1187555-8b89-4a2c-9168-be280e1c6b86.png</url>
      <title>Forem: Lawrence Murithi</title>
      <link>https://forem.com/lawrence_murithi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/lawrence_murithi"/>
    <language>en</language>
    <item>
      <title>A Beginner’s Guide to Apache Kafka: The Engine of Real-Time Data</title>
      <dc:creator>Lawrence Murithi</dc:creator>
      <pubDate>Thu, 14 May 2026 07:34:43 +0000</pubDate>
      <link>https://forem.com/lawrence_murithi/a-beginners-guide-to-apache-kafka-the-engine-of-real-time-data-2k7j</link>
      <guid>https://forem.com/lawrence_murithi/a-beginners-guide-to-apache-kafka-the-engine-of-real-time-data-2k7j</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Imagine you are running a massive online store. Every second, hundreds of users are clicking items, adding them to carts and making purchases. Your inventory system needs to know about the purchases, your recommendation engine needs to know about the clicks and your security system needs to monitor for fraud.&lt;br&gt;
If you connect every single system directly to each other, you get a tangled, unmanageable mess.&lt;br&gt;
This is the exact problem Apache Kafka was built to solve. Instead of systems talking directly to each other, they all send their data to a &lt;strong&gt;central hub (Kafka)&lt;/strong&gt; and any system that needs that data simply reads it from the hub. This creates a completely decoupled architecture; the system sending the data doesn't need to know anything about the systems receiving it.&lt;br&gt;
This article delves into everything you need to know to understand Apache Kafka, from its history to running your first commands.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is Apache Kafka?
&lt;/h3&gt;

&lt;p&gt;Apache Kafka is an &lt;strong&gt;open-source distributed event streaming&lt;/strong&gt; platform.&lt;br&gt;
Let's break that down.&lt;br&gt;
&lt;strong&gt;• Event&lt;/strong&gt; - This is a record of something that happened (e.g. User A clicked button B at 12:00 PM). These events, also known as messages or records, are the fundamental immutable data structures consisting of a &lt;strong&gt;key&lt;/strong&gt;, &lt;strong&gt;value&lt;/strong&gt;, &lt;strong&gt;timestamp&lt;/strong&gt; and &lt;strong&gt;headers&lt;/strong&gt; that are continuously transmitted.&lt;br&gt;
&lt;strong&gt;• Streaming&lt;/strong&gt; - The data flows continuously in real-time, rather than waiting to be processed in daily batches. Kafka allows you to publish (write) and subscribe to (read) streams of events, store them indefinitely, and process them as they occur.&lt;br&gt;
&lt;strong&gt;• Distributed&lt;/strong&gt; - It doesn't just run on one computer. It runs across many computers working together, making it incredibly fast and virtually impossible to crash.&lt;br&gt;
Think of Kafka as a massive, high-speed, highly organized post office. Senders drop off packages (data) and the post office holds onto them until the receivers come to pick them up. This complete journey of data, from generation and publishing to storage, consumption, and eventual deletion, represents the &lt;strong&gt;Kafka lifecycle&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Kafka was originally created at &lt;strong&gt;LinkedIn&lt;/strong&gt; in &lt;strong&gt;2011&lt;/strong&gt; by software engineers &lt;strong&gt;Jay Kreps&lt;/strong&gt;, &lt;strong&gt;Neha Narkhede&lt;/strong&gt; and &lt;strong&gt;Jun Rao&lt;/strong&gt;.&lt;br&gt;
LinkedIn was generating billions of data points daily (profile views, messages, connections), and their existing databases and message queues couldn't keep up. They needed a system that could handle these massive amounts of data in real-time without slowing down.&lt;br&gt;
It was named Kafka, after the author &lt;strong&gt;Franz Kafka&lt;/strong&gt;, because he was a writer and the software was an &lt;strong&gt;optimized system for writing data&lt;/strong&gt;. Eventually, LinkedIn gave it out to the Apache Software Foundation, making it free and open-source.&lt;/p&gt;
&lt;h3&gt;
  
  
  Core Characteristics of Kafka
&lt;/h3&gt;

&lt;p&gt;Thousands of companies such as Netflix, Uber and Airbnb use Kafka for various reasons.&lt;br&gt;
&lt;strong&gt;1. High Throughput&lt;/strong&gt; - Kafka can handle millions of messages per second.&lt;br&gt;
&lt;strong&gt;2. Scalable&lt;/strong&gt; - Kafka expands seamlessly without any downtime. If you need more power, you just add another computer (node) to the Kafka system.&lt;br&gt;
&lt;strong&gt;3. Permanent (Durable)&lt;/strong&gt; - Unlike traditional message queues that delete a message once it is read, Kafka writes data to a hard drive and keeps it for a set amount of time (days, weeks, or forever).&lt;br&gt;
&lt;strong&gt;4. Fault-Tolerant&lt;/strong&gt; - Kafka keeps copies (replicas) of your data on different computers. If one computer crashes or catches fire, the data is still safe on another, and the system automatically switches to the backup without missing a beat.&lt;/p&gt;
&lt;h4&gt;
  
  
  When to Use Kafka
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;• Real-time tracking&lt;/strong&gt; - Tracking website activity (page views, clicks) as it happens.&lt;br&gt;
&lt;strong&gt;• Log aggregation&lt;/strong&gt; - Collecting logs from hundreds of different servers into one central place for monitoring, debugging, or auditing.&lt;br&gt;
&lt;strong&gt;• Location tracking&lt;/strong&gt; - Apps like Uber use Kafka to process the real-time GPS locations of drivers and riders.&lt;br&gt;
&lt;strong&gt;• Stream processing&lt;/strong&gt; - Transforming data on the fly such as using the Kafka Streams API to convert currencies in real-time as transactions happen.&lt;br&gt;
&lt;strong&gt;• Event sourcing&lt;/strong&gt; - Storing state-changing events. Instead of overwriting existing data to save the current state, you permanently record every individual action that led to that state as an append-only log(a database doesn't update a shopping cart's final inventory to show 1 Hat, it records the exact history, Added Shirt, Added Hat and Removed Shirt).&lt;br&gt;
&lt;strong&gt;• Data Integration&lt;/strong&gt; - Using Kafka Connect to continuously pull data from an old database and push it into a new cloud warehouse.  In this context, kafka connect is utilized as a specialized tool and framework for scalably and reliably streaming data between Kafka and these external systems without custom code.&lt;/p&gt;
&lt;h4&gt;
  
  
  When NOT to use Kafka
&lt;/h4&gt;

&lt;p&gt;• You just need a standard database to search for specific records (use SQL or NoSQL). Kafka is designed for sequential reading, not searching for a specific item.&lt;br&gt;
• You only have a small amount of data (Kafka is complex; setting it up for low traffic is overkill).&lt;br&gt;
• You need simple task routing.&lt;/p&gt;
&lt;h3&gt;
  
  
  Key Kafka Concepts and Rules
&lt;/h3&gt;

&lt;p&gt;To understand Kafka, you need to know its vocabulary and the strict rules that govern how data is managed.&lt;br&gt;
&lt;strong&gt;• Event (Message/record)&lt;/strong&gt; - This is the actual piece of data( immutable record of something that happened). An event consists of a Key, a Value, a Timestamp, and optional metadata headers. The Message Key acts as an &lt;strong&gt;optional identifier&lt;/strong&gt; used for routing the event to a specific partition, while the Message Value is the &lt;strong&gt;core payload&lt;/strong&gt; containing the business data. The Value is the actual data. The Key is optional but important for organizing data. Before an event is sent over the network, it is translated into a binary format (bytes) in a process called serialization. &lt;br&gt;
&lt;strong&gt;Serialization&lt;/strong&gt; is the crucial step of converting these readable data objects into binary bytes for efficient network transmission and storage. Conversely, &lt;strong&gt;Deserialization&lt;/strong&gt; is the reverse process used by consumers to convert those binary bytes back into readable data.&lt;br&gt;
&lt;strong&gt;• Producer&lt;/strong&gt; - The application that sends data into Kafka (e.g. the website frontend sending click data). Producers &lt;strong&gt;send/write (publish)&lt;/strong&gt; messages to topics and decide which partition the data should be sent to. &lt;br&gt;
&lt;strong&gt;• Consumer&lt;/strong&gt; - The application that reads data from Kafka (e.g. the analytics dashboard). Consumers &lt;strong&gt;receive/read (subscribe)&lt;/strong&gt; messages from topics.&lt;br&gt;
&lt;strong&gt;• Topic&lt;/strong&gt; - Its a named stream of events or logical category or channel where related events are continuously published and stored. &lt;br&gt;
If you send user clicks to Kafka, you would send them to a topic named user_clicks. Consumers read from specific topics. Unlike traditional queues, topics have a retention policy. You configure a topic to keep data for 24 hours, 7 days, or until the disk reaches a certain size. Once the limit is hit, the oldest data is automatically deleted.&lt;br&gt;
&lt;strong&gt;• Partition&lt;/strong&gt; - This is the secret to Kafka's speed. A single topic is split into multiple parts called Partitions. They split data across multiple brokers/servers, enabling multiple consumers to read data in parallel. This is the mechanism that allows Kafka to scale and process massive amounts of data concurrently.&lt;br&gt;
Imagine a grocery store with only one checkout lane (one topic), a line forms. If you open 10 checkout lanes (partitions), 10 times as many people can check out at once.&lt;br&gt;
    &lt;strong&gt;- Rule 1&lt;/strong&gt; - Order is only guaranteed within a single partition. If you send messages to Partition 0 and Partition 1, you cannot guarantee which one gets read first. But messages inside each individual partition are read in the exact order they arrive.&lt;br&gt;
    &lt;strong&gt;- Rule 2&lt;/strong&gt; - Keys determine the partition. If a Producer sends an event without a key, Kafka assigns it to a &lt;strong&gt;random partition&lt;/strong&gt; (&lt;strong&gt;Round-robin routing&lt;/strong&gt;). If an event has a key (like customer_id_123), Kafka uses a &lt;strong&gt;math formula&lt;/strong&gt; (&lt;strong&gt;hashing&lt;/strong&gt;) to ensure every event with that same key always goes to the exact same partition. This guarantees all purchases by customer_123 are processed in the correct order.&lt;br&gt;
&lt;strong&gt;• Offset&lt;/strong&gt; - Inside a partition, every single message is assigned a unique, sequential ID number called an Offset (e.g., 0, 1, 2, 3...). These offsets act as unique, ever-increasing integers used to accurately maintain reading positions. Offsets only go up and are never reused. Consumers use offsets to keep a bookmark of their specific reading position so they can resume reading safely after a crash or restart.&lt;br&gt;
&lt;strong&gt;• Consumer Groups&lt;/strong&gt; - A team of consumers working together to read a topic.&lt;br&gt;
      &lt;strong&gt;- The Golden Rule&lt;/strong&gt; - A single partition can only be read by one consumer within the same group. If a topic has 4 partitions, and your group has 4 consumers, each gets exactly one partition. If you have 5 consumers in the group, the 5th one sits idle. This is how Kafka scales reading perfectly without processing the same message twice.&lt;br&gt;
&lt;strong&gt;• Broker/ Server&lt;/strong&gt; - A single Kafka node. This individual node is responsible for receiving messages from producers, storing them on disk, and serving them to consumers upon request.&lt;br&gt;
&lt;strong&gt;• Cluster&lt;/strong&gt; - A group of Brokers(servers) working together. Brokers are linked together to operate seamlessly as a single distributed network, providing fault tolerance, high availability, and massive scale. Within a cluster, data is duplicated across brokers using a Replication Factor. &lt;strong&gt;Replication factor&lt;/strong&gt; is a configuration defining the exact number of copies of a partition that must be maintained across different brokers to ensure fault tolerance. If your Replication Factor is 3, three different brokers have a copy of the data. &lt;br&gt;
For each partition, one broker is assigned the &lt;strong&gt;Leader&lt;/strong&gt; (&lt;strong&gt;primary broker&lt;/strong&gt;) and exclusively handles all read and write requests for that specific partition to ensure strict data consistency. &lt;br&gt;
The other brokers become &lt;strong&gt;Followers&lt;/strong&gt; (&lt;strong&gt;backup brokers&lt;/strong&gt;) and they passively replicate the data from the Leader (acting as &lt;strong&gt;In-Sync Replicas or ISR&lt;/strong&gt;) so they can seamlessly and instantly take over if the Leader fails. &lt;br&gt;
&lt;strong&gt;• KRaft (Kafka Raft)&lt;/strong&gt; - The internal manager of Kafka. Kraft is the modern built-in consensus protocol that functions as the internal cluster manager, meaning it is the overarching system responsible for managing broker states, leader elections, and metadata within Kafka. It keeps track of which brokers are online, which broker holds which partition, and handles the recovery if a broker crashes.&lt;br&gt;
Historically, &lt;strong&gt;Zookeeper&lt;/strong&gt; served as the legacy external coordination service that acted as the cluster manager before being phased out. Kafka recently removed ZooKeeper and replaced it with KRaft, which is built directly into Kafka to make it faster and easier to manage the state of the cluster.&lt;/p&gt;
&lt;h4&gt;
  
  
  How Kafka Works
&lt;/h4&gt;

&lt;p&gt;Here is a detailed flow of how data moves through Kafka, showing Partitions, Offsets, and Consumer Groups:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F32llb28fmx5uhca0maju.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F32llb28fmx5uhca0maju.png" alt="How Kafka works" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;NB:&lt;/strong&gt; Two different Consumer Groups can read the exact same messages without interfering with each other. Because Kafka stores the data on disk, Consumer Group 2 (Receipt System) can read the message hours after Consumer Group 1 (Inventory System) read it, simply by starting at an older Offset.&lt;/p&gt;
&lt;h3&gt;
  
  
  Kafka architecture
&lt;/h3&gt;

&lt;p&gt;To understand Apache Kafka’s architecture, we need to examine its internal design and core components.&lt;br&gt;
Kafka architecture explains how Kafka does what it does. Kafka’s architecture is designed to do three things flawlessly; &lt;strong&gt;never lose data&lt;/strong&gt;, &lt;strong&gt;handle millions of messages a second&lt;/strong&gt;, and &lt;strong&gt;scale up without turning the system off&lt;/strong&gt;.&lt;br&gt;
To understand how it works, we can break Kafka’s architecture into three main areas. &lt;br&gt;
&lt;strong&gt;1. The Network Architecture (The Physical Components)&lt;/strong&gt;&lt;br&gt;
Kafka is a distributed system, meaning it is not just one big computer. It is a network of smaller computers working together as a single unit and comprises of The Kafka Cluster, Brokers, The KRaft Controller (The Manager), Producers and Consumers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The Data Architecture/Storage (Logical Components)&lt;/strong&gt;&lt;br&gt;
Kafka does not store data in tables like a standard database. It stores data using a concept called an &lt;strong&gt;Append-Only Commit Log&lt;/strong&gt;.&lt;br&gt;
Imagine a physical logbook. When a new message arrives, Kafka writes it at the very bottom of the page. You cannot erase, edit, or insert a message in the middle. You can only append (add) to the end.&lt;br&gt;
This architectural choice is the secret to Kafka's speed. Because it never wastes time searching for a record to update or delete, writing to Kafka is incredibly fast.&lt;/p&gt;
&lt;h4&gt;
  
  
  How Topics and Partitions fit into the Log.
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;A  Topic is just a logical name for a group of these logbooks.&lt;/li&gt;
&lt;li&gt;A Partition is the actual physical logbook file sitting on a Broker's hard drive.&lt;/li&gt;
&lt;li&gt;An Offset is the line number in that logbook.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. High Availability Architecture (Fault Tolerance)&lt;/strong&gt;&lt;br&gt;
Because hardware fails, Kafka’s architecture assumes that brokers will eventually crash. It protects your data using Replication.&lt;br&gt;
When you create a topic, you set a Replication Factor. If you set a replication factor of 3, Kafka guarantees that three different Brokers will have an exact copy of the data.&lt;br&gt;
For every single partition, Kafka elects one Broker to be the Leader. which Producers and Consumers talk. The other Brokers are become Followers. They do not talk to producers or consumers but copy everything the Leader does in real-time.&lt;br&gt;
If the Leader broker crashes, the KRaft Controller notices immediately. It instantly promotes one of the Followers to become the new Leader. The Producers and Consumers automatically connect to the new Leader, and the system continues without dropping a single message.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. The Philosophy(Core Design Rules)&lt;/strong&gt;&lt;br&gt;
Kafka’s architecture relies on a few specific design choices that make it different from almost every other messaging system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A. Smart Consumers, Dumb Brokers/Servers&lt;/strong&gt;&lt;br&gt;
In traditional message queues, the server (the queue) is smart. It remembers which consumer read which message and deletes the message after it is read. This puts a heavy workload on the server.&lt;br&gt;
Kafka flipped this architecture. The Kafka Broker is dumb while the Consumer is smart. The server just stores the data and deletes it after a certain time while the consumer tracks its own Offset (its place in the logbook). This takes a massive load off the brokers, allowing them to handle millions of messages per second.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;B. The Pull Model&lt;/strong&gt;&lt;br&gt;
Many systems push data to the consumers. If a sudden spike in traffic happens, the system pushes so much data that it crashes the consumer application.&lt;br&gt;
Kafka uses a Pull architecture. Producers push data into Kafka, but Kafka never pushes data to Consumers. The Consumers pull data from Kafka only when they are ready for it. If the consumer gets overloaded, it just slows down its pulling. The data waits safely on Kafka’s hard drive until the consumer catches up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;C. Using Disk instead of RAM (The OS Page Cache)&lt;/strong&gt;&lt;br&gt;
While most messaging systems try to keep data in RAM (memory) because it is faster, Kafka writes straight to the hard drive.&lt;br&gt;
because it relies on the Operating System's Page Cache. The OS automatically uses free RAM to temporarily hold the most recently written data. When a consumer asks for the latest data, Kafka actually serves it straight from the OS memory without ever spinning the hard disk, giving you memory-like speeds with hard-drive-like storage capacity.&lt;/p&gt;
&lt;h4&gt;
  
  
  Visualizing the Architecture
&lt;/h4&gt;

&lt;p&gt;Here is how all these pieces connect in a real-world scenario.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fecyzp16n797rk3t1e2jw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fecyzp16n797rk3t1e2jw.png" alt="Kafka Architecture" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  How to Install Apache Kafka (Locally)
&lt;/h3&gt;

&lt;p&gt;To run Kafka on your computer, you need to have Java installed.&lt;br&gt;
&lt;em&gt;Step 1: Download Kafka&lt;/em&gt;&lt;br&gt;
Go to the official Apache Kafka Downloads page &lt;a href="https://kafka.apache.org/community/downloads/" rel="noopener noreferrer"&gt;here&lt;/a&gt; and download the latest .tgz file (binaries).&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Step 2: Extract the file&lt;/em&gt;&lt;br&gt;
Open your terminal and extract the folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;tar&lt;/span&gt; &lt;span class="nt"&gt;-xzf&lt;/span&gt; kafka_2.13-4.2.0.tgz

&lt;span class="c"&gt;# you can rename the folder &lt;/span&gt;
&lt;span class="nb"&gt;mv &lt;/span&gt;kafka_2.13-4.2.0/ kafka

&lt;span class="c"&gt;# Navigate into the folder&lt;/span&gt;
&lt;span class="nb"&gt;cd &lt;/span&gt;kafka
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Step 3: Generate a Cluster UUID&lt;/em&gt;&lt;br&gt;
Since we are using modern Kafka (KRaft mode), first generate a unique ID for the cluster&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;KAFKA_CLUSTER_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;bin/kafka-storage.sh random-uuid&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Step 4: Format the Storage&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bin/kafka-storage.sh format &lt;span class="nt"&gt;-t&lt;/span&gt; &lt;span class="nv"&gt;$KAFKA_CLUSTER_ID&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; config/kraft/server.properties
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Step 5: Start the Kafka Server&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bin/kafka-server-start.sh config/kraft/server.properties
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Leave this terminal window open. Kafka is now running!&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Kafka Commands for Beginners
&lt;/h4&gt;

&lt;p&gt;Open a new terminal window (keep the server running in the first one) to run these commands.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;1. Create a Topic&lt;/em&gt;&lt;br&gt;
Before you can send data, you need to create a topic. Let's create one called first_topic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bin/kafka-topics.sh &lt;span class="nt"&gt;--create&lt;/span&gt; &lt;span class="nt"&gt;--topic&lt;/span&gt; first_topic &lt;span class="nt"&gt;--bootstrap-server&lt;/span&gt; localhost:9092 &lt;span class="nt"&gt;--partitions&lt;/span&gt; 3 &lt;span class="nt"&gt;--replication-factor&lt;/span&gt; 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NB:&lt;/strong&gt; localhost:9092 is the default address where your local Kafka broker is running. We set --partitions 3 to split the topic into three lanes for speed, and --replication-factor 1 because we only have one local broker running right now.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;2. Start a Producer (Send Data)&lt;/em&gt;&lt;br&gt;
This command opens a prompt where you can type messages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bin/kafka-console-producer.sh &lt;span class="nt"&gt;--topic&lt;/span&gt; first_topic &lt;span class="nt"&gt;--bootstrap-server&lt;/span&gt; localhost:9092
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once it starts, type a few lines and hit Enter after each.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hello Kafka!&lt;br&gt;
This is my first message.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;3. Start a Consumer (Read Data)&lt;/em&gt;&lt;br&gt;
Open a third terminal window and run the below command to read the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bin/kafka-console-consumer.sh &lt;span class="nt"&gt;--topic&lt;/span&gt; first_topic &lt;span class="nt"&gt;--from-beginning&lt;/span&gt; &lt;span class="nt"&gt;--bootstrap-server&lt;/span&gt; localhost:9092
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The --from-beginning flag tells the consumer to start reading from Offset 0. You will instantly see the messages you typed in the Producer terminal appear here. If you go back to the Producer terminal and type a new message, it will pop up in the Consumer terminal in real-time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Apache Kafka is the nervous system of modern data engineering. By sitting in the middle of your architecture, it decouples the applications that create data from the applications that need to use data.&lt;br&gt;
While it can be complex to manage at a massive scale, the core concept remains remarkably simple; Producers write events to Topics, those Topics are split into Partitions for speed, and Consumers use Offsets to read those events whenever they are ready. By leveraging Consumer Groups, Kafka ensures that data is processed efficiently, securely, and at an incredibly massive scale.&lt;/p&gt;

</description>
      <category>kafka</category>
      <category>dataengineering</category>
      <category>luxdev</category>
    </item>
    <item>
      <title>The Great Data Debate: Should You Build Your Warehouse Top-Down or Bottom-Up?</title>
      <dc:creator>Lawrence Murithi</dc:creator>
      <pubDate>Mon, 11 May 2026 16:06:03 +0000</pubDate>
      <link>https://forem.com/lawrence_murithi/the-great-data-debate-should-you-build-your-warehouse-top-down-or-bottom-up-4pbe</link>
      <guid>https://forem.com/lawrence_murithi/the-great-data-debate-should-you-build-your-warehouse-top-down-or-bottom-up-4pbe</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Imagine you have a massive, disorganized garage. You need to clean it up so you can actually find things. You have two ways to tackle this.&lt;br&gt;
The first way is to take every single item out of the garage, build a perfect, custom-sized shelving unit for the entire space, categorize every loose screw and tool into a master list, and then put everything in its exact, permanent place.&lt;br&gt;
The second way is to just clean out the corner where you keep your gardening tools because it’s spring and that’s what you need right now. Later, when winter comes, you can clean out the corner for your snow shovels.&lt;br&gt;
This is exactly how the data engineering world looks at building a Data Warehouse. The &lt;strong&gt;clean the whole garage first&lt;/strong&gt; method is the &lt;strong&gt;Inmon approach&lt;/strong&gt;. The &lt;strong&gt;clean corner by corner&lt;/strong&gt; method is the &lt;strong&gt;Kimball approach&lt;/strong&gt;.&lt;br&gt;
If your company wants to store data to make smart business decisions, you will inevitably bump into these two names; Bill Inmon and Ralph Kimball. &lt;br&gt;
This article looks at how the architectures work, the good, the bad, and which one you should actually use.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Inmon Architecture(The Top-Down Master Plan)
&lt;/h3&gt;

&lt;p&gt;Bill Inmon is often called the &lt;strong&gt;father of the data warehouse&lt;/strong&gt;. His philosophy is that a data warehouse should be the single, ultimate source of truth for the entire business.&lt;/p&gt;

&lt;h4&gt;
  
  
  How It works
&lt;/h4&gt;

&lt;p&gt;Inmon uses a top-down approach. You start by looking at the entire company, pull data from all the different software systems (sales, HR, finance) and clean it up. Then, you store all of it in one massive, highly organized central database.&lt;br&gt;
Because of this design, the Inmon approach requires that &lt;strong&gt;business requirements are defined first&lt;/strong&gt;. You must have a complete understanding of the enterprise's overarching data needs before building the model. Furthermore, it relies on &lt;strong&gt;strong governance&lt;/strong&gt;, meaning there are strict, centralized rules controlling data quality, security, and standardization across the board.&lt;br&gt;
Inmon uses a &lt;strong&gt;normalized structure&lt;/strong&gt;. This means data is stored without any duplication. If a customer's name changes, you only have to update it in one single place.&lt;br&gt;
Building a &lt;strong&gt;centralized warehouse first&lt;/strong&gt; is the core of this method. Once this giant central warehouse is built, you carve out smaller pieces of it, &lt;strong&gt;Data Marts&lt;/strong&gt;, for specific departments to use. Each department gets their own data mart, but that data mart is fed strictly by the central warehouse.&lt;/p&gt;

&lt;p&gt;Below is a flowchart showing multiple source systems feeding into a single Staging Area, flows into a large central Enterprise Data Warehouse, which then splits into smaller Data Marts pointing to the end users.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Source → ETL → Data Warehouse → Data Marts → Reports&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw8ztesp8hjuy1bsc4wjb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw8ztesp8hjuy1bsc4wjb.png" alt="Inmon approach" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Pros
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;- Single source of truth&lt;/strong&gt; - Because everything flows from one central hub, the different teams will never have conflicting numbers.&lt;br&gt;
&lt;strong&gt;- High consistency&lt;/strong&gt; - Due to strong governance and a centralized structure, definitions and metrics mean the exact same thing across the entire enterprise.&lt;br&gt;
&lt;strong&gt;- Good for large organizations&lt;/strong&gt; - The robust, highly structured foundation is capable of handling vast amounts of complex, enterprise-wide data efficiently over the long term.&lt;br&gt;
&lt;strong&gt;- Easy to update&lt;/strong&gt; - Since data isn't duplicated, updating records or fixing errors is very clean and simple.&lt;br&gt;
&lt;strong&gt;- Built for the future&lt;/strong&gt; - If the company grows or adds new departments, the foundation is already solid.&lt;/p&gt;

&lt;h4&gt;
  
  
  Cons
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;- Slow to implement&lt;/strong&gt; - Designing a perfect system for an entire enterprise takes months, sometimes years, before anyone sees real value.&lt;br&gt;
&lt;strong&gt;- It’s expensive&lt;/strong&gt; - You need highly specialized database experts and a massive upfront budget to build and maintain the central hub.&lt;br&gt;
&lt;strong&gt;- Hard for business users to read&lt;/strong&gt; - The normalized database is great for computers, but very confusing for a regular business person trying to run a report.&lt;br&gt;
&lt;strong&gt;- Hard to change&lt;/strong&gt; - Because the entire enterprise is highly integrated and normalized, pivoting the architecture to accommodate new, unforeseen business models is difficult and time-consuming.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Kimball Architecture(The Bottom-Up Quick Win)
&lt;/h3&gt;

&lt;p&gt;Ralph Kimball felt Inmon method was slow and expensive and decided to craft a better method. His philosophy is that a data warehouse &lt;strong&gt;focus on business processes&lt;/strong&gt; and answer specific business questions as quickly as possible.&lt;/p&gt;

&lt;h4&gt;
  
  
  How it works
&lt;/h4&gt;

&lt;p&gt;Kimball uses a bottom-up approach prioritized around &lt;strong&gt;fast delivery&lt;/strong&gt;. Instead of building a giant central warehouse first, you start by building individual Data Marts. &lt;br&gt;
For example, if the sales team needs a report urgently, you pull data just for the sales team, run it through ETL and build a Sales Data Mart. Then later, you build an HR Data Mart.&lt;br&gt;
Kimball uses a &lt;strong&gt;denormalized structure&lt;/strong&gt;, known as the &lt;strong&gt;Star Schema&lt;/strong&gt;. This means he doesn't care if data is duplicated. He organizes data into &lt;strong&gt;Facts&lt;/strong&gt; (numbers such as sales amount) and &lt;strong&gt;Dimensions&lt;/strong&gt; (context such as time, location, or customer name). &lt;br&gt;
Rather than being isolated silos, these individual Data Marts are eventually linked together to form an &lt;strong&gt;Integrated Warehouse&lt;/strong&gt;. To keep things from getting chaotic, Kimball uses &lt;strong&gt;conformed dimensions (an enterprise bus)&lt;/strong&gt;. This is a strict rule that says if both the Sales mart and the HR mart use a Date or a Customer, they must use the exact same definition, allowing the data marts to connect logically for company-wide reporting.&lt;/p&gt;

&lt;p&gt;Below is a flowchart showing source systems feeding into an ETL process, which builds independent Data Marts(Star Schemas) first. These marts are linked together by shared conformed dimensions to form a logical Integrated Warehouse, which is then used for End-User Reports.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Source → ETL → Data Marts → Integrated Warehouse → Reports&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8jsp6mje41b82dhyxt9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft8jsp6mje41b82dhyxt9.png" alt="Kimball" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  The Pros
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;- Faster implementation&lt;/strong&gt; - You can get a single department up and running with data in a matter of weeks, delivering immediate ROI.&lt;br&gt;
&lt;strong&gt;- Cheaper to start&lt;/strong&gt; - You don't need a massive upfront budget.&lt;br&gt;
&lt;strong&gt;- Business-friendly&lt;/strong&gt; - The Star Schema is incredibly easy for regular business users to understand. They can drag and drop fields in software like Tableau or PowerBI easily.&lt;br&gt;
&lt;strong&gt;- Flexible&lt;/strong&gt; - It is much easier to add new data marts or modify existing ones as business needs change without breaking a massive central database.&lt;/p&gt;

&lt;p&gt;The Cons:&lt;br&gt;
&lt;strong&gt;- Data duplication&lt;/strong&gt; - Because data is stored in multiple different marts, you use up more storage space.&lt;br&gt;
&lt;strong&gt;- Harder to update&lt;/strong&gt; - Because Kimball favors speed and query performance over strict organization, the same piece of data is intentionally stored in multiple places. For example, if a customer's address changes, you might have to update it in five different data marts.&lt;br&gt;
&lt;strong&gt;- Risk of inconsistency&lt;/strong&gt; - If you aren't strictly enforcing conformed dimensions, your data marts will drift apart. Because data is duplicated across different marts, sales and finance might end up reporting different total revenue numbers.&lt;br&gt;
&lt;strong&gt;- Integration challenges&lt;/strong&gt; - Because the system is built piece-by-piece rather than centrally planned from the start, tying all the disparate data marts together into a unified, integrated warehouse later on can become technically complex and messy. &lt;br&gt;
For example, if Sales mart is built in January and the HR mart in July, the teams might design their databases differently. A user trying to generate a combined report showing Sales Revenue vs. Employee Training Costs might realize that Sales measures time in Weeks, while HR measures time in Months. Trying to join the two data marts together to answer enterprise-wide questions thus becomes technologically complex.&lt;/p&gt;

&lt;h4&gt;
  
  
  Which Architecture is better?
&lt;/h4&gt;

&lt;p&gt;If you ask a room full of data engineers this question, you will probably start an argument. But realistically, neither is better. It entirely depends on what your company needs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You should use Inmon if&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You work in a highly regulated industry (like banking, insurance, or healthcare) where data accuracy and audit trails are more important than speed.&lt;/li&gt;
&lt;li&gt;You have a large budget, a big team of data engineers, and plenty of time.&lt;/li&gt;
&lt;li&gt;Your company's data is incredibly complex and changes constantly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;You should use Kimball if&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You are a startup, a retail business, or a fast-moving company that needs data right now.&lt;/li&gt;
&lt;li&gt;You want your non-technical business teams to build their own reports without asking IT for help every time.&lt;/li&gt;
&lt;li&gt;You are on a tight budget and need to prove the value of the data warehouse to your boss quickly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The Modern Reality
&lt;/h3&gt;

&lt;p&gt;It is worth mentioning that technology has changed a lot since Inmon and Kimball wrote their books in the 1990s.&lt;br&gt;
Back then, computer storage was incredibly expensive and Inmon’s method of not duplicating data saved money. &lt;br&gt;
Today, cloud storage is incredibly cheap. Because storage is cheap, many companies lean heavily toward Kimball's Star Schema because the cost of duplicating data just doesn't matter much anymore.&lt;br&gt;
Furthermore, new hybrid approaches have popped up. The &lt;strong&gt;Data Vault architecture (by Dan Linstedt)&lt;/strong&gt; is becoming very popular. It essentially takes the best of Inmon’s strict central storage and pairs it with Kimball’s easy-to-read data marts.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Bottom Line
&lt;/h2&gt;

&lt;p&gt;When it comes to building a data warehouse, don't get caught up in treating Inmon or Kimball like a religion. You aren't building a monument but a tool to help your company make money.&lt;br&gt;
If your company has the patience to build a bulletproof foundation, go top-down with Inmon. If your company needs answers tomorrow to keep the lights on, go bottom-up with Kimball. &lt;br&gt;
Pick the approach that fits your business reality, not the one that looks prettiest on a whiteboard.&lt;/p&gt;

</description>
      <category>kimball</category>
      <category>dataengineering</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Docker for Data Professionals: From Zero to Containerizing Your First Project</title>
      <dc:creator>Lawrence Murithi</dc:creator>
      <pubDate>Mon, 11 May 2026 13:39:03 +0000</pubDate>
      <link>https://forem.com/lawrence_murithi/docker-for-data-professionals-from-zero-to-containerizing-your-first-project-5ea2</link>
      <guid>https://forem.com/lawrence_murithi/docker-for-data-professionals-from-zero-to-containerizing-your-first-project-5ea2</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;If you work with data, you probably have spent hours writing a Python script, training a machine learning model or building a data pipeline. It runs perfectly on your laptop but when you send the same code to a teammate or try to run it on a company server, it instantly crashes.&lt;br&gt;
Usually, the error has nothing to do with your code. It crashes because of issues like; the other computer has a different version of Python, is missing a library like pandas, or uses a different operating system.&lt;br&gt;
Docker was created to solve this exact problem.&lt;br&gt;
This article delves into what Docker is, why data scientists and analysts should care about it, and how to use it step-by-step.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is Docker?
&lt;/h3&gt;

&lt;p&gt;Before the 1950s, global shipping was a mess. Loading and unloading a ship was a nightmare(slow and unstandardized) because contents such as barrels, sacks, cars and boxes were different shapes weights and size. &lt;br&gt;
Then, the shipping industry invented the steel shipping container. It didn't matter if you were shipping cars, coffee, or electronics, you just put your contents in a standard box. Ships, trains, and cranes were now built to handle that box.&lt;br&gt;
Docker does the exact same thing for software.&lt;br&gt;
Instead of just moving your code from one computer to another, Docker allows you to package your code, the programming language, the exact libraries you used, and the system settings into one standard box.&lt;br&gt;
Because everything your code needs is inside that box, it will run exactly the same way on your laptop, your coworker's laptop, or a cloud server.&lt;/p&gt;
&lt;h3&gt;
  
  
  Docker vs. Virtual Machines
&lt;/h3&gt;

&lt;p&gt;You might be thinking, Isn't that just a Virtual Machine(VM)?&lt;br&gt;
It’s a fair assumption, as both provide isolated environments for your applications, but Docker is fundamentally lighter and more efficient.&lt;br&gt;
A traditional VM relies on software called a &lt;strong&gt;hypervisor&lt;/strong&gt; to bundle your code and libraries with a complete, dedicated guest operating system. Booting up a whole new copy of Windows or Linux makes VMs massive, resource-heavy, and slow to start.&lt;br&gt;
However, Docker only virtualizes the application layer. It uses a background service called the &lt;strong&gt;Docker Engine&lt;/strong&gt; to share your host computer's underlying operating system. By stripping away the bulky guest OS, Docker packages only the absolute essentials; the code, runtime, and settings, into a highly portable container. This isolation guarantees your app will run reliably across any infrastructure. Docker containers also take up a fraction of the disk space and launch in mere seconds.&lt;/p&gt;
&lt;h4&gt;
  
  
  Core Docker Terminologies
&lt;/h4&gt;

&lt;p&gt;Before writing any code, it's critical to understand the basic vocabulary of the Docker ecosystem.&lt;br&gt;
&lt;strong&gt;1. Docker Engine&lt;/strong&gt; - This is the underlying background program running on your machine. It does the actual heavy lifting required to build, run and manage your containers.&lt;br&gt;
&lt;strong&gt;2. Dockerfile&lt;/strong&gt; - Think of this as a recipe. It is a plain text document that contains a step-by-step list of commands. Docker reads this file to know exactly which software to install and which files to copy to build your environment.&lt;br&gt;
&lt;strong&gt;3. Images&lt;/strong&gt; - An image is a frozen, unchangeable blueprint created by running a Dockerfile. It holds your code, tools, and system libraries in one package. Images are used to spawn active containers. Think of it as the static mold used to make identical products.&lt;br&gt;
&lt;strong&gt;4. Containers&lt;/strong&gt; - This is the live, running version of an image. A container isolates your application and its requirements from the rest of your computer, guaranteeing it behaves the exact same way no matter what machine it runs on.&lt;br&gt;
&lt;strong&gt;5. Docker Hub&lt;/strong&gt; - This is a massive online library for Docker images. Just like GitHub is used for sharing code, Docker Hub is a public platform where people can upload their own custom images or download pre-made environments to save time.&lt;br&gt;
&lt;strong&gt;6. Volumes&lt;/strong&gt; - Because containers are temporary, any data saved inside them is lost when they shut down. Volumes fix this by linking a folder inside the container to a folder securely saved on your actual hard drive, preventing data loss.&lt;br&gt;
&lt;strong&gt;7. Networks&lt;/strong&gt; - This is the system that allows multiple standalone containers to talk to each other safely. For example, a network lets a container holding your Python code securely send data to a separate container running a database.&lt;/p&gt;
&lt;h3&gt;
  
  
  Why Data Professionals Need Docker
&lt;/h3&gt;

&lt;p&gt;While Software developers have used Docker for years to run websites, it has now become a required skill for data teams because of various reasons.&lt;br&gt;
&lt;strong&gt;• Reproducibility&lt;/strong&gt; - In data science, if someone cannot reproduce your results, your results are not valid. Docker guarantees that anyone who runs your container will get the exact same output.&lt;br&gt;
&lt;strong&gt;• Easy Handoffs&lt;/strong&gt; - A Predictive model is usually handed over to a data engineer or a software team to put it into production. A Docker container would easen their work since they don't have to guess how to set up the environment. They just run it.&lt;br&gt;
&lt;strong&gt;• Working with Old Code&lt;/strong&gt; - Sometimes you need to run a script written three years ago using Python 3.6. Instead of messing up your current computer by downgrading your software, you just spin up a Docker container with the old versions, run the job, and delete it.&lt;/p&gt;
&lt;h4&gt;
  
  
  Pros of Using Docker
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Portability&lt;/strong&gt; &lt;br&gt;
Docker packages your application along with all its dependencies, libraries, and configuration files into a single image. Because the environment is locked inside this image, the application will run exactly the same way on a developer's laptop, a testing server, or in the production cloud. It eliminates the problem of "It Works on My Machine".&lt;br&gt;
&lt;strong&gt;2. Resource Efficiency&lt;/strong&gt; &lt;br&gt;
Traditional Virtual Machines (VMs) require a full, heavy guest Operating System for every application. Docker containers, however, share the host machine's OS kernel thus are incredibly lightweight, take up significantly less hard drive space, and can start up in milliseconds. You can also run many more containers on a single server than you could VMs.&lt;br&gt;
&lt;strong&gt;3. Isolation of Environments&lt;/strong&gt;&lt;br&gt;
Every container runs in its own isolated environment. This means you can have one container running an application that requires Python 2.7, and another container running an application that requires Python 3.10 on the exact same server.&lt;br&gt;
&lt;strong&gt;4. Ideal for Microservices and Scalability&lt;/strong&gt;&lt;br&gt;
Docker is the foundation for modern microservices architectures. Instead of building one massive, monolithic application, you can build small, independent services (e.g., a database container, a web server container, an authentication container). If your web traffic spikes, you can quickly spin up 10 extra web server containers without having to duplicate the database.&lt;br&gt;
&lt;strong&gt;5. Faster Deployment and CI/CD Integration&lt;/strong&gt;&lt;br&gt;
Docker images are pre-configured thus deploying them is as simple as downloading the image and pressing run. This makes Docker incredibly popular for Continuous Integration/Continuous Deployment (CI/CD) pipelines. If a new version of an app has a bug, rolling back is as easy as running the previous Docker image tag.&lt;/p&gt;
&lt;h4&gt;
  
  
  Cons of Using Docker
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. Steep Learning Curve&lt;/strong&gt;&lt;br&gt;
For beginners, Docker introduces a lot of new concepts hence takes time to become proficient. Developers have to learn how to write Dockerfiles, manage docker-compose configurations, understand container networking (how containers talk to each other), and grasp how images are built. &lt;br&gt;
&lt;strong&gt;2. Data Persistence Complexity&lt;/strong&gt;&lt;br&gt;
By design, containers are &lt;strong&gt;ephemeral (temporary)&lt;/strong&gt;. If a container is deleted or crashes, all the data inside it is permanently lost. To save data permanently (like a database), you have to learn how to manage &lt;strong&gt;Docker Volumes&lt;/strong&gt; or &lt;strong&gt;Bind Mounts&lt;/strong&gt; to connect container storage to the host machine's hard drive. &lt;br&gt;
&lt;strong&gt;3. Cross-Platform Performance and Quirks&lt;/strong&gt;&lt;br&gt;
Docker is natively a Linux technology. While Docker Desktop allows you to run it on macOS and Windows, it actually does this by running a lightweight, hidden Linux Virtual Machine in the background. This can lead to heavy RAM/CPU usage on Mac and Windows machines, and file-syncing between the host and the container can sometimes be slow.&lt;br&gt;
&lt;strong&gt;4. Security Concerns (Shared Kernel)&lt;/strong&gt;&lt;br&gt;
Because containers share the host's Operating System kernel, they are less isolated than full Virtual Machines. If a hacker finds a vulnerability in the host OS kernel, they might be able to break out of the container and access the host machine or other containers. Additionally, poorly configured containers running as the root user pose a significant security risk.&lt;br&gt;
&lt;strong&gt;5. Not Ideal for Desktop/GUI Applications&lt;/strong&gt;&lt;br&gt;
Docker is heavily optimized for backend services, APIs, databases, and command-line tools. While it is technically possible to run graphical desktop applications (GUI) inside Docker, it is highly complex, clunky, and generally not recommended.&lt;/p&gt;
&lt;h4&gt;
  
  
  First Docker Project
&lt;/h4&gt;

&lt;p&gt;Let’s build a simple data project and put it inside a Docker container.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Install Docker&lt;/strong&gt;&lt;br&gt;
Download Docker Desktop for Windows, Mac, or Linux &lt;a href="https://www.docker.com/products/docker-desktop/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. Docker Desktop is a helpful graphical interface that includes the underlying Docker Engine. Install it and open the application. It runs quietly in the background.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Set Up Your Project Files&lt;/strong&gt;&lt;br&gt;
Create a new folder on your computer e.g. myproject. Inside this folder, create three files.&lt;br&gt;
&lt;strong&gt;File 1: main.py&lt;/strong&gt;&lt;br&gt;
This is the Python script. Write a simple program that uses the pandas library to create a small dataset and print it out.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Name&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Alice&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Bob&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Charlie&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Age&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;35&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Role&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Data Analyst&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Data Engineer&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Data Scientist&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;df&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DataFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--- Team Data ---&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;df&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;File 2: requirements.txt&lt;/strong&gt;&lt;br&gt;
This file tells Python which libraries are needed. Since pandas was used, list it here.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pandas==2.1.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;File 3: Dockerfile&lt;/strong&gt;&lt;br&gt;
This is the magic file. Create a file named Dockerfile. Open it in a text editor and paste the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="c"&gt;# 1. Start with a base image pulled from Docker Hub that already has Python&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt;&lt;span class="s"&gt; python:3.10-slim&lt;/span&gt;

&lt;span class="c"&gt;# 2. Create a working directory inside the container&lt;/span&gt;
&lt;span class="k"&gt;WORKDIR&lt;/span&gt;&lt;span class="s"&gt; /app&lt;/span&gt;

&lt;span class="c"&gt;# 3. Copy our requirements file into the container&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; requirements.txt .&lt;/span&gt;

&lt;span class="c"&gt;# 4. Install the libraries listed in requirements.txt&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt

&lt;span class="c"&gt;# 5. Copy the rest of our code into the container&lt;/span&gt;
&lt;span class="k"&gt;COPY&lt;/span&gt;&lt;span class="s"&gt; main.py .&lt;/span&gt;

&lt;span class="c"&gt;# 6. Tell the container what to do when it starts&lt;/span&gt;
&lt;span class="k"&gt;CMD&lt;/span&gt;&lt;span class="s"&gt; ["python", "main.py"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3: Build the Docker Image&lt;/strong&gt;&lt;br&gt;
Now, turn those three files into a Docker Image.&lt;br&gt;
Open your computer's terminal (Command Prompt on Windows, Terminal on Mac/Linux) and navigate to the myproject folder and run the below command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker build &lt;span class="nt"&gt;-t&lt;/span&gt; my-first-data-app &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NB:&lt;/strong&gt; The period . at the end tells Docker to look for the Dockerfile in the current folder.&lt;br&gt;
&lt;strong&gt;• docker build&lt;/strong&gt; tells Docker to read the recipe.&lt;br&gt;
&lt;strong&gt;• -t my-first-data-app&lt;/strong&gt; gives the image a name (tag) so it can be easier to find it later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4: Run the Container&lt;/strong&gt;&lt;br&gt;
Once the build is finished, the image is ready and can be run using the command below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run my-first-data-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This displays the output of the Python script on the screen.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--- Team Data ---
      Name  Age            Role
0    Alice   25    Data Analyst
1      Bob   30   Data Engineer
2  Charlie   35  Data Scientist
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Image can now be sent to anyone in the world, and it would print the exact same table, even if they don't have Python installed on their computer.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Multi-Container Problem
&lt;/h3&gt;

&lt;p&gt;Running a single container is great. However, modern applications are rarely just one piece of software.&lt;br&gt;
A standard web application usually consists of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A frontend application &lt;/li&gt;
&lt;li&gt;A backend API &lt;/li&gt;
&lt;li&gt;A database &lt;/li&gt;
&lt;li&gt;A caching system &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using basic Docker commands means you have to build and run each of these containers manually, figure out how to connect them to the same network so they can talk to each other and manage their startup order. Doing this by typing long commands into the terminal every single day is frustrating and prone to human error.&lt;/p&gt;
&lt;h3&gt;
  
  
  Docker Compose
&lt;/h3&gt;

&lt;p&gt;Docker Compose is a tool designed specifically to solve the multi-container problem.&lt;br&gt;
Instead of typing a bunch of manual terminal commands, Docker Compose allows you to define your entire multi-container application in a single text file called &lt;strong&gt;docker-compose.yml&lt;/strong&gt;.&lt;br&gt;
&lt;strong&gt;YAML (Yet Another Markup Language)&lt;/strong&gt; is just a way to write configuration data in a clean, readable format using indentation.&lt;br&gt;
With Compose, you define &lt;strong&gt;services&lt;/strong&gt;. Each service represents one container in your application setup. You can define what image the service should use, what ports it should open, and how it connects to the other services.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A Practical Docker Compose Example&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# The structure of docker compose&lt;/span&gt;

&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;8080:8080"&lt;/span&gt;

  &lt;span class="na"&gt;postgres&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;postgres&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;5432:5432"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;services&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;postgres&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;postgres:latest&lt;/span&gt;
    &lt;span class="na"&gt;container_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;postgres&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;POSTGRES_USER&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;postgres&lt;/span&gt;
      &lt;span class="na"&gt;POSTGRES_PASSWORD&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12345&lt;/span&gt;
      &lt;span class="na"&gt;POSTGRES_DB&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;postgres&lt;/span&gt;
    &lt;span class="na"&gt;ports&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;5433:5432"&lt;/span&gt;
    &lt;span class="na"&gt;healthcheck&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CMD-SHELL"&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;pg_isready&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;-U&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;postgres"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
      &lt;span class="na"&gt;interval&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;15s&lt;/span&gt;
      &lt;span class="na"&gt;timeout&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;10s&lt;/span&gt;
      &lt;span class="na"&gt;retries&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;

  &lt;span class="na"&gt;etl&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;.&lt;/span&gt;
    &lt;span class="na"&gt;container_name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;etl&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;DB_USER&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;postgres&lt;/span&gt;
      &lt;span class="na"&gt;DB_PASSWORD&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12345&lt;/span&gt;
      &lt;span class="na"&gt;DB_HOST&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;postgres&lt;/span&gt;
      &lt;span class="na"&gt;DB_PORT&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5432&lt;/span&gt;
      &lt;span class="na"&gt;DB_NAME&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;postgres&lt;/span&gt;
    &lt;span class="na"&gt;depends_on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;postgres&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;condition&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;service_healthy&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break it down.&lt;br&gt;
&lt;strong&gt;services&lt;/strong&gt; - We have two services defined; postgres (the database) and etl (the process interacting with the database).&lt;br&gt;
&lt;strong&gt;image&lt;/strong&gt; - For the postgres service, we are not building our own image. We are downloading the official postgres:latest image directly from Docker Hub.&lt;br&gt;
&lt;strong&gt;container_name&lt;/strong&gt; - Explicitly sets the names of the running containers to postgres and etl instead of letting Docker auto-generate random names.&lt;br&gt;
&lt;strong&gt;environment&lt;/strong&gt; - This passes variables (like passwords and database names) into the containers. The etl service's DB_HOST is simply postgres. Docker Compose automatically creates a network so the etl container can talk to the database using its service name.&lt;br&gt;
&lt;strong&gt;ports&lt;/strong&gt; - Maps port 5433 on your host machine to port 5432 inside the postgres container. This allows you to connect to the database from outside of Docker using port 5433.&lt;br&gt;
&lt;strong&gt;healthcheck&lt;/strong&gt; - Tells Docker how to test if the postgres database is actually ready to accept connections. It runs the command pg_isready every 15 seconds, waiting up to 10 seconds for a response, and will try 5 times before failing.&lt;br&gt;
&lt;strong&gt;build&lt;/strong&gt; - For the etl service, we tell Compose to look in the current folder (.) for a Dockerfile and build the image from scratch.&lt;br&gt;
&lt;strong&gt;depends_on&lt;/strong&gt; - This tells Docker not to start the etl service until the postgres container is fully up and has successfully passed its healthcheck (condition: service_healthy).&lt;/p&gt;

&lt;p&gt;Once you have written the above file, you can start your entire application; the database, the custom network, and the backend with just one command as below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker-compose up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you are done working and want to shut everything down and clean up the network, you type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker-compose down
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Using Docker Volumes for Data
&lt;/h3&gt;

&lt;p&gt;Volumes persist data outside of the container's lifecycle. Why is this important for data professionals?&lt;br&gt;
In the example above, we packed our Python script directly into the container. But what if you are processing a 10-gigabyte CSV file? You do not want to pack a massive data file inside your Docker image. Images are supposed to be lightweight. Furthermore, if your code generates a cleaned CSV, and the container stops running, that new file will be lost forever.&lt;br&gt;
A Volume fixes this by acting as a bridge between your actual computer and the container.&lt;br&gt;
Imagine you have a folder called data on your laptop, and you want your Docker container to read a file inside it. You would run your container like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-v&lt;/span&gt; /path/to/your/local/data:/app/data my-first-data-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The -v command maps a folder on your computer to a folder inside the container. Now, your Python script can read heavy datasets and save output files directly to your laptop, without making the Docker image bloated.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Docker is an incredibly powerful tool that has revolutionized software engineering by making apps fast, portable, and scalable. However, for a very simple, static website or a solo developer building a basic script, adding Docker might introduce unnecessary complexity and overhead.&lt;br&gt;
If you want to start using Docker in your daily data work, ensure to follow these rules.&lt;br&gt;
&lt;strong&gt;1. Use official base images&lt;/strong&gt; - When writing a Dockerfile, always start with an official image from Docker Hub like python:3.10-slim or jupyter notebook. They are secure and well-maintained.&lt;br&gt;
&lt;strong&gt;2. Keep it small&lt;/strong&gt; - Use versions of Linux that have &lt;strong&gt;slim&lt;/strong&gt; or &lt;strong&gt;alpine&lt;/strong&gt; in the name. They take up less space on your hard drive.&lt;br&gt;
&lt;strong&gt;3. Pin your versions&lt;/strong&gt; - Always use a requirements.txt file and specify the exact version of the library you used (e.g., scikit-learn==1.3.0). If you just write scikit-learn, Docker will download the newest version, which might break your code.&lt;br&gt;
&lt;strong&gt;4. Don't put passwords in Dockerfiles&lt;/strong&gt; - If your script connects to a database, never hardcode your password into the script or the Dockerfile. Use environment variables instead.&lt;br&gt;
&lt;strong&gt;5. Level up with Docker Compose&lt;/strong&gt; - Once you are comfortable running a single container, look into Docker Compose. While Docker commands handle individual containers, Docker Compose allows you to define and manage multi-container applications. By writing a single docker-compose.yml file, you can seamlessly utilize Networks to connect multiple containers e.g. running Python script in one container and a PostgreSQL database in another and spin them all up with just one simple command (docker-compose up).&lt;br&gt;
Mastering Docker could save you hundreds of hours of debugging. Once you learn how to containerize your data projects, "it works on my machine" will be a phrase you never have to say again.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>dataengineering</category>
      <category>luxdev</category>
    </item>
    <item>
      <title>Folders, Apartments, and Fake Computers: A Guide to Virtual Environments, Docker, and VMs</title>
      <dc:creator>Lawrence Murithi</dc:creator>
      <pubDate>Thu, 07 May 2026 12:23:35 +0000</pubDate>
      <link>https://forem.com/lawrence_murithi/folders-apartments-and-fake-computers-a-guide-to-virtual-environments-docker-and-vms-503d</link>
      <guid>https://forem.com/lawrence_murithi/folders-apartments-and-fake-computers-a-guide-to-virtual-environments-docker-and-vms-503d</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;If you have been spending a substantial amount of time writing code, you must have run into a frustrating problem: "It works on my computer, but it doesn't work on yours."&lt;br&gt;
This happens because computers are set up differently. You might have a different operating system, a different version of a programming language, or different background software running. When a website or app breaks because of this, developers can lose hours or even days trying to figure out what the problem is.&lt;br&gt;
To solve this, developers came up with ways to isolate software. Instead of installing an app directly onto your main computer, you put it inside a &lt;strong&gt;protective bubble&lt;/strong&gt;. This bubble tricks the software into thinking it has its own private space, with exactly what it needs to run, so it won't mess with the rest of your system.&lt;br&gt;
There are three main tools we use to create these bubbles; &lt;strong&gt;Virtual Environments&lt;/strong&gt;, &lt;strong&gt;Virtual Machines (VMs)&lt;/strong&gt; and &lt;strong&gt;Docker&lt;/strong&gt;. While they all aim to solve similar problems, they do it in completely different ways, using completely different layers of your computer. &lt;br&gt;
Let's break down exactly what each one is, how they compare and when you should use them.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Virtual Environments
&lt;/h3&gt;

&lt;p&gt;A Virtual Environment is a localized directory that contains a specific version of a programming language and the specific software packages required for a project. It is the simplest and lightest way to isolate a project and is most commonly used in Python (using tools like venv or virtualenv) although similar concepts exist in other languages.&lt;/p&gt;

&lt;h4&gt;
  
  
  How Virtual Environments work
&lt;/h4&gt;

&lt;p&gt;A Virtual Environment provides no system-level isolation. It does not share hardware, nor does it isolate the OS. It simply changes the PATH variables in your terminal so that when you install a package or run a script, it uses the isolated folder instead of the computer's global system files.&lt;br&gt;
Imagine you are building two different websites on your laptop. Website A is older and needs version 2.0 of a web framework like Django. Website B is brand new and needs version 4.0 of that exact same framework. If you install these tools directly onto your main computer system, they will conflict and one of your websites will stop working.&lt;br&gt;
A virtual environment fixes this by creating a dedicated, private folder for your project. When you turn on(activate) the virtual, it temporarily rewrites your computer's internal GPS, known as the system PATH. Because of this, your computer temporarily ignores its main, global list of tools. Instead, it only looks at the tools installed inside that specific project folder.&lt;/p&gt;

&lt;h4&gt;
  
  
  Pros
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;• Extremely fast&lt;/strong&gt; - Creating and starting a virtual environment takes less than a second because it is just moving some folders around.&lt;br&gt;
&lt;strong&gt;• Lightweight&lt;/strong&gt; - It only takes up a few megabytes of space on your hard drive. There is no heavy software running in the background.&lt;br&gt;
&lt;strong&gt;• Simple to use&lt;/strong&gt; - Usually, it just takes one or two simple commands in your terminal to get started and shut down.&lt;br&gt;
&lt;strong&gt;• No dependency conflicts&lt;/strong&gt; - it solves the problem of dependency conflicts between different projects&lt;/p&gt;

&lt;h4&gt;
  
  
  Cons
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;• Weak isolation&lt;/strong&gt; - It only isolates programming packages (like Python libraries). It does not isolate the operating system, the system clock, or your hardware settings.&lt;br&gt;
&lt;strong&gt;• "It works on my machine" can still happen&lt;/strong&gt; - Because the isolation is weak, hidden problems can sometimes slip through. If your code secretly relies on a specific font or a hidden system tool installed on your Mac, and you send your virtual environment code to a friend on a Windows PC, the code might still break.&lt;/p&gt;

&lt;p&gt;Virtual environments are used on local computer on day to day coding when working on multiple projects using the same programming language but want to keep their dependencies separate from one another.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Virtual Machines (VMs)
&lt;/h3&gt;

&lt;p&gt;A Virtual Machine is a complete software emulation of a physical computer. It runs its own full Operating System (Guest OS) entirely separate from the host computer's Operating System. It is the heaviest, most complete, and oldest form of isolation. Software like VirtualBox, VMware, or Microsoft Hyper-V allows you to do this.&lt;/p&gt;

&lt;h4&gt;
  
  
  How Virtual Machines work
&lt;/h4&gt;

&lt;p&gt;If a virtual environment is like putting your code in a separate folder, a Virtual Machine is like buying an entirely new physical computer, shrinking it down, and putting it inside your current computer.&lt;br&gt;
It uses a piece of software called a &lt;strong&gt;Hypervisor&lt;/strong&gt;(like VMware, VirtualBox, or Hyper-V). The hypervisor carves out a specific amount of your physical computer's RAM, CPU, and storage and dedicates it to the VM. You then install a full Operating System (like Windows or Ubuntu) onto that carved-out space. This new system is called the &lt;strong&gt;Guest OS&lt;/strong&gt; which operates/behaves like a real computer while the main computer is called the &lt;strong&gt;Host&lt;/strong&gt;. &lt;/p&gt;

&lt;h4&gt;
  
  
  Pros
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;• Complete isolation&lt;/strong&gt; - What happens inside a VM stays inside a VM. Because the hypervisor locks the hardware, if a VM gets infected with a severe virus, your main host computer is almost always completely safe.&lt;br&gt;
&lt;strong&gt;• Run different operating systems&lt;/strong&gt; - You can run a full Windows computer inside a Mac, or a Linux computer inside Windows, allowing you to use software made for different platforms.&lt;br&gt;
&lt;strong&gt;• Highly secure&lt;/strong&gt; - Because the hardware is strictly separated at a deep level, it is trusted by banks, governments, and massive corporations for highly sensitive tasks.&lt;/p&gt;

&lt;h4&gt;
  
  
  Cons
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;• Massive resource hog&lt;/strong&gt; - Since you are running a second operating system on top of your current one, VMs eat up a lot of RAM, CPU power, and battery life. Even if the VM is just sitting idle, it is still running background updates, managing a clock, and keeping a digital desktop alive hence wasting power.&lt;br&gt;
&lt;strong&gt;• Huge files&lt;/strong&gt; - A VM can easily take up 20 to 100 gigabytes of storage space just to hold the basic operating system files.&lt;br&gt;
&lt;strong&gt;• Slow&lt;/strong&gt; - Booting up a VM takes just as long as turning on a physical computer, and moving files in and out of it can be tedious.&lt;/p&gt;

&lt;p&gt;VMs are used in large corporate cloud servers or on a local machine when strict security is needed. Its critical when you need to test software on a completely different operating system, or when a business is running older, legacy applications that require an outdated OS to survive.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Docker (Containers)
&lt;/h3&gt;

&lt;p&gt;Docker is a platform that uses &lt;strong&gt;containerization&lt;/strong&gt; to package an application and all its necessary dependencies (libraries, frameworks, etc.) into a single, standardized unit called a &lt;strong&gt;container&lt;/strong&gt;. Containers are the clever middle ground between the lightness of a Virtual Environment and the strict, heavy isolation of a Virtual Machine.&lt;/p&gt;

&lt;h4&gt;
  
  
  How docker work
&lt;/h4&gt;

&lt;p&gt;Every operating system is made of two main parts; the &lt;strong&gt;core engine (Kernel)&lt;/strong&gt;, which physically tells your RAM and CPU what to do, and the &lt;strong&gt;user files/tools&lt;/strong&gt; that make up the desktop experience you see on screen.&lt;br&gt;
While a Virtual Machine duplicates both parts making it so heavy, Docker only duplicates the user files and tools. All Docker containers share the main host computer's Kernel.&lt;br&gt;
Think of it like an apartment building. A Virtual Machine is like giving everyone their own separate house with their own separate plumbing and electricity. Docker is like an apartment complex where everyone has their own locked, private room(container) and can decorate however they want, but they all share the building's central plumbing and electrical systems hidden in the walls(Host OS Kernel).&lt;/p&gt;

&lt;p&gt;To use Docker, you write a simple text file called a &lt;strong&gt;Dockerfile&lt;/strong&gt;. It reads like a recipe; Start with a bare-bones version of Linux, set up some default database passwords, download the latest PostgreSQL and start the database server. Docker reads this file and packages it into a container. This container can be handed to anyone, and it will run exactly the same way, regardless of what computer they have.&lt;/p&gt;

&lt;h4&gt;
  
  
  Pros
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;• Consistent everywhere&lt;/strong&gt; - It solves the "it works on my machine" problem perfectly. A Docker container behaves exactly the same on a Mac, a Windows PC or a cloud server because the environment inside the container never changes.&lt;br&gt;
&lt;strong&gt;• Fast and lightweight&lt;/strong&gt;  - Because they don't boot up a full operating system kernel, containers start in seconds and usually only take up a few hundred megabytes of space.&lt;br&gt;
&lt;strong&gt;• Easy to share and scale&lt;/strong&gt; - You can run dozens or even hundreds of containers on the same computer without them fighting over resources. This allows developers to build microservices. Instead of building one massive app, you put the shopping cart in one container, the user login in another, and the payment system in a third. If the payment container crashes, the rest of the website stays up.&lt;/p&gt;

&lt;h4&gt;
  
  
  Cons
&lt;/h4&gt;

&lt;p&gt;• &lt;strong&gt;Steeper learning curve&lt;/strong&gt; - You have to learn Docker-specific terminal commands, how to write Dockerfiles and how networking works to let containers talk to each other.&lt;br&gt;
&lt;strong&gt;• OS limitations&lt;/strong&gt; - Because Docker shares the host's kernel, you generally run Linux containers on Linux machines. Although Linux can run containers on Mac and Windows, Docker usually installs a tiny, hidden Linux Virtual Machine in the background to provide the Linux Kernel making Docker slightly heavier on Mac and Windows than it is on native Linux.&lt;br&gt;
&lt;strong&gt;• Less secure than VMs&lt;/strong&gt; - Because containers share the host kernel, the wall between them is thinner hence a critical vulnerability in the host OS could potentially affect all containers.&lt;/p&gt;

&lt;p&gt;Docker is used almost everywhere. On a developer's laptop, in automated testing environments, and in production running live websites on the open internet. Its used when building modern web applications, working with a team of developers who all use different computers, or breaking a large app down into smaller microservices.&lt;br&gt;
It gives developer's an isolated, highly reliable environment that is identical across all machines, without wasting your computer's RAM and hard drive space.&lt;/p&gt;

&lt;h4&gt;
  
  
  Similarities between the tools
&lt;/h4&gt;

&lt;p&gt;The core similarity between all three is the concept of isolation. &lt;br&gt;
They all exist to create boundaries between projects and software. &lt;br&gt;
They also all make it easier to delete a project without leaving junk files behind; you just delete the virtual environment folder, the VM file, or the container image, and everything associated with that project is instantly gone, leaving your main computer perfectly clean.&lt;br&gt;
Most times, they are often used together in the real world. A large company might run a giant Virtual Machine in the cloud to provide security, put Docker inside that Virtual Machine to manage different web apps easily, and a developer might use a Virtual Environment inside that Docker container to organize their Python code.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Major Differences
&lt;/h4&gt;

&lt;p&gt;The difference lies in how much they isolate and how heavy they are.&lt;br&gt;
&lt;strong&gt;• Virtual Environment (Lightest)&lt;/strong&gt; - Isolates only the language packages but relies entirely on your computer for everything else.&lt;br&gt;
&lt;strong&gt;• Docker (Middle)&lt;/strong&gt; - Isolates the application and the operating system files, but shares the core OS engine (the kernel) to save power and speed.&lt;br&gt;
&lt;strong&gt;• Virtual Machine (Heaviest)&lt;/strong&gt; - Isolates absolutely everything. It clones the physical hardware and runs a 100% separate operating system, taking up a lot of space and power to provide maximum security.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flryewh0u6iuk0nrvd682.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flryewh0u6iuk0nrvd682.png" alt="Isolation tools" width="800" height="712"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;If you are just writing a quick Python script to scrape a website, analyze some data, and need to install a few libraries without breaking your computer, use a Virtual Environment.&lt;br&gt;
If you are building a web app, working with a database, collaborating with other developers, and need to make sure your code runs exactly the same way on your laptop as it will on your company's live servers, use Docker.&lt;br&gt;
If you are on a Mac but absolutely need to run a piece of Windows-only enterprise software, or you are testing dangerous malware and need maximum security to protect your real computer, use a Virtual Machine.&lt;/p&gt;

</description>
      <category>docker</category>
      <category>virtualmachine</category>
      <category>virtualenvironment</category>
      <category>dataengineering</category>
    </item>
    <item>
      <title>The Medallion Architecture: Turning Messy Data into Business Gold</title>
      <dc:creator>Lawrence Murithi</dc:creator>
      <pubDate>Wed, 06 May 2026 16:06:09 +0000</pubDate>
      <link>https://forem.com/lawrence_murithi/the-medallion-architecture-turning-messy-data-into-business-gold-2blm</link>
      <guid>https://forem.com/lawrence_murithi/the-medallion-architecture-turning-messy-data-into-business-gold-2blm</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Imagine drawing water from a muddy river. You would never scoop a glass of water from the bank and drink it straight down. You would want that water pumped into a treatment plant, filtered to remove the debris, and chemically purified until it is crystal clear and safe to consume.&lt;br&gt;
Data requires the exact same treatment.&lt;br&gt;
Ever seen raw data pulled directly from a company’s servers? It's usually a complete mess. Website logs, sales applications, customer service chatbots, and payment gateways all generate endless streams of information. If you take all that raw information, dump it into a single pile, and try to build a revenue report, the results will be a disaster. Your numbers will be wrong, your system will crawl to a halt, and nobody will trust the data.&lt;br&gt;
To process this information safely, data engineers build systems with specific &lt;strong&gt;layers&lt;/strong&gt; that clean and organize records step-by-step. Historically, this was done using traditional data warehouse layers. Today, a modern framework called the &lt;strong&gt;Medallion Architecture&lt;/strong&gt; has taken over the industry.&lt;br&gt;
Here is a deep dive into how data layers work, why the Medallion concept was invented, and how it refines digital mud into a clear, single source of truth.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Old Way(Traditional Data Warehouse Layers)
&lt;/h3&gt;

&lt;p&gt;Before the Medallion Architecture existed, engineers used a classic three-step method to move data from external software into a company dashboard.&lt;br&gt;
To elaborate on the traditional Data Warehouse architecture, it is essential to ground the concepts in the frameworks introduced by &lt;strong&gt;W.H. Inmon&lt;/strong&gt; (often called the &lt;strong&gt;father of the data warehouse&lt;/strong&gt;) and &lt;strong&gt;Ralph Kimball&lt;/strong&gt;.&lt;br&gt;
Historically known as the Three-Tier Enterprise Data Warehouse (EDW) Architecture, this system was designed to separate &lt;strong&gt;operational systems&lt;/strong&gt; (where data is created) from &lt;strong&gt;analytical systems&lt;/strong&gt; (where data is analyzed).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The Staging Layer(The Transient Extraction Zone)&lt;/strong&gt;&lt;br&gt;
This was the receiving dock. The staging area is defined as a temporary, intermediate storage zone between operational data sources (ODS) and the data warehouse. &lt;br&gt;
Data from a shopify store or a salesforce database was copied and temporarily dropped here. The main goal was speed; get the data out of the live application quickly so the app wouldn't slow down for regular users.&lt;/p&gt;

&lt;h4&gt;
  
  
  Attributes of staging layer
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Decoupling OLTP and OLAP&lt;/strong&gt; - The primary architectural goal of this layer is to isolate Online Transaction Processing (OLTP) systems (like Salesforce or Shopify) from Online Analytical Processing (OLAP) workloads. Analytical queries are highly &lt;strong&gt;resource-intensive&lt;/strong&gt;; running them directly on a live database can cause catastrophic latency for end-users.&lt;br&gt;
&lt;strong&gt;Extraction Mechanics&lt;/strong&gt; - Data is pulled into this layer using methodologies such as &lt;strong&gt;batch processing&lt;/strong&gt; or &lt;strong&gt;Change Data Capture (CDC)&lt;/strong&gt;. The data here is typically stored in its raw, native format.&lt;br&gt;
&lt;strong&gt;Volatility&lt;/strong&gt; - According to traditional DWH design principles, data in the staging layer is transient. Once the data is successfully moved to the next tier, it is generally purged or overwritten in the next batch cycle to conserve expensive storage space.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The Integration Layer (The Core Enterprise Data Warehouse)&lt;/strong&gt;&lt;br&gt;
This is where the heavy lifting happened. Engineers wrote scripts to clean the data and match up records.&lt;br&gt;
This layer represents what W.H. Inmon famously defined as the subject-oriented, integrated, time-variant, and non-volatile collection of data in support of management's decision-making process.&lt;br&gt;
 If your billing system called a customer Client_001 and your website called them User_001, the Integration layer linked them together into a central, highly structured database.&lt;/p&gt;

&lt;h4&gt;
  
  
  Attributes of integration layer
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Semantic Reconciliation&lt;/strong&gt; - The heavy lifting is known as semantic reconciliation and &lt;strong&gt;Master Data Management&lt;/strong&gt; (MDM). Engineers must resolve heterogeneous data formats (e.g., merging Client_001 from an Oracle database and User_001 from a JSON web log) into a unified entity.&lt;br&gt;
&lt;strong&gt;Data Cleansing and Normalization&lt;/strong&gt; - In this layer, data undergoes rigorous cleansing (handling null values, standardizing date formats). Structurally, Inmon advocated for storing this data in the Third Normal Form (3NF). This highly normalized structure reduces data redundancy and ensures mathematical consistency across the enterprise, creating a &lt;strong&gt;Single Version of Truth (SVOT)&lt;/strong&gt;.&lt;br&gt;
&lt;strong&gt;The Bottleneck&lt;/strong&gt; - Because of the complex normalization rules, writing data into this layer requires highly complex, tightly coupled SQL scripts, making the Integration Layer notoriously slow to update or modify.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. The Presentation Layer(Data Marts and Dimensional Modeling)&lt;/strong&gt;&lt;br&gt;
The highly normalized 3NF data in the Integration layer is too complex for business users to query efficiently, therefore, data must be reshaped for consumption. Engineers would pre-package specific tables for specific teams e.g. creating a Marketing Table or a Sales Table that connected easily to dashboard software.&lt;/p&gt;

&lt;h4&gt;
  
  
  Attributes of presentation layer
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;The Data Mart&lt;/strong&gt; - The Presentation layer is composed of subsets of the data warehouse focused on a specific business unit also called Data Marts (e.g., Sales, HR, Marketing).&lt;br&gt;
&lt;strong&gt;Dimensional Modeling (The Kimball Method)&lt;/strong&gt; - In this layer, engineers apply Ralph Kimball’s dimensional modeling techniques, organizing data into &lt;strong&gt;Star Schemas&lt;/strong&gt; or &lt;strong&gt;Snowflake Schemas&lt;/strong&gt;. Data is divided into &lt;strong&gt;Facts&lt;/strong&gt; (measurable, quantitative data e.g sales amount) and &lt;strong&gt;Dimensions&lt;/strong&gt; (descriptive attributes e.g time, store, or customer).&lt;br&gt;
&lt;strong&gt;Optimized for Read-Heavy Workloads&lt;/strong&gt; - By pre-joining and denormalizing the data, this layer allows Business Intelligence tools like PowerBI to execute complex analytical queries rapidly without requiring end-users to understand underlying SQL structures.&lt;/p&gt;

&lt;h4&gt;
  
  
  The Problem with the Old Way
&lt;/h4&gt;

&lt;p&gt;This system relied heavily on a process called ETL (Extract, Transform, Load). Engineers would extract the data, transform/clean it and then load it into the warehouse. The fatal flaw was that the raw data was often discarded after it was cleaned to save storage space. If a data engineer accidentally deleted a crucial column during the clean phase, that historical data was gone forever.&lt;br&gt;
&lt;strong&gt;1. The Schema-on-Write Constraint&lt;/strong&gt;&lt;br&gt;
Traditional DWHs operated on a &lt;strong&gt;Schema-on-Write&lt;/strong&gt; paradigm. This means that before data could be loaded into the warehouse, the warehouse's schema (tables, columns, data types) had to be rigidly defined. If a new column was added to the source software, the ETL pipeline would fail, or simply drop the unrecognized data, until an engineer manually updated the database schema.&lt;br&gt;
&lt;strong&gt;2. Destructive Transformations and Storage Costs&lt;/strong&gt;&lt;br&gt;
On-premise relational database storage such as Teradata or Oracle appliances used to be very expensive. To save disk space, raw data was deemed expendable. Data was extracted, transformed to fit the strict schema, and the raw source data was then discarded.&lt;br&gt;
This model had some downsides which included:&lt;br&gt;
      &lt;strong&gt;• Loss of Auditability and Lineage&lt;/strong&gt; - If a transformation logic error occurred (e.g., a script incorrectly rounded up financial figures), there was no historical raw data to refer back to since the original data was permanently lost.&lt;br&gt;
        &lt;strong&gt;• Lack of Flexibility for Machine Learning&lt;/strong&gt; - Modern Data Science requires massive amounts of raw, unstructured or semi-structured data to train machine learning models. The traditional integration layer stripped away the granular, raw anomalies that data scientists actually need, leaving only highly aggregated, structured data.&lt;br&gt;
As a result of the flaw which resulted to loss of raw data and rigidity of ETL paved the way for Data Lakes, there was a shift from ETL to ELT(where cheap cloud storage allows raw data to be stored before transformation), and ultimately the modern Medallion Architecture (Bronze, Silver, Gold), which preserves raw data while still providing structured analytics.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Modern Shift(The Medallion Architecture)
&lt;/h3&gt;

&lt;p&gt;As cloud storage became incredibly cheap, companies stopped throwing away their raw data and began dumping everything into massive, cheap storage areas(Data Lakes).&lt;br&gt;
Eventually, companies pioneered the Lakehouses which combined the cheap, infinite storage of a Data Lake with the strict organization of a traditional Data Warehouse.&lt;br&gt;
The need to help companies organize the massive amounts of data inside a Lakehouse therefore gave birth to the Medallion Architecture. &lt;br&gt;
The Medallion Architecture separates data into three specific stages; &lt;strong&gt;Bronze&lt;/strong&gt;, &lt;strong&gt;Silver&lt;/strong&gt;, and &lt;strong&gt;Gold&lt;/strong&gt;. It mimics the logical flow of the traditional layers but fundamentally changes how data is treated, preserved, and upgraded.&lt;/p&gt;

&lt;h4&gt;
  
  
  How do the three layers work?
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;1. The Bronze Layer(The Raw Zone)&lt;/strong&gt;&lt;br&gt;
This is where all the raw data lands from the various sources.&lt;br&gt;
The data is saved exactly as it arrived. You do not fix typos. You do not rename columns. You just capture it.&lt;/p&gt;

&lt;h4&gt;
  
  
  Features of bronze layer
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;• Safety and Troubleshooting&lt;/strong&gt; - since the raw data is completely untouched, you never have to worry about accidentally destroying information. If an engineer writes a bad piece of code that ruins the data in the later layers, they can simply go back to the Bronze layer and restart the process.&lt;br&gt;
&lt;strong&gt;• Historical Archive&lt;/strong&gt; - The Bronze layer acts as an infinite, permanent record of everything that ever happened in the business. It is usually &lt;strong&gt;append-only&lt;/strong&gt;, meaning new records are just added to the pile without overwriting old records.&lt;br&gt;
&lt;strong&gt;• Speed&lt;/strong&gt; - Getting data into the Bronze layer is fast since the computer isn't doing any complex math, translations or cleaning. Engineers often use tools called &lt;strong&gt;Change Data Capture (CDC)&lt;/strong&gt; to stream this raw data in real-time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The Silver Layer(The Cleaned Zone)&lt;/strong&gt;&lt;br&gt;
Once the data is safely locked away in the Bronze layer, it is copied and moved into the Silver layer. The goal of the Silver layer is to create a &lt;strong&gt;Single Source of Truth&lt;/strong&gt; for the entire enterprise.&lt;/p&gt;

&lt;h4&gt;
  
  
  What happens here?
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;• Cleaning and Standardization&lt;/strong&gt; - Engineers fix the formatting. For example, if one source system writes dates as DD-MM-YYYY and another writes MM-DD-YYYY, the Silver layer standardizes all into one standard format.&lt;br&gt;
• &lt;strong&gt;Filtering and Quarantining&lt;/strong&gt; - Junk data is handled here. If a user accidentally enters an age like 999, the system spots it and instead of deleting it, engineers push that bad record into a separate quarantine table so it doesn't ruin the main data set, but can still be investigated later.&lt;br&gt;
&lt;strong&gt;• Deduplication&lt;/strong&gt; - Sometimes, source systems can glitch and send the same receipt twice. The Silver layer strips out duplicates so every row is unique.&lt;br&gt;
&lt;strong&gt;• Joining&lt;/strong&gt; - Data from different tables is connected using relationships. A log of customer purchases is joined with a product inventory table so that you can see exactly what item was bought, not just a random product ID number.&lt;br&gt;
&lt;strong&gt;• Security&lt;/strong&gt; - This is where sensitive information (like passwords, social security numbers, or personal emails) is scrambled or hidden so that analysts using the data later on cannot see private customer details.&lt;/p&gt;

&lt;p&gt;Data scientists and analysts spend a lot of time in the Silver layer. It is clean and trustworthy, but it is still highly detailed. Every single individual action is visible, which makes it the perfect place to look for hidden trends or train machine learning models.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. The Gold Layer(The Action Zone)&lt;/strong&gt;&lt;br&gt;
The Gold layer is the final destination. The data here is no longer meant for deep exploration but is designed to answer specific business questions immediately.&lt;/p&gt;

&lt;h4&gt;
  
  
  What happens here?
&lt;/h4&gt;

&lt;p&gt;In the Silver layer, you might have a table with ten million individual rows. If a user tries to load the rows into a dashboard, the software will freeze. However, in the Gold layer, those millions of rows are turned into highly summarized, bite-sized metrics.&lt;br&gt;
&lt;strong&gt;• Aggregations&lt;/strong&gt; - Instead of listing every single sale, engineers create a Gold table that simply shows Total Sales per Store per Day.&lt;br&gt;
&lt;strong&gt;• Business Logic&lt;/strong&gt; - This is where specific company rules live. If your marketing team defines an active subscriber as someone who has opened an email in the last 30 days, that exact mathematical rule is applied to a Gold table.&lt;br&gt;
&lt;strong&gt;• Performance&lt;/strong&gt; - Data loads instantly since it's heavily summarized and simplified using Star Schema layout. When you connect any Business Intelligence tools to the Gold layer, the charts populate immediately.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why the Medallion Architecture Wins
&lt;/h3&gt;

&lt;p&gt;The reason nearly every modern data team is adopting this structure is because it solves the biggest headaches that have plagued developers for decades.&lt;br&gt;
&lt;strong&gt;1. Bulletproof Data Lineage&lt;/strong&gt;&lt;br&gt;
When an executive looks at a Gold dashboard and sees that monthly revenue dropped by 50%, panic sets in. The data team needs to find out if the business is actually failing, or if the system is just broken. &lt;br&gt;
With this architecture, they can trace the flow backward. They check the rules in the Gold layer. If those are correct, they look at the cleaned data in the Silver layer. If that looks fine, they check the raw files in the Bronze layer.&lt;br&gt;
&lt;strong&gt;2. Extreme Flexibility&lt;/strong&gt;&lt;br&gt;
If the finance department suddenly requests a completely new way to calculate annual growth, the data team doesn't have to panic. They do not have to go back to the original software sources, and they do not have to re-clean everything. They simply build a new Gold table on top of the already clean Silver data.&lt;br&gt;
&lt;strong&gt;3. System Reliability (ACID Transactions)&lt;/strong&gt;&lt;br&gt;
Modern Medallion architectures are built on specialized table formats like &lt;strong&gt;Delta Lake&lt;/strong&gt; or &lt;strong&gt;Apache Iceberg&lt;/strong&gt; which support ACID transactions. That means if a server crashes halfway through moving data from Silver to Gold, it won't leave you with a half-finished, corrupted table. The system will automatically roll back to the last safe state, preventing bad data from leaking into executive reports.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;If you want to remember how the Medallion Architecture functions, just remember these three phrases:&lt;br&gt;
Bronze -Here is everything we found(Messy, huge, exact copies).&lt;br&gt;
Silver -Here is what actually happened (Clean, standardized, truthful).&lt;br&gt;
Gold - Here is what we should do about it (Summarized, fast, ready for action).&lt;br&gt;
The Foundation of Trust&lt;br&gt;
A data platform is only as useful as the trust people put into it. If employees constantly find missing numbers, broken charts, or conflicting reports, they will abandon the dashboards and go back to guessing.&lt;br&gt;
The Medallion Architecture is much more than a way to organize servers; it is a framework for building organizational trust. By moving information systematically through the Bronze, Silver, and Gold layers, a company guarantees that every digital footprint is captured securely, cleaned relentlessly, and presented flawlessly. Just like turning muddy water into something safe to drink, the Medallion Architecture takes the chaos of raw information and refines it into the exact clarity a business needs to survive.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>luxdev</category>
      <category>dataengineering</category>
      <category>warehouse</category>
    </item>
    <item>
      <title>Transactional Power Vs Analytical Precision: The Essential Guide to OLTP and OLAP</title>
      <dc:creator>Lawrence Murithi</dc:creator>
      <pubDate>Fri, 01 May 2026 19:58:49 +0000</pubDate>
      <link>https://forem.com/lawrence_murithi/transactional-power-vs-analytical-precision-the-essential-guide-to-oltp-and-olap-2nfe</link>
      <guid>https://forem.com/lawrence_murithi/transactional-power-vs-analytical-precision-the-essential-guide-to-oltp-and-olap-2nfe</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Behind every digital interaction is a fundamental divide in how data is handled. The system required to process your grocery checkout with lightning speed is radically different from the system a corporation uses to analyze a decade of sales growth. This is the core distinction between &lt;strong&gt;Transactional Power&lt;/strong&gt; vs. &lt;strong&gt;Analytical Precision&lt;/strong&gt;. To understand the backbone of modern technology, you must understand &lt;strong&gt;OLTP (Online Transactional Processing)&lt;/strong&gt; and &lt;strong&gt;OLAP (Online Analytical Processing)&lt;/strong&gt;. &lt;br&gt;
Though they sound like technical jargon, they are simple concepts that define how businesses operate and grow. &lt;br&gt;
This article serves as your roadmap to understanding how these systems function, their unique strengths, and why the balance between them is the secret to data-driven success.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OLTP(Online Transaction Processing): Handling the Day-to-Day&lt;/strong&gt;&lt;br&gt;
OLTP is the engine that runs traditional databases. It is designed to manage everyday business operations and process thousands of short, fast interactions per second. It is the system that handles the daily, minute-by-minute work of a business. Whenever a specific action or transaction takes place, OLTP is the system taking care of it.&lt;br&gt;
In a database, a transaction is any small unit of work such as changing your password. &lt;br&gt;
Transaction systems follow important rules called &lt;strong&gt;ACID properties&lt;/strong&gt;.&lt;br&gt;
ACID Properties are a set of four fundamental principles that guarantee reliable database transactions. They ensure data integrity and accuracy, preventing corruption even during system failures or concurrent operations. &lt;br&gt;
The four principles are:&lt;br&gt;
&lt;strong&gt;Atomicity(All-or-Nothing)&lt;/strong&gt; - A transaction is treated as a single unit, it either fully completes or entirely fails and rolls back.&lt;br&gt;
&lt;strong&gt;Consistency(Data Integrity)&lt;/strong&gt; - A transaction ensures the database moves from one valid state to another, adhering to all constraints and rules. That means data remains valid before and after transaction&lt;br&gt;
&lt;strong&gt;Isolation(Concurrent Control)&lt;/strong&gt; - Concurrent transactions are isolated from each other, ensuring they don’t interfere with each other.&lt;br&gt;
&lt;strong&gt;Durability(Permanent Data)&lt;/strong&gt; - Once a transaction is committed, its changes are permanently saved and will survive system failures or crashes.&lt;/p&gt;

&lt;h4&gt;
  
  
  Examples of OLTP in real life
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Adding an item to your online shopping cart.&lt;/li&gt;
&lt;li&gt;Booking an airline ticket.&lt;/li&gt;
&lt;li&gt;Sending a text message.&lt;/li&gt;
&lt;li&gt;Banking systems (Mpesa, ATM transactions)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Think of OLTP like the cashier at a busy grocery store. The cashier’s job is to scan items quickly, take your money, hand you a receipt, and move on to the next person.&lt;/p&gt;

&lt;h3&gt;
  
  
  How OLTP Works
&lt;/h3&gt;

&lt;p&gt;OLTP systems prioritize speed and accuracy. They use a design concept called &lt;strong&gt;normalization&lt;/strong&gt;. This means the database organizes data into many small tables to avoid saving the same piece of information twice. Because the data is spread out neatly, the system can insert a new record, update a row, or delete a piece of data almost instantly.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;

&lt;p&gt;Imagine you want to withdraw $50 from an ATM. The bank's OLTP system immediately checks your balance, approves the withdrawal, and updates your account to show $50 less. This has to happen in seconds, and it has to be 100% accurate so you cannot overdraw your account.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key features of OLTP
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;• Low latency/Fast response time&lt;/strong&gt; - When you swipe your card, you expect it to be approved in seconds. OLTP databases are built to respond instantly.&lt;br&gt;
&lt;strong&gt;• High number of users&lt;/strong&gt; - The system ensures that thousands of users can access the same row in a database without failure.&lt;br&gt;
&lt;strong&gt;• Normalized Data&lt;/strong&gt; - Databases are typically highly normalized to reduce redundancy and ensure fast data entry. A single OLTP transaction does not require much data. &lt;br&gt;
&lt;strong&gt;• Real-time processing/Accuracy&lt;/strong&gt; - If you transfer $50 from your current account to your savings account, the system must subtract $50 from one and add $50 to the other. If the system crashes halfway through, the OLTP system cancels the whole thing so your data does not get corrupted. OLTP systems are built to be perfectly accurate and fail-safe.&lt;br&gt;
&lt;strong&gt;• Write-heavy operations&lt;/strong&gt; - Thousands of users might be doing things at the exact same time, the system is therefore constantly writing, updating or deleting information to the database.&lt;br&gt;
&lt;strong&gt;• Highly available&lt;/strong&gt; - Because OLTP systems handle the immediate, day-to-day operations of a business, the system is designed to be online, working, and accessible virtually 100% of the time thus downtime is not an option. &lt;br&gt;
OLTP systems are usually built with backup servers and fail-safes. If one server crashes, another one instantly takes over so the customer doesn't notice a glitch.&lt;/p&gt;

&lt;h4&gt;
  
  
  Pros of OLTP
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;• Efficiency in Data Entry&lt;/strong&gt; - Highly optimized for adding, modifying, or deleting records.&lt;br&gt;
&lt;strong&gt;• Data Integrity&lt;/strong&gt; - High reliability due to ACID compliance.&lt;br&gt;
&lt;strong&gt;• Availability&lt;/strong&gt; - Designed for 24/7 uptime for business-critical applications.&lt;/p&gt;

&lt;h4&gt;
  
  
  Cons of OLTP
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;• Inefficient for complex Analysis&lt;/strong&gt; - If you ask an OLTP database to calculate the average sales of a product over the last five years, it will have to scan millions of everyday records. This takes a lot of computing power and can slow down the system for people trying to use it for normal tasks.&lt;br&gt;
&lt;strong&gt;• Limited History&lt;/strong&gt; - To keep things fast, OLTP systems usually only hold current or recent data. Old data is often moved somewhere else to save space.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OLAP (Online Analytical Processing)&lt;/strong&gt;&lt;br&gt;
OLAP is the engine behind data warehouses. If OLTP is the system for doing things, OLAP is the system for analyzing things. While OLTP only looks at a tiny slice of data at a time, OLAP is the brains used for strategic planning since its designed for data mining, processing huge amounts of information to find patterns, trends and summaries as well as complex reporting. Managers, data scientists, and business owners use OLAP to spot trends, build reports and make big decisions. &lt;/p&gt;

&lt;h4&gt;
  
  
  Making Sense of OLAP
&lt;/h4&gt;

&lt;p&gt;Think of OLAP as the manager in the back office of the grocery store. They aren't ringing up customers. They are sitting at a desk, looking at charts and graphs of past sales to decide if they need to order more apples for next week.&lt;/p&gt;

&lt;h4&gt;
  
  
  How OLAP Works
&lt;/h4&gt;

&lt;p&gt;OLAP systems are not built to process quick, small updates. To make this faster, OLAP uses &lt;strong&gt;denormalization&lt;/strong&gt;. Instead of spreading data across many tiny tables like OLTP, OLAP groups massive amounts of related data together into large tables. This takes up more storage space, but it means the system can read through billions of records very quickly to find patterns.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key features of OLAP
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;• Read-heavy operations&lt;/strong&gt; - Unlike OLTP, which is constantly writing new data (new orders, new users), OLAP mostly just reads old data. It looks at what already happened.&lt;br&gt;
&lt;strong&gt;• Complex Queries&lt;/strong&gt; - OLAP tasks involve complex math—adding, averaging, and grouping massive lists of numbers.&lt;br&gt;
&lt;strong&gt;• Multidimensional Analysis&lt;/strong&gt; - Users can slice and dice data (e.g. viewing sales by region, then by month, then by product category) using data cubes.&lt;br&gt;
&lt;strong&gt;• Denormalized Data&lt;/strong&gt; - Databases often use Star or Snowflake schemas to reduce the number of table joins needed for queries.&lt;br&gt;
&lt;strong&gt;• Slower response time&lt;/strong&gt; - While nobody wants to wait all day, an OLAP report might take a few minutes or even a few hours to run. This usually is not a concern since the person waiting is usually a business manager, not a customer standing at a checkout counter.&lt;/p&gt;

&lt;h4&gt;
  
  
  Pros of OLAP
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;• Handles Massive Data&lt;/strong&gt; - It can easily process millions or billions of rows of historical data.&lt;br&gt;
&lt;strong&gt;• Does Not Disrupt the Business&lt;/strong&gt; - Because OLAP lives in a data warehouse, running a massive, heavy report will not slow down the cash registers running on the OLTP database.&lt;br&gt;
&lt;strong&gt;• High Performance for Reporting&lt;/strong&gt; - Optimized for complex analytical queries.&lt;br&gt;
&lt;strong&gt;• Strategic Insights&lt;/strong&gt; - Allows businesses to identify trends, patterns, and anomalies to drive decision-making.&lt;br&gt;
&lt;strong&gt;• User-Friendly&lt;/strong&gt;: The system is often integrated with Business Intelligence tools like PowerBI for visualization.&lt;/p&gt;

&lt;h4&gt;
  
  
  Cons of OLAP
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;• Data is Not Real-Time&lt;/strong&gt; - OLAP systems are usually updated in batches, often overnight. If you look at an OLAP report at 2:00 PM, it usually only includes data up until the night before.&lt;br&gt;
&lt;strong&gt;• Slow to Update&lt;/strong&gt; - Adding new data to an OLAP system takes time because the data has to be heavily organized and formatted before it is saved.&lt;br&gt;
&lt;strong&gt;• Expensive and Complex&lt;/strong&gt; - Building and maintaining a data warehouse requires specialized engineers and large amounts of server storage.&lt;br&gt;
&lt;strong&gt;• Latency&lt;/strong&gt; - Queries can take seconds, minutes, or even hours because of the massive volume of data being scanned.&lt;/p&gt;

&lt;h4&gt;
  
  
  Example
&lt;/h4&gt;

&lt;p&gt;A regional manager for a coffee shop chain wants to know, "Between hot chocolate or dark roast coffee, which sold better on rainy days last year?" To answer this, the system has to look at weather data, sales data from fifty stores and a whole year of dates. An OLAP system can pull this specific report together without breaking a sweat.&lt;/p&gt;

&lt;h4&gt;
  
  
  Examples of OLAP in real life
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Netflix figuring out what genres of movies are most popular in different countries during the summer.&lt;/li&gt;
&lt;li&gt;A hospital analyzing patient records over ten years to see if a specific treatment is working.

&lt;ul&gt;
&lt;li&gt;A retail store deciding how much inventory to buy for Black Friday based on the last three years of sales.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h4&gt;
  
  
  Common OLAP Operations
&lt;/h4&gt;

&lt;p&gt;OLAP systems organize massive amounts of data into multi-dimensional structures, often referred to as &lt;strong&gt;OLAP cubes&lt;/strong&gt;. These cubes allow users to view business metrics from any angle. To explore, analyze, and make sense of this complex data, OLAP systems support several powerful analytical operations.&lt;/p&gt;

&lt;p&gt;Here is a detailed look at the five core OLAP operations:&lt;br&gt;
&lt;strong&gt;1. Roll-Up (Consolidation)&lt;/strong&gt;&lt;br&gt;
Roll-up is also known as consolidation or aggregation and involves summarizing data to a higher, more generalized level. This operation reduces the detail of the data by climbing up a concept hierarchy or by removing a dimension entirely. It is primarily used by upper management to view macro-level business trends.&lt;br&gt;
It uses mathematical functions—such as summing, averaging or counting to group smaller data points into larger, overarching categories.&lt;br&gt;
&lt;strong&gt;Example (Time Hierarchy)&lt;/strong&gt; &lt;br&gt;
Daily sales → Monthly sales → Yearly sales.&lt;/p&gt;

&lt;p&gt;If a company has millions of records of individual daily transactions, viewing them all at once can be overwhelming. Using a roll-up operation, an executive can consolidate these daily records to see total sales by month, and then roll up again to see the total gross revenue for the entire year.&lt;br&gt;
&lt;strong&gt;Business Value&lt;/strong&gt; - Roll-up provides a big picture view of business performance, stripping away unnecessary granular details to highlight overarching trends.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Drill-Down&lt;/strong&gt;&lt;br&gt;
Drill-down is the exact opposite of roll-up. It involves navigating from highly summarized, macro-level data down to highly detailed, micro-level data. This is done by stepping down a concept hierarchy or by adding a new dimension to the dataset.&lt;br&gt;
It breaks a larger aggregated number into the smaller components that make it up, allowing analysts to uncover the root causes behind a specific metric.&lt;br&gt;
&lt;strong&gt;Example (Geography &amp;amp; Time Hierarchy)&lt;/strong&gt;&lt;br&gt;
Yearly sales → Monthly sales → Daily sales (or Country → Region → Individual Store).&lt;/p&gt;

&lt;p&gt;Imagine an annual report shows that total yearly sales are significantly lower than expected. A manager can drill down from the yearly view to the monthly view and discover in what specific month sales plummeted. They can then drill down further into the month's daily sales to find which specific week caused the drop.&lt;br&gt;
&lt;strong&gt;Business Value&lt;/strong&gt; - It is essential for root-cause analysis, troubleshooting anomalies, and investigating sudden spikes or drops in performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Slice&lt;/strong&gt;&lt;br&gt;
The slice operation performs a selection on one specific dimension of the OLAP cube, resulting in a new, smaller slice of the data. &lt;br&gt;
Think of it like slicing a single piece of bread from a whole loaf. It locks one variable in place so you can analyze the rest of the data in a two-dimensional table.&lt;br&gt;
You isolate a single value within one dimension (e.g., Time, Geography, or Product) while keeping the other dimensions open.&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt; &lt;br&gt;
Show sale records for Nairobi city only.&lt;/p&gt;

&lt;p&gt;If a data cube contains sales data across Products, Time, and Cities, applying a slice on the City dimension for Nairobi isolates that market. The resulting view will show the sales of all products over all time periods, but exclusively for Nairobi location.&lt;br&gt;
&lt;strong&gt;Business Value&lt;/strong&gt; - It allows regional managers, department heads or specific product owners to filter out irrelevant data and focus entirely on the one area of the business they are responsible for.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Dice&lt;/strong&gt;&lt;br&gt;
While a slice filters data based on a single condition, a dice operation isolates a highly specific sub-cube by applying multiple filters across two or more dimensions simultaneously. &lt;br&gt;
Think of it like cutting a smaller block out of a larger block of cheese.&lt;br&gt;
It selects specific ranges or values across multiple dimensions to create a highly targeted subset of the original data.&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt; &lt;br&gt;
Show laptop sales in Nairobi and Mombasa during January and February.&lt;/p&gt;

&lt;p&gt;Here, the user is applying filters across three separate dimensions, Product Dimension(Laptops only), Geography Dimension(Nairobi and Mombasa only) and Time Dimension(January and February only).&lt;br&gt;
&lt;strong&gt;Business Value&lt;/strong&gt; - Dicing is used for highly specialized, multi-faceted analysis. It allows data scientists and marketers to look at exact intersections of data, such as evaluating the success of a specific winter promotion for a specific tech product in key coastal cities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Pivot (Rotate)&lt;/strong&gt;&lt;br&gt;
Pivot, sometimes called rotation, does not filter or change the underlying data, instead, it changes the visual perspective. It rotates the data axes to provide an alternative presentation, making different relationships easier to spot.&lt;br&gt;
It rearranges the layout of the data, typically by swapping rows and columns, or by moving a dimension from the background into the foreground.&lt;br&gt;
&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
Swapping Products and Time periods.&lt;/p&gt;

&lt;p&gt;A manager might be looking at a table where Products (Laptops, Phones, Tablets) are listed in the rows and Months (January, February, March) are the columns. By pivoting the data, they can make Months the rows and Products the columns.&lt;br&gt;
&lt;strong&gt;Business Value&lt;/strong&gt; - Different layouts highlight different trends. A pivot makes it easier to compare data side-by-side depending on what the analyst is trying to prove, ensuring the final report is as readable and impactful as possible.&lt;br&gt;
&lt;strong&gt;NB:&lt;/strong&gt; OLAP is not mainly about recording what is happening right now. It is about understanding what has happened and what it means.&lt;/p&gt;

&lt;h3&gt;
  
  
  OLTP vs. OLAP
&lt;/h3&gt;

&lt;p&gt;The distinction between OLTP (Online Transaction Processing) and OLAP (Online Analytical Processing) boils down to two distinct phases of business; &lt;strong&gt;execution&lt;/strong&gt; and &lt;strong&gt;strategy&lt;/strong&gt;. Simply put, OLTP runs the business, while OLAP analyzes the business.&lt;br&gt;
These two systems are designed for fundamentally different jobs. Understanding how they differ and how they work together comes down to understanding their relationship with time, purpose, and data architecture.&lt;/p&gt;

&lt;p&gt;Here is a detailed comparison of how the two systems operate.&lt;br&gt;
&lt;strong&gt;1. Main Purpose and System Goals&lt;/strong&gt;&lt;br&gt;
OLTP - Its primary objective is to handle daily business operations and execute transactions seamlessly. Its core focus is on accuracy, transaction safety, and ensuring the day-to-day business continues without interruption.&lt;br&gt;
OLAP - Its primary objective is to extract valuable insights from data to help leadership make smart, strategic decisions. Instead of facilitating transactions, it focuses on reporting, identifying long-term trends, and planning for the future.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The User Profiles&lt;/strong&gt;&lt;br&gt;
OLTP - These systems are used by everyday customers, cashiers, front-line staff, and mobile applications. These are the people actively interacting with the business in real-time buying items, logging into portals or booking appointments.&lt;br&gt;
OLAP - These systems are utilized by business analysts, managers, and corporate executives. These users interact with data using dashboards, Business Intelligence reports and complex spreadsheets to evaluate business performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Data State and Architectural Design&lt;/strong&gt;&lt;br&gt;
OLTP - Data is current, real-time, and highly operational. Since the data is constantly changing, the database is highly normalized to ensure efficiency and eliminate data redundancy. It is optimized to handle a constant stream of inserting, updating, and deleting small bits of data.&lt;br&gt;
OLAP - Data is historical, static, and rarely changes. It consists of summarized data spanning months or years. Because the goal is fast analysis rather than fast updates, the database is often denormalized allowing the system to efficiently read millions of rows of data at once without altering them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Query Dynamics and Performance Needs&lt;/strong&gt;&lt;br&gt;
OLTP - Queries are short, simple, and require incredibly fast response times per transaction. They generally touch only a few records at a time.&lt;br&gt;
&lt;strong&gt;Example Query&lt;/strong&gt; - Update bread's price to $10, What is John's email address? or Update a specific customer's order.&lt;br&gt;
OLAP - Queries are heavy, long, and highly complex. While speed is still important, the system is built to process massive analytical workloads rather than split-second individual actions.&lt;br&gt;
&lt;strong&gt;Example Query&lt;/strong&gt; - What is the average age of customers who bought bread in November of 2022? or Show the global sales trends broken down by region over the past 5 years.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Real-World Examples&lt;/strong&gt;&lt;br&gt;
OLTP Systems - ATMs, retail checkout registers, airline booking systems, and e-commerce shopping carts.&lt;br&gt;
OLAP Systems - Corporate data dashboards, annual financial reports, and Business Intelligence (BI) platforms.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Synergy(How OLTP and OLAP Work Together)
&lt;/h3&gt;

&lt;p&gt;A successful business relies on a symbiotic relationship between both systems. You cannot accurately analyze a business if you do not have an OLTP system reliably recording the daily sales. Conversely, you cannot grow a business if you lack an OLAP system to look back at your history and determine what strategies are actually working.&lt;/p&gt;

&lt;p&gt;So, how does the two systems connect? &lt;br&gt;
They are linked through a pipeline process known as &lt;strong&gt;ETL (Extract, Transform, Load)&lt;/strong&gt;.&lt;br&gt;
Every day, the OLTP database handles the rapid work of serving customers and processing transactions. At the end of the day, usually in the night when customer traffic and system strain are at their lowest, an automated batch script runs.&lt;br&gt;
Extract - The script pulls a copy of the day's newly generated operational data from the OLTP database.&lt;br&gt;
Transform - It cleans, formats, and aggregates that raw data to ensure it is properly structured for analysis.&lt;br&gt;
Load - Finally, the script deposits that formatted data into the OLAP data warehouse.&lt;br&gt;
By the time the business analysts and executives log into their dashboards the next morning, the OLAP warehouse is fully updated with yesterday's finalized numbers. The data is now perfectly prepped to be searched, graphed, and studied.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Bottom Line
&lt;/h3&gt;

&lt;p&gt;The difference between OLTP and OLAP simply comes down to time. While OLTP handles the exact moment a transaction occurs, OLAP handles months or years of historical data that the transactions leaves behind. Together, they allow a business to operate today while intelligently planning for tomorrow.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Every time you interact with a screen, you are leaving a digital footprint. Databases are the safe spaces that hold those footprints. OLTP ensures daily transactions are fast and secure. Data warehouses collect all those footprints over time. Finally, OLAP helps businesses look at the giant trail of footprints to figure out where they should step next.&lt;br&gt;
These tools might be invisible, but they are the engine running modern business, keeping our digital lives fast, organized, and constantly improving.&lt;/p&gt;

</description>
      <category>luxdev</category>
      <category>dataengineering</category>
      <category>olap</category>
    </item>
    <item>
      <title>From Tables to Tides: Navigating Databases, Warehouses, Marts, Lakes, and the Lakehouse Revolution</title>
      <dc:creator>Lawrence Murithi</dc:creator>
      <pubDate>Fri, 01 May 2026 17:13:47 +0000</pubDate>
      <link>https://forem.com/lawrence_murithi/the-data-behind-your-screen-a-simple-guide-to-databases-data-warehouses-oltp-and-olap-1bj</link>
      <guid>https://forem.com/lawrence_murithi/the-data-behind-your-screen-a-simple-guide-to-databases-data-warehouses-oltp-and-olap-1bj</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Every time you buy a coffee with a card, "like" a post on social media, withdraw money from an ATM or buy a shirt online, you are interacting with a database. Behind the scenes of every app and website, data is constantly being created, moved, stored and read.&lt;br&gt;
However, not all data storage is the same. The way a system stores your checkout items at a grocery store is very different from the way that same grocery chain analyzes ten years of sales trends.&lt;br&gt;
To understand how modern software handles data, we need to look at the main types of storage; &lt;strong&gt;traditional databases&lt;/strong&gt;, &lt;strong&gt;data warehouses&lt;/strong&gt;, &lt;strong&gt;data marts&lt;/strong&gt;, &lt;strong&gt;data lakes&lt;/strong&gt; and &lt;strong&gt;lake houses&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
If you are not a computer guru, these terms might sound very technical but they are not as complex as they sound. But once you break them down, they make perfect sense. &lt;br&gt;
This article gives a simple but detailed breakdown of what these are, how they work, and why software relies on both.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Basics of Data Storage
&lt;/h3&gt;

&lt;p&gt;In today's data-driven world, organizations generate massive amounts of information. To effectively store, manage, and analyze this data, businesses use different architectural models based on their specific needs. &lt;br&gt;
Before we look at the specific processing types, it helps to understand the physical or virtual places where data lives.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The Database (The Daily Worker/Operational Engine)&lt;/strong&gt;&lt;br&gt;
Think of how you keep track of your personal budget. You might use a spreadsheet. A spreadsheet is great for one person looking at a few hundred rows of information. Now imagine a company like Amazon trying to use a spreadsheet to track millions of orders happening every minute. The spreadsheet would freeze and crash instantly.&lt;br&gt;
A database is like a highly advanced, incredibly secure digital filing cabinet built to store massive amounts of information without crashing. Databases are primarily designed for &lt;strong&gt;OLTP (Online Transactional Processing)&lt;/strong&gt;. They are the workhorses that power day-to-day operations, such as processing bank transactions, managing inventory, or storing user profiles. Its main job is to quickly record new information, update existing information, and allow users to quickly look up specific details. More importantly, it is organized so that users can find exactly what they are looking for in a fraction of a second.&lt;br&gt;
Information in a standard database is usually organized into tables with rows and columns. For example, an online store might have one table for Customers, one for Products, and one for Orders. The database connects these tables so the system knows exactly which customer bought which product. Think of a traditional database like a busy cash register. It needs to be fast, accurate, and handle hundreds of transactions at once without freezing.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Characteristics of a Database
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;ACID Compliance&lt;/strong&gt; – Traditional relational databases follow strict rules (Atomicity, Consistency, Isolation, Durability) to ensure that transactions are processed reliably and that data remains accurate even in the event of a system crash.&lt;br&gt;
&lt;strong&gt;Normalized Structure&lt;/strong&gt; – Data is organized into tables to reduce redundancy. For example, a customer’s address is stored in one place rather than being repeated for every order they place.&lt;br&gt;
&lt;strong&gt;Real-Time Interaction&lt;/strong&gt; – Databases are designed to handle thousands of concurrent users making small, rapid changes to the data simultaneously.&lt;/p&gt;

&lt;h4&gt;
  
  
  Types of Databases
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Relational (SQL)&lt;/strong&gt; - Uses tables with rows and columns (e.g., MySQL, PostgreSQL, Oracle). Ideal for structured data where relationships are clearly defined.&lt;br&gt;
&lt;strong&gt;Non-Relational (NoSQL)&lt;/strong&gt; - Uses flexible structures like documents or graphs (e.g., MongoDB, Cassandra). Ideal for rapidly changing data types and massive scaling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The Data Warehouse (The Long-Term Archive/Analytical Hub)&lt;/strong&gt;&lt;br&gt;
As a business runs, over time, its database fills up with millions of past transactions. After a few years, a company manager might want to know, "Which of our stores sold the most winter coats in December over the last five years?"&lt;br&gt;
For the database to answer that question, it has to dig through millions of old records thus it slows down. This causes the system to freeze hence people trying to buy things on the website at that moment cannot check out.&lt;br&gt;
Using the grocery store analogy, a store manager walking up to a cashier who has a long line of customers and asking them to calculate the store's total profit for the last decade would cause a crisis and bring the whole store to a halt. To fix this, companies build &lt;strong&gt;Data Warehouses&lt;/strong&gt;.&lt;br&gt;
A data warehouse is a massive storage system designed to hold historical data from many different sources. It aggregates data from various sources such as different operational databases, CRM systems and flat files to provide a comprehensive, historical view of the entire organization. Periodically, usually in the night, the company copies all the new data from these sources and dumps it into the data warehouse.&lt;br&gt;
From the previous example, if the database is the cash register, the data warehouse is the company's central filing room. A data warehouse takes the daily receipts from all the different cash registers, organizes them and stores them for years. &lt;br&gt;
The data warehouse acts as the company's long-term memory. It doesn't handle everyday customer actions. Instead, it is a quiet, organized space where business analysts can run massive queries and reports without interrupting the live website. &lt;br&gt;
Data warehouses utilize &lt;strong&gt;OLAP (Online Analytical Processing)&lt;/strong&gt;. Instead of focusing on individual transactions, they are optimized to scan millions of rows to find trends, averages and insights.&lt;/p&gt;

&lt;h4&gt;
  
  
  The ETL Process (The Warehouse Engine)
&lt;/h4&gt;

&lt;p&gt;Before data enters a warehouse, it must undergo &lt;strong&gt;ETL&lt;/strong&gt; (Extract, Transform, Load).&lt;br&gt;
Extract - Pulling data from multiple, often messy, source systems.&lt;br&gt;
Transform - Cleaning, deduplicating, and formatting the data into a standardized structure.&lt;br&gt;
Load - Moving the clean data into the warehouse.&lt;br&gt;
This is known as &lt;strong&gt;Schema-on-Write&lt;/strong&gt;, meaning the structure of the data must be defined and validated before it can be stored.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Benefits of a Data Warehouse
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Data Integration&lt;/strong&gt; – It breaks down data silos by combining information from marketing, sales, and finance into one single source of truth.&lt;br&gt;
&lt;strong&gt;Historical Context&lt;/strong&gt; – While databases often only show current data, warehouses store years of historical records, allowing for year-over-year comparisons.&lt;br&gt;
&lt;strong&gt;Optimized for Performance&lt;/strong&gt; – Warehouses often use columnar storage, which allows them to perform complex calculations such as, What was the total revenue for 2023?, significantly faster than a standard database.&lt;br&gt;
&lt;strong&gt;High Quality &amp;amp; Accuracy&lt;/strong&gt; – Because data is cleaned during the ETL process, business leaders can trust that the reports they generate are based on accurate, non-conflicting information.&lt;br&gt;
Why use a Data Warehouse?&lt;br&gt;
&lt;strong&gt;NB:&lt;/strong&gt; A data warehouse is the foundation for Business Intelligence. It allows executives to run complex What if? scenarios and generate reports that inform long-term strategy. It also ensures that the operational databases are not slowed down by heavy analytical queries.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Data Marts(The Departmental Lens)&lt;/strong&gt;&lt;br&gt;
A data mart is a highly focused, specialized subset of a data warehouse designed to serve the specific needs of a single department or business unit.&lt;br&gt;
While a traditional Data Warehouse acts as a massive, centralized repository containing all of an organization's structured data, a data mart isolates only the information relevant to a specific team.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Benefits of a Data Mart
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Enhanced Performance&lt;/strong&gt; - Because the data mart is smaller and queries are highly specific, reports and dashboards load much faster.&lt;br&gt;
&lt;strong&gt;Improved Security&lt;/strong&gt; - By isolating data, companies can strictly control who has access to sensitive departmental information &lt;br&gt;
&lt;strong&gt;Ease of Use&lt;/strong&gt; - Business users and analysts do not have to sift through irrelevant enterprise data to find what they need.&lt;br&gt;
Data marts can be &lt;strong&gt;Dependent&lt;/strong&gt; (built by drawing data from an existing enterprise data warehouse) or &lt;strong&gt;Independent&lt;/strong&gt; (built directly from operational systems).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Data Lakes(The Raw Data Reservoir)&lt;/strong&gt;&lt;br&gt;
A data lake is a massive, highly scalable storage system designed to hold vast amounts of raw, unprocessed data in its native format.&lt;br&gt;
Unlike a data warehouse, which requires data to be cleaned, transformed, and structured into strict tables before it can be stored(Schema-on-Write), a data lake stores data exactly as it is generated, assigning structure only when the data is eventually read or queried (Schema-on-Read).&lt;/p&gt;

&lt;h5&gt;
  
  
  Data Lakes store?
&lt;/h5&gt;

&lt;p&gt;&lt;em&gt;Structured Data&lt;/em&gt; - Traditional tables and relational databases.&lt;br&gt;
&lt;em&gt;Semi-Structured Data&lt;/em&gt; - JSON files, XML, CSVs, and server logs.&lt;br&gt;
&lt;em&gt;Unstructured Data&lt;/em&gt; - Emails, documents, PDFs.&lt;br&gt;
&lt;em&gt;Binary/Media Data&lt;/em&gt; - Images, audio files, and videos.&lt;br&gt;
&lt;em&gt;Streaming Data&lt;/em&gt; - Real-time IoT sensor data and website clickstreams.&lt;/p&gt;

&lt;h5&gt;
  
  
  Why use a Data Lake?
&lt;/h5&gt;

&lt;p&gt;A data lake is ideal when an organization wants to capture and retain everything, even data they don't immediately need. It is highly cost-effective because it utilizes cheap cloud storage. Furthermore, having raw, unmanipulated data is essential for training artificial intelligence (AI) and complex Machine Learning (ML) models.&lt;br&gt;
&lt;strong&gt;NB:&lt;/strong&gt; Without proper organization and governance, a data lake can become a messy, unsearchable &lt;strong&gt;Data Swamp&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Data Lakehouse(The Modern Hybrid)&lt;/strong&gt;&lt;br&gt;
For years, companies had to maintain a two-tier architecture; a Data Lake for raw data and machine learning, and a separate Data Warehouse for clean data and business reporting. This resulted in expensive storage costs, data duplication, and complex maintenance.&lt;br&gt;
A Data Lakehouse is a modern architectural design that merges the best concepts of both systems. It is built directly on top of cheap data lake storage, but it applies the organizational structures, management tools, and performance speeds of a data warehouse.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Features of a Lakehouse
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Flexibility &amp;amp; Scale&lt;/strong&gt; - Like a data lake, it can store massive amounts of structured, semi-structured, and unstructured data.&lt;br&gt;
&lt;strong&gt;Reliability &amp;amp; Structure&lt;/strong&gt; - Like a data warehouse, it supports ACID transactions (meaning data is reliable, updates don't break the system, and multiple people can read/write simultaneously).&lt;br&gt;
&lt;strong&gt;Single Source of Truth&lt;/strong&gt; - Teams no longer have to copy data from the lake to the warehouse. Business analysts can build BI dashboards, and data scientists can run machine learning models directly on the exact same data platform.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary of the Storage systems
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2a89psyc3zhg2niiz8xm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2a89psyc3zhg2niiz8xm.png" alt="storage" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2b995bwwvxr923luvsn4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2b995bwwvxr923luvsn4.png" alt="Data storage" width="800" height="989"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Bottom Line
&lt;/h3&gt;

&lt;p&gt;In today's modern economy, data is a company’s most valuable asset. However, data only provides value if it can be accessed, analyzed, and trusted. By understanding the distinctions between these storage methods, organizations can build a robust infrastructure that avoids the Data Swamp, reduces operational costs, and ultimately turns raw information into a competitive advantage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Choosing the right data storage architecture is no longer about finding a one-size-fits-all solution but matching the right tool to the specific needs of the business. As organizations evolve from simple record-keeping to complex artificial intelligence and real-time analytics, their data strategy must also mature.&lt;br&gt;
For Day-to-Day Operations, Database remains the essential engine, ensuring that transactions are processed accurately and instantly.&lt;br&gt;
For Strategic Reporting, Data Warehouse and its specialized Data Marts provide the single source of truth needed for executive decision-making and departmental efficiency.&lt;br&gt;
For Big Data &amp;amp; Innovation, Data Lake serves as the vital reservoir for raw information, fueling the next generation of Machine Learning and AI development.&lt;br&gt;
For the Future of Scalability, Data Lakehouse represents the ultimate convergence, offering the best of all worlds; the speed of a warehouse with the massive flexibility of a lake.&lt;/p&gt;

</description>
      <category>datawarehousing</category>
      <category>luxdev</category>
      <category>dataengineering</category>
      <category>database</category>
    </item>
    <item>
      <title>Apache Airflow for Beginners: DAGs, Tasks, Operators, and Scheduling Explained</title>
      <dc:creator>Lawrence Murithi</dc:creator>
      <pubDate>Wed, 29 Apr 2026 20:24:12 +0000</pubDate>
      <link>https://forem.com/lawrence_murithi/apache-airflow-for-beginners-dags-tasks-operators-and-scheduling-explained-p2d</link>
      <guid>https://forem.com/lawrence_murithi/apache-airflow-for-beginners-dags-tasks-operators-and-scheduling-explained-p2d</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Being a beginner in data engineering can seem very scary. People use technical words like ETL, pipelines, data warehouses, architecture, orchestration etc. At that point, it is very easy to feel like you need a computer science degree just to understand what they mean. However, most of these terms are just technical but not as complicated as they sound. &lt;br&gt;
Data engineering, in simple terms, involves extracting data from a place such as websites, social media pages, excel/csv files or payment systems etc, cleaning it, and storing it somewhere (database, data warehouse or data lake). If you need this done once, you can run a simple Python script. However, if the job must run every hour, every day, or every week, you need a tool that can manage it for you. That's where Apache Airflow comes in.&lt;/p&gt;
&lt;h3&gt;
  
  
  What is Apache Airflow?
&lt;/h3&gt;

&lt;p&gt;To understand Apache Airflow, think about a process like baking a cake. You do not just throw everything into the oven. You follow steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Buy the ingredients&lt;/li&gt;
&lt;li&gt;Prepare the dough&lt;/li&gt;
&lt;li&gt;Put the dough in the oven&lt;/li&gt;
&lt;li&gt;Bake the cake&lt;/li&gt;
&lt;li&gt;Let it cool&lt;/li&gt;
&lt;li&gt;Add frosting&lt;/li&gt;
&lt;li&gt;Serve the cake&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some steps must happen before others. You cannot frost the cake before baking it. You cannot bake the cake before preparing the dough. You also need to know how long each step should take and what to do if something goes wrong. &lt;br&gt;
This kind of process is called a &lt;strong&gt;workflow&lt;/strong&gt; or &lt;strong&gt;pipeline&lt;/strong&gt; and Airflow helps you manage that workflow.&lt;br&gt;
&lt;strong&gt;NB:&lt;/strong&gt; Airflow does not usually do the heavy data processing itself but tells other tools when to do the work.&lt;br&gt;
A workflow may be a data pipeline, a machine learning pipeline, a reporting process, or any process made up of several steps.&lt;br&gt;
Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extract_data &amp;gt;&amp;gt; clean_data &amp;gt;&amp;gt; load_data &amp;gt;&amp;gt; send_email
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Apache Airflow is an open-source platform used to &lt;strong&gt;schedule&lt;/strong&gt;, &lt;strong&gt;monitor&lt;/strong&gt; and &lt;strong&gt;manage&lt;/strong&gt; workflows. It was originally created by Maxime Beauchemin at Airbnb in 2014 to manage increasingly complex data workflows. It helps you decide what task should run first, what should follow, what should happen if something fails, and when the whole process should run again.&lt;/p&gt;

&lt;h4&gt;
  
  
  Airflow as an Orchestrator
&lt;/h4&gt;

&lt;p&gt;Orchestration refers to arranging many tasks so they run in the right order and at the scheduled time. It makes sure that task B does not run before task A has finished. It also records whether each task succeeded or failed. Without orchestration, you will have many scripts running manually or through separate cron jobs hence becoming difficult to manage as your project grows.&lt;/p&gt;

&lt;h4&gt;
  
  
  Why Airflow?
&lt;/h4&gt;

&lt;p&gt;While a normal Python script could run fine with simple tasks, you need more control as the number of tasks increases. Airflow is useful because data jobs often have many moving parts.&lt;/p&gt;

&lt;p&gt;Airflow is useful because of various reasons:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Scheduling&lt;/strong&gt;&lt;br&gt;
Since most data work is repetitive, scheduling enables workflows to run automatically based on the scheduled time. Airflow handles complex timezone logic natively, ensuring global data pipelines run exactly when they should.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Catchup and Backfilling&lt;/strong&gt;&lt;br&gt;
If your pipeline breaks over the weekend and you don't fix it until Monday, Airflow knows it missed Saturday and Sunday. It will automatically go back in time and run the missed jobs in order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Task Orchestration&lt;/strong&gt;&lt;br&gt;
Tasks are arranged depending on which task runs first, second, and last.&lt;br&gt;
Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extract &amp;gt;&amp;gt; transform &amp;gt;&amp;gt; load
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This order is critical because if the load task runs before the transform task, the database may receive dirty data. If the transform task runs before extract, there will be no data to clean.&lt;br&gt;
Airflow has parallel execution capabilities to run several tasks simultaneously and wait for all of them to finish before moving to the next step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Monitoring&lt;/strong&gt;&lt;br&gt;
Monitoring standard scripts to know if a job ran successfully requires SSH-ing into a server and digging through terminal files. However, Airflow provides a centralized web interface for the entire data ecosystem to monitor.&lt;br&gt;
&lt;strong&gt;The Web Dashboard/Task Statuses&lt;/strong&gt; - Airflow comes with a beautiful, easy-to-read user interface (UI) with Color-coded views. You can log in and see exactly which tasks succeeded(green), which are currently running(light green), queued(gray) and which failed(red).&lt;br&gt;
&lt;strong&gt;Gantt Charts&lt;/strong&gt; - Visual representations of task duration, helping you identify bottlenecks in your pipeline.&lt;br&gt;
&lt;strong&gt;Historical Trends&lt;/strong&gt; - view the history of a specific pipeline over a duration of time to spot intermittent failures or slowing performance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Automated Retries&lt;/strong&gt;&lt;br&gt;
In the real world, tasks can  fail for temporary reasons. An API may be rate-limited, a database might briefly drop a connection, or a network hiccup might occur.&lt;br&gt;
Instead of waking up at 3:00 AM to manually restart a failed script, Airflow handles transient errors gracefully by trying the task again based on the number of retries set.&lt;br&gt;
Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"retries"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"retry_delay"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;timedelta(minutes=&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="err"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this scenario, if the task fails, Airflow will wait for 5 minutes before trying again, up to three times.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Accessible Logs&lt;/strong&gt;&lt;br&gt;
Finding out why and when a pipeline breaks is very critical. Airflow attaches isolated logs to every single task execution eliminating the need to hunt through an entire server log file.&lt;br&gt;
A user is also able to click on a failed task directly in the web UI and instantly read the error message for that specific run, reducing debugging time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Failure Handling&lt;/strong&gt;&lt;br&gt;
When a task fails, letting the rest of the script run can result in corrupt data or crashed databases. Airflow thus stops execution of the downstream tasks preventing bad data from moving through the pipeline.&lt;br&gt;
Airflow can also be configured to send an automated email, slack message, or an alert when a pipeline fails, ensuring the team is instantly aware of critical data outages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Clear Pipeline Structure&lt;/strong&gt;&lt;br&gt;
Airflow workflows are written entirely in Python hence the pipeline configuration is treated like any other software project. Workflows are visible and anyone can see how tasks connect to each other hence a new person joining the team can open the Airflow UI and understand the pipeline flow.&lt;br&gt;
Workflows can be committed to Git, peer-reviewed, and rolled back if a mistake is made.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Core Assets(Airflow Terminologies)
&lt;/h3&gt;

&lt;p&gt;Before writing any Airflow code, its important to understand its building blocks and the main terms used in the Airflow world because they describe parts of a workflow system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. DAG&lt;/strong&gt;&lt;br&gt;
In Airflow, a full workflow is called a DAG(Directed Acyclic Graph).&lt;br&gt;
&lt;strong&gt;Directed&lt;/strong&gt; - the workflow moves in one direction. The process has a starting point and an ending point and does not move backward.&lt;br&gt;
&lt;strong&gt;Acyclic&lt;/strong&gt; - there are no loops. Since workflow must have a clear start and a clear end loops are not allowed since they create endless cycles and the pipeline might never finish running.&lt;br&gt;
&lt;strong&gt;Graph&lt;/strong&gt; - a structure made up of points and connections. The points are &lt;strong&gt;tasks&lt;/strong&gt; and the connections are &lt;strong&gt;dependencies&lt;/strong&gt;&lt;br&gt;
A DAG is, therefore, a workflow made up of tasks arranged in a clear order and indicating how they connect with each other.&lt;br&gt;
Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nc"&gt;DAG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;dag_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;stock_etl_dag&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;start_date&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2026&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;schedule&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;timedelta&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hours&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;catchup&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;dag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Task&lt;/strong&gt;&lt;br&gt;
A task is one step inside a DAG or one job inside a pipeline. A task should usually do one clear job. Creating one huge task that does everything makes debugging hard thus work should be split into separate tasks.&lt;br&gt;
Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;fetch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;PythonOperator&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;task_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;fetch_stock_data&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;python_callable&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;fetch_stock&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;fetch is the task object, and fetch_stock_data is the task name shown in Airflow. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Operator&lt;/strong&gt;&lt;br&gt;
An operator is the tool used to create and run a task. Different operators are used for different types of jobs.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj2kb77ahnutf277pln9u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj2kb77ahnutf277pln9u.png" alt="Operators" width="466" height="201"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Dependency&lt;/strong&gt;&lt;br&gt;
A dependency defines the order of tasks by telling Airflow which task must run before another task. In simple terms, a dependency is the relationship between tasks.&lt;br&gt;
Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extract &amp;gt;&amp;gt; transform &amp;gt;&amp;gt; load
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means extract runs first, transform runs after extract succeeds and load runs after transform succeeds.&lt;br&gt;
You can also define parallel dependencies to show which tasks should run simultaneously.&lt;br&gt;
Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;download &amp;gt;&amp;gt; [clean_data, backup_data] &amp;gt;&amp;gt; send_email
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This means download runs first, clean_data and backup_data run after download then send_email executes after both clean_data and backup_data finish.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Scheduler&lt;/strong&gt;&lt;br&gt;
The scheduler is the brain of Airflow which checks the DAGs and decides which tasks should run and when.&lt;br&gt;
If the scheduler is not running, DAGs may appear in the UI but tasks may stay queued or show no status.&lt;br&gt;
The scheduler constantly checks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;which DAGs exist&lt;/li&gt;
&lt;li&gt;whether a DAG is due to run&lt;/li&gt;
&lt;li&gt;whether a task’s upstream tasks have succeeded&lt;/li&gt;
&lt;li&gt;whether a task should be queued&lt;/li&gt;
&lt;li&gt;whether a failed task should retry&lt;/li&gt;
&lt;li&gt;whether a DAG run is complete
The scheduler does not usually execute the task itself but decides which task is ready and sends it to the executor.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;6. Executor&lt;/strong&gt;&lt;br&gt;
The executor is the part of Airflow that decides how tasks are actually run. Different Airflow setups use different executors.&lt;br&gt;
Common executors include:&lt;br&gt;
&lt;strong&gt;SequentialExecutor&lt;/strong&gt; - This runs one task at a time thus cannot run many tasks in parallel. It is simple and often used for learning or testing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LocalExecutor&lt;/strong&gt; - This runs tasks locally on the same machine, and it can run more than one task at the same time. It's useful when Airflow is installed on one server and you want tasks to run on that server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CeleryExecutor&lt;/strong&gt; - This is used for larger setups. The scheduler sends tasks to a queue, and workers pick them up and run them. This setup usually needs a message broker such as Redis or RabbitMQ.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;KubernetesExecutor&lt;/strong&gt; - This runs each task in a separate Kubernetes pod. It's more advanced and usually used in cloud or production environments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NB:&lt;/strong&gt; The scheduler decides that a task should run while the executor handles the running method(how Airflow runs tasks).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Worker&lt;/strong&gt;&lt;br&gt;
A worker is the process that actually executes tasks. This term is particularly important when using CeleryExecutor.&lt;br&gt;
In a Celery setup, the flow looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Scheduler &amp;gt;&amp;gt; Queue &amp;gt;&amp;gt; Worker &amp;gt;&amp;gt; Task runs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The scheduler decides the task is ready, the executor sends the task to a queue and the worker picks it up and runs it.&lt;br&gt;
&lt;strong&gt;NB:&lt;/strong&gt; The scheduler decides what should run while the worker does the actual execution.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. XCom&lt;/strong&gt;&lt;br&gt;
XCom means cross-communication. It allows tasks to pass small pieces of data to each other. XCom can help pass data from one task to another.&lt;br&gt;
XCom is for passing small messages between tasks, not for moving large datasets. Passing large datasets through XCom slows down Airflow and fills the metadata database.&lt;/p&gt;

&lt;p&gt;In PythonOperator, you can push data to XCom:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ti&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;xcom_push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;raw_data&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then another task can pull it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;kwargs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ti&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;xcom_pull&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;task_ids&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;extract&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;raw_data&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, you can save large data somewhere else, then pass the location through XCom.&lt;br&gt;
Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extract task saves data to /tmp/raw_stock_data.csv
XCom passes "/tmp/raw_stock_data.csv"
transform task reads the file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;9. Sensors&lt;/strong&gt;&lt;br&gt;
A Sensor is a special type of Operator that just waits. &lt;br&gt;
Imagine you are expecting an important package. You stand at the window waiting for the mail truck. A Sensor does this in software. It can wait for a file to drop into a folder, or wait for another database to finish an update before letting the DAG move on to the next step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10. Metadata Database&lt;/strong&gt;&lt;br&gt;
The metadata database is Airflow’s internal database and uses it to remember what happened(records results of a DAG).&lt;br&gt;
It stores information such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;DAGs&lt;/li&gt;
&lt;li&gt;DAG runs&lt;/li&gt;
&lt;li&gt;Task runs&lt;/li&gt;
&lt;li&gt;Task states&lt;/li&gt;
&lt;li&gt;Schedules&lt;/li&gt;
&lt;li&gt;Retries&lt;/li&gt;
&lt;li&gt;Users&lt;/li&gt;
&lt;li&gt;Roles&lt;/li&gt;
&lt;li&gt;Variables&lt;/li&gt;
&lt;li&gt;Connections&lt;/li&gt;
&lt;li&gt;XCom values&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This database is very important because Airflow needs memory.&lt;br&gt;
For example, Airflow needs to know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Did this task succeed?&lt;/li&gt;
&lt;li&gt;Did this task fail?&lt;/li&gt;
&lt;li&gt;How many times has it retried?&lt;/li&gt;
&lt;li&gt;When did the DAG last run?&lt;/li&gt;
&lt;li&gt;What logs belong to this task?&lt;/li&gt;
&lt;li&gt;What DAGs exist?&lt;/li&gt;
&lt;li&gt;Which users can log in?&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What Airflow is NOT
&lt;/h3&gt;

&lt;p&gt;To fully understand Airflow, you also need to know its limits.&lt;br&gt;
&lt;strong&gt;It's not a data streaming tool&lt;/strong&gt; - Airflow is built for &lt;strong&gt;batch processing&lt;/strong&gt; (running jobs every hour, every day, or every week). It is not designed to process live data happening by the second, like tracking live mouse clicks on a website.&lt;br&gt;
&lt;strong&gt;It's not a data processing engine&lt;/strong&gt; - Airflow is the manager, not the worker. You should not use Airflow to process a 100-gigabyte CSV file in its own memory. Instead, Airflow should send a command to a tool like Apache Spark or Snowflake to do the heavy lifting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Apache Airflow may look difficult when you first encounter it because it comes with many technical jargons making data engineering feel more complicated than it really is. Airflow is simply a workflow manager which helps you organise work that must happen in a specific order. Apache Airflow is about control. It helps you control timing, order, failure, retries, logs, and monitoring.&lt;br&gt;
Just like baking a cake, you must follow the right sequence. A data pipeline works the same way. You extract data, transform it, load it, check it, and sometimes send a notification. Each step depends on the previous one. Airflow gives you a clean way to define these steps and make sure they run correctly.&lt;/p&gt;

</description>
      <category>luxdev</category>
      <category>dataengineering</category>
      <category>apacheairflow</category>
    </item>
    <item>
      <title>ETL vs ELT: Which One Should You Use and Why?</title>
      <dc:creator>Lawrence Murithi</dc:creator>
      <pubDate>Sat, 11 Apr 2026 17:51:32 +0000</pubDate>
      <link>https://forem.com/lawrence_murithi/etl-vs-elt-which-one-should-you-use-and-why-4and</link>
      <guid>https://forem.com/lawrence_murithi/etl-vs-elt-which-one-should-you-use-and-why-4and</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Imagine you are running a massive kitchen. Every day, trucks arrive carrying raw ingredients from different farms. Some boxes have dirty potatoes, some tomatoes are bruised, and the meat needs to be separated from the bone.&lt;br&gt;
Can you just throw all of this straight onto a customer’s plate? Definitely not. You have to wash, chop, season, and cook the ingredients first.&lt;/p&gt;

&lt;p&gt;In the business world, data works the same way. Every day, companies generate tons of raw data from apps, websites, payment gateways, customer service logs etc. This raw data is usually dirty and messy. It has errors, missing fields and mismatched formats. Before it can be used for reporting or decision-making, it needs to be moved, processed and organized. This process of moving and cleaning data is called &lt;strong&gt;data integration&lt;/strong&gt;. &lt;br&gt;
The two main approaches are used in data integration are ETL (Extract, Transform, Load) and ELT (Extract, Load, Transform). Although both methods aim to prepare data for analysis, they follow different steps and are suited for different situations. &lt;br&gt;
If you are just stepping into data engineering, software engineering or backend development, ETL and ELT are common terms you will encounter. &lt;br&gt;
This article explains both approaches in detail, compares them, and helps you understand when to use each one.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is ETL?
&lt;/h2&gt;

&lt;p&gt;ETL stands for Extract, Transform, Load. It is the traditional method used to move and prepare data.&lt;br&gt;
The key idea in ETL is that data is cleaned and transformed before it is stored in the final system. This means that by the time the data reaches the data warehouse, it is already structured, organized, and ready for use.&lt;br&gt;
This approach was developed at a time when computing resources were limited, and companies had to be very careful about what data they stored.&lt;/p&gt;

&lt;h3&gt;
  
  
  Steps in ETL
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Extract&lt;/strong&gt;&lt;br&gt;
This step involves collecting raw data from different sources such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Databases&lt;/li&gt;
&lt;li&gt;APIs&lt;/li&gt;
&lt;li&gt;Excel files&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In real-world scenarios, data rarely comes from a single source. A company may have customer data in one system, sales data in another, and marketing data in a third system. This extraction step pulls all this data together.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Transform&lt;/strong&gt;&lt;br&gt;
In this stage, data is processed in a separate system before being stored. This transformation step ensures that all data is consistent, accurate, and usable.&lt;/p&gt;

&lt;p&gt;Common transformations include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Standardizing data formats&lt;/li&gt;
&lt;li&gt;Handling missing values&lt;/li&gt;
&lt;li&gt;Removing duplicate records&lt;/li&gt;
&lt;li&gt;Fixing errors in data&lt;/li&gt;
&lt;li&gt;Masking sensitive data such as credit card numbers&lt;/li&gt;
&lt;li&gt;Combining data from different sources&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This step is where raw data is made meaningful. Without transformation, data would remain inconsistent and difficult to analyze.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Load&lt;/strong&gt;&lt;br&gt;
After transformation, the cleaned data is loaded into a data warehouse or database.&lt;br&gt;
At this stage, the data is ready for carrying out analysis, creating dashboards and reporting. &lt;br&gt;
&lt;strong&gt;Simple Diagram of ETL&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr3blgiapqpgd16xihdio.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr3blgiapqpgd16xihdio.png" alt="ETL" width="341" height="148"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Why ETL Was Popular
&lt;/h3&gt;

&lt;p&gt;In the past, data warehouses were physical servers sitting in basements. Storage space was incredibly expensive and computing power was very limited. Companies, therefore, could not afford to store raw, useless data. They had to clean it up and shrink it down before loading it into the warehouse.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is ELT?
&lt;/h2&gt;

&lt;p&gt;ELT stands for Extract, Load, Transform. It is a modern approach made possible by cloud computing. Here data is loaded first and transformed later inside the data lake.&lt;br&gt;
This approach takes advantage of modern systems that can store large amounts of data and process it quickly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Steps in ELT
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Extract&lt;/strong&gt;&lt;br&gt;
Data is collected from different sources just like in ETL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Load&lt;/strong&gt;&lt;br&gt;
This is a major shift from ETL. Instead of first cleaning the data, you load the raw data directly into your target data lake without any changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Transform&lt;/strong&gt;&lt;br&gt;
The transformation happens inside the data lake. This means analysts can use the warehouse's own computing power to clean, format, and organize the data..&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simple Diagram of ELT&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwdv7cxynv3ek5ljfic0f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwdv7cxynv3ek5ljfic0f.png" alt="ELT" width="795" height="197"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Why ELT Became Popular
&lt;/h3&gt;

&lt;p&gt;The emergence of modern cloud data warehouses such as Snowflake, Google BigQuery, and Amazon Redshift changed the game. Today, storing data in the cloud is incredibly cheap. Furthermore, these cloud warehouses have massive, scalable computing power.&lt;br&gt;
Instead of buying a separate, expensive server just to transform data (like in ETL), companies no longer need to clean data before storing it. They can store everything and process it later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Differences Between ETL and ELT
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Order of Steps&lt;/strong&gt;&lt;br&gt;
in ETL, transformation happens before loading while in ELT transformation happens after loading.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Where the Transformation Happens&lt;/strong&gt;&lt;br&gt;
In ETL, transformation happens in a separate server outside the warehouse while in ELT, the transformation happens right inside the destination data warehouse.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Speed of Loading&lt;/strong&gt;&lt;br&gt;
ELT is usually much faster at the loading stage since there is no cleaning of the data. ETL takes longer because the data has to wait in line to be processed before it can be loaded into the warehouse.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Maintenance and Flexibility&lt;/strong&gt;&lt;br&gt;
ETL is less flexible and changes require rebuilding pipelines. If a mistake is made in an ETL pipeline, or if you want to format the data differently, you have to go back to the source, re-extract the data, and run it through the whole pipeline again.&lt;br&gt;
With ELT, the raw data is already sitting in your warehouse. Any mistake during transformation, you simply write a new SQL query and transform the raw data afresh. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. The Skills Required&lt;/strong&gt;&lt;br&gt;
ETL often requires specialized tools and programming such as software engineers who know Java, Python or drag-and-drop tools. ELT uses SQL and since the data is transformed inside a database, it is accessible to analysts.&lt;br&gt;
&lt;strong&gt;NB:&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ETL focuses on control, structure, and quality before storage&lt;/li&gt;
&lt;li&gt;ELT focuses on speed, flexibility, and scalability after storage.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Advantages and Disadvantages
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ETL
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Security and Compliance&lt;/strong&gt; - If you are dealing with highly sensitive data (like medical records or credit cards), ETL allows you to strip out/mask the sensitive parts before storage in the main warehouse. &lt;br&gt;
&lt;strong&gt;Reduced and cheaper Storage&lt;/strong&gt; - Because you are only loading refined data, you take up much less storage space in your destination database.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Rigid&lt;/strong&gt; - Setting up an ETL pipeline takes a lot of time. If a source system needs to make a change, the whole ETL pipeline might break and need to be rewritten.&lt;br&gt;
&lt;strong&gt;Bottlenecks&lt;/strong&gt; - If you have massive amounts of data, the processing server can easily get overwhelmed and slow down the whole operation.&lt;/p&gt;

&lt;h3&gt;
  
  
  ELT
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Advantages&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Agility&lt;/strong&gt; - Since raw data is loaded quickly and directly into the warehouse, analysts do not have to wait for engineers to build complex pipelines to access the raw data.&lt;br&gt;
&lt;strong&gt;Future-Proof&lt;/strong&gt; - Because you keep a copy of the exact raw data, reprocessing of raw data is always possible. You can also go back and answer new business questions that you hadn't thought of previously.&lt;br&gt;
&lt;strong&gt;Scalability&lt;/strong&gt; - Cloud warehouses are designed to scale automatically thus are able to support large datasets.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disadvantages&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Security Risks&lt;/strong&gt; - Since you are loading raw, unfiltered data into your warehouse, you have to be careful about who has access to the warehouse if that data contains sensitive information such as passwords, personal addresses or financial details.&lt;br&gt;
&lt;strong&gt;Higher computing costs&lt;/strong&gt; - While cloud storage is cheap, cloud computing can get expensive. If you have bad SQL code running inefficient transformations inside your warehouse every hour, your monthly cloud bill will skyrocket.&lt;/p&gt;

&lt;h3&gt;
  
  
  ETL Tools
&lt;/h3&gt;

&lt;p&gt;These tools are designed for structured, enterprise-level data pipelines.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Informatica&lt;/li&gt;
&lt;li&gt;IBM DataStage&lt;/li&gt;
&lt;li&gt;Talend&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ELT Tools
&lt;/h3&gt;

&lt;p&gt;Modern ELT uses different tools for each step:&lt;br&gt;
These tools allow analysts to work directly with data using SQL.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fivetran / Airbyte → Extract and Load&lt;/li&gt;
&lt;li&gt;dbt (Data Build Tool) → Transform&lt;/li&gt;
&lt;li&gt;Cloud Warehouses → Snowflake, BigQuery, Redshift&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Real-World Use Cases
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Banking System (ETL)&lt;/strong&gt;&lt;br&gt;
A bank handles sensitive data from mobile app banking, ATMs and physical branch locations. This data contains raw account numbers, account balances, passwords and PIN, personal details and financial transactions thus must be secured before storage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;E-commerce Startup (ELT)&lt;/strong&gt;&lt;br&gt;
An online store that wants to track user behavior will generate large amounts of data daily just from people clicking around their website, viewing products, adding items to carts etc. The marketing team thus has to constantly change what they want to measure. One week they may want to track abandoned carts while the following week they may want to track how long people look at a specific product. The business has to frequently change what it wants to analyze.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which One Should You Use and Why?
&lt;/h2&gt;

&lt;p&gt;If you are starting a new project and trying to choose between ETL and ELT, here is a practical guide to help you decide.&lt;br&gt;
&lt;strong&gt;Choose ETL if&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;- You are bound by strict privacy laws&lt;/strong&gt; - If you work with sensitive data (healthcare, banking), the ability to scrub data before it lands in a database should be key.&lt;br&gt;
&lt;strong&gt;- Your system uses on-premise databases&lt;/strong&gt; - If your company still keeps its servers in a physical server room, your database may not have high processing power required to do transformations internally hence you will need a separate ETL server.&lt;br&gt;
&lt;strong&gt;- Your data source is unstructured&lt;/strong&gt; - If you are extracting data from highly complex, old mainframes that output weird file types, standard ELT tools might not know how to read them. You will need a custom ETL script to decode and format the data before it can be saved.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Choose ELT if&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;- You are using a cloud data warehouse&lt;/strong&gt; - If you have Snowflake, BigQuery, or Redshift, ELT is most convinient since it takes advantage of what you are already paying for.&lt;br&gt;
&lt;strong&gt;- You work with large volumes of diverse data&lt;/strong&gt; - If you are tracking millions of tiny events (like website clicks, product views or IoT sensor readings), pushing it directly to the cloud is the only way to keep up with the volume.&lt;br&gt;
&lt;strong&gt;- You need flexibility in analysis and fast data processing&lt;/strong&gt; - ELT allows data engineers to focus purely on moving data from point A to point B, while empowering data analysts to handle the business logic and formatting using SQL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The debate between ETL and ELT is less about which one is better and more about matching your business needs, data size, and system architecture. Understanding both approaches helps you design better data pipelines and make smarter decisions when working with data.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>data</category>
      <category>database</category>
      <category>dataengineering</category>
    </item>
    <item>
      <title>Advanced SQL Techniques for Data Analytics Every Data Analyst Should Know</title>
      <dc:creator>Lawrence Murithi</dc:creator>
      <pubDate>Thu, 09 Apr 2026 13:21:19 +0000</pubDate>
      <link>https://forem.com/lawrence_murithi/advanced-sql-techniques-for-data-analytics-every-data-analyst-should-know-53c8</link>
      <guid>https://forem.com/lawrence_murithi/advanced-sql-techniques-for-data-analytics-every-data-analyst-should-know-53c8</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In today’s data-driven environment, organizations rely heavily on data to make decisions. Businesses collect large amounts of information from different sources such as sales systems, customer platforms, and operational databases. However, raw data alone is not useful unless it can be analyzed and transformed into meaningful insights.&lt;/p&gt;

&lt;p&gt;SQL (Structured Query Language) plays a central role in this process. It allows analysts to retrieve, clean, and analyze data stored in relational databases. While basic SQL skills are important, advanced SQL techniques are what truly enable analysts to solve complex business problems.&lt;/p&gt;

&lt;p&gt;This article explains advanced SQL concepts in simple terms and shows how they are applied in real-world data analytics scenarios. The goal is to help you understand not just how to write SQL queries, but how to use them effectively in practical situations.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Role of SQL in Data Analytics
&lt;/h3&gt;

&lt;p&gt;SQL is the foundation of data analytics. Most business data is stored in databases, and SQL is the language used to interact with that data.&lt;/p&gt;

&lt;p&gt;Data analysts use SQL to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extract data from databases&lt;/li&gt;
&lt;li&gt;Filter and clean datasets&lt;/li&gt;
&lt;li&gt;Combine data from multiple tables&lt;/li&gt;
&lt;li&gt;Perform calculations and aggregations&lt;/li&gt;
&lt;li&gt;Prepare data for reporting tools like Power BI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;SQL is often the first step before using any visualization tools. If the data is not properly prepared using SQL, the final reports may be inaccurate or misleading.&lt;/p&gt;

&lt;h3&gt;
  
  
  Working with Complex Queries
&lt;/h3&gt;

&lt;p&gt;As data becomes more complex, simple queries are not enough to handle it. Advanced SQL, therefore, introduces techniques that help break down complex problems into manageable steps. &lt;br&gt;
In real-world data analysis, datasets are often large and contain multiple tables with different relationships. Moreover, analysts are expected to answer questions that involve comparisons, calculations and multiple layers of logic. These techniques therefore allow analysts to solve the problems step by step instead of trying to do everything in one single query.&lt;br&gt;
Complex query techniques thus help analysts organize their queries in a way that is easier to understand, maintain, and scale. &lt;/p&gt;

&lt;p&gt;They are useful when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Comparing values against aggregated results&lt;/li&gt;
&lt;li&gt;Reusing part of a query&lt;/li&gt;
&lt;li&gt;Working with multi-step transformations&lt;/li&gt;
&lt;li&gt;Simplifying long and confusing SQL statements&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some of the advanced SQL techniques include:&lt;/p&gt;
&lt;h4&gt;
  
  
  Subqueries
&lt;/h4&gt;

&lt;p&gt;A subquery is a query inside another query. Subqueries are useful when you need to perform a calculation first and then use that result in another query. They allow you to embed logic directly inside your main query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;AVG&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explanation:&lt;br&gt;
_- The inner query calculates the average salary&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The outer query returns employees earning above average_&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Subqueries can be used in different parts of a query:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In the WHERE clause&lt;/li&gt;
&lt;li&gt;In the SELECT clause&lt;/li&gt;
&lt;li&gt;In the FROM clause (called derived tables)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Real-World Case Scenarios:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identify high-performing employees based on salary or performance metrics. &lt;/li&gt;
&lt;li&gt;Finding customers who spend more than the average customer&lt;/li&gt;
&lt;li&gt;Identifying products priced above the average price&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;NB:&lt;/strong&gt; While subqueries are powerful, they can become slow if used incorrectly, especially with large datasets.&lt;/p&gt;
&lt;h4&gt;
  
  
  Common Table Expressions (CTEs)
&lt;/h4&gt;

&lt;p&gt;A CTE is a temporary result in an SQL query that helps improves readability and organization(temporary table that exists only while the query is running).&lt;/p&gt;

&lt;p&gt;CTEs allow you to define a query once and then use it in the main query. This makes complex queries easier to read and understand, especially when working with multiple steps.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;sales_summary&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;total_sales&lt;/span&gt;
    &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;
    &lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;product_id&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales_summary&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;total_sales&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Types of CTEs:&lt;br&gt;
&lt;strong&gt;- Recursive CTE&lt;/strong&gt;: A specialized CTE that references itself, which is essential for querying hierarchical data like organizational charts or family trees.&lt;br&gt;
&lt;strong&gt;- Non-Recursive CTE&lt;/strong&gt;: The most common type, used to simplify standard queries by creating manageable logical steps.&lt;br&gt;
Benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Makes queries clean and easier to read&lt;/li&gt;
&lt;li&gt;Breaks complex logic into steps, thus easier to debug and modify&lt;/li&gt;
&lt;li&gt;Improves maintainability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;NB:&lt;/strong&gt; You can also have multiple CTEs in one query, which is useful for complex data transformations.&lt;/p&gt;

&lt;p&gt;In business reporting, analysts often build layered queries. CTEs allow them to structure their logic clearly when working with large datasets.&lt;br&gt;
Step 1: Calculate total sales per product&lt;br&gt;
Step 2: Filter high-performing products&lt;br&gt;
Step 3: Join with other tables for reporting&lt;/p&gt;
&lt;h3&gt;
  
  
  Advanced Joins
&lt;/h3&gt;

&lt;p&gt;Joins are used to combine data from multiple tables. In advanced SQL, joins become more powerful when dealing with complex relationships.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;order_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_name&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
&lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;
&lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="n"&gt;o&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a retail company:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Customers table stores customer details&lt;/li&gt;
&lt;li&gt;Orders table stores transactions&lt;/li&gt;
&lt;li&gt;Products table stores product information&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Using joins, analysts can create a full view of customer purchases.&lt;/p&gt;

&lt;p&gt;Poor joins can lead to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Duplicate data&lt;/li&gt;
&lt;li&gt;Incorrect totals&lt;/li&gt;
&lt;li&gt;Misleading reports&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Window Functions
&lt;/h3&gt;

&lt;p&gt;Window functions allow us to perform advanced calculations across a group of related rows while keeping the original data. They are useful for ranking, running totals, moving averages, and analytical reporting.&lt;br&gt;
Window functions often remove the need for complex self-joins and provide an analytical layer within SQL.&lt;br&gt;
Window functions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Keep every row&lt;/li&gt;
&lt;li&gt;Add calculated values to each row
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;column_1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="k"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
           &lt;span class="k"&gt;PARTITION&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="k"&gt;column&lt;/span&gt;
           &lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="k"&gt;column&lt;/span&gt;
       &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;output_column&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="k"&gt;table_name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Window functions are widely used in business intelligence and reporting for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rankings within a group&lt;/li&gt;
&lt;li&gt;Calculating running totals&lt;/li&gt;
&lt;li&gt;Compare rows (current vs previous)&lt;/li&gt;
&lt;li&gt;Analyzing trends over time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Companies use ranking to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identify top performers&lt;/li&gt;
&lt;li&gt;Allocate bonuses&lt;/li&gt;
&lt;li&gt;Compare employee performance
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="o"&gt;##&lt;/span&gt; &lt;span class="n"&gt;Ranking&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;

&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;RANK&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;rank&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;employees&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Businesses use running totals to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Track revenue growth&lt;/li&gt;
&lt;li&gt;Monitor daily or monthly performance&lt;/li&gt;
&lt;li&gt;Forecast future trends
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="o"&gt;##&lt;/span&gt; &lt;span class="n"&gt;Running&lt;/span&gt; &lt;span class="n"&gt;totals&lt;/span&gt;

&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;running_total&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Aggregations and Grouping
&lt;/h3&gt;

&lt;p&gt;Aggregation helps summarize large datasets. Raw data is often too detailed to understand directly. Aggregation thus helps turn large datasets into meaningful summaries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;region&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;total_sales&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;region&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Aggregation allows analysts to answer questions such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Total sales by region&lt;/li&gt;
&lt;li&gt;Sales by product category&lt;/li&gt;
&lt;li&gt;Monthly revenue trends&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Aggregation is often used together with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Filtering (HAVING)&lt;/li&gt;
&lt;li&gt;Sorting (ORDER BY)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Data Cleaning and Transformation
&lt;/h3&gt;

&lt;p&gt;Data cleaning is one of the most important steps in analytics. Since raw data is usually dirty and messy, SQL helps clean and prepare it before analysis. &lt;br&gt;
Raw data may contain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Duplicates&lt;/li&gt;
&lt;li&gt;Missing values&lt;/li&gt;
&lt;li&gt;Incorrect formats&lt;/li&gt;
&lt;li&gt;Inconsistent entries&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Removing Duplicates
&lt;/h4&gt;

&lt;p&gt;Removes repeated values and ensures each entry appears only once.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;DISTINCT&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Handling Missing Values
&lt;/h4&gt;

&lt;p&gt;Replaces NULL values with a default value thus preventing errors in reports&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;COALESCE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;phone&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Not Available'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Data Transformation
&lt;/h4&gt;

&lt;p&gt;Creates a new calculated column&lt;br&gt;
Data transformation also includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Changing data types&lt;/li&gt;
&lt;li&gt;Formatting dates&lt;/li&gt;
&lt;li&gt;Standardizing values
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;total_sales&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Using SQL for Real-World Business Problems
&lt;/h3&gt;

&lt;p&gt;Advanced SQL is not just about writing queries but solving real problems.&lt;br&gt;
In organizations, SQL is used daily to answer business questions and support decisions.&lt;/p&gt;
&lt;h4&gt;
  
  
  Customer Segmentation
&lt;/h4&gt;

&lt;p&gt;Businesses use customer segmentation to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Target high-value customers&lt;/li&gt;
&lt;li&gt;Design marketing strategies&lt;/li&gt;
&lt;li&gt;Improve customer retention
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="o"&gt;##&lt;/span&gt; &lt;span class="k"&gt;Grouping&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="n"&gt;based&lt;/span&gt; &lt;span class="k"&gt;on&lt;/span&gt; &lt;span class="n"&gt;spending&lt;/span&gt;

&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="k"&gt;CASE&lt;/span&gt; 
    &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="n"&gt;total_spent&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt; &lt;span class="s1"&gt;'High Value'&lt;/span&gt;
    &lt;span class="k"&gt;WHEN&lt;/span&gt; &lt;span class="n"&gt;total_spent&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt; &lt;span class="s1"&gt;'Medium Value'&lt;/span&gt;
    &lt;span class="k"&gt;ELSE&lt;/span&gt; &lt;span class="s1"&gt;'Low Value'&lt;/span&gt;
&lt;span class="k"&gt;END&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;segment&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customer_sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  Sales Performance Analysis
&lt;/h4&gt;

&lt;p&gt;Total sales are calculated per product and sorted products by performance to identify best-selling products.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;total_sales&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;product_id&lt;/span&gt;
&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;total_sales&lt;/span&gt; &lt;span class="k"&gt;DESC&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Segmentation helps organizations to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understand performance&lt;/li&gt;
&lt;li&gt;Identify opportunities&lt;/li&gt;
&lt;li&gt;Solve operational problems&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Performance Optimization
&lt;/h3&gt;

&lt;p&gt;SQL queries must be clean, easy to understand and efficient.&lt;br&gt;
In large databases, poor queries can slow down systems and delay reports.&lt;/p&gt;

&lt;p&gt;Best Practices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use indexes on important columns to speed up data retrieval&lt;/li&gt;
&lt;li&gt;Avoid selecting unnecessary columns&lt;/li&gt;
&lt;li&gt;Filter data early to reduces data size&lt;/li&gt;
&lt;li&gt;Use CTEs instead of repeated subqueries&lt;/li&gt;
&lt;li&gt;Avoid unnecessary joins&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Advanced SQL is a critical skill for data analysts. It goes beyond basic queries and allows analysts to work with complex datasets, perform advanced calculations and solve real-world business problems.&lt;/p&gt;

&lt;p&gt;In this article, we explored key advanced SQL techniques such as subqueries, CTEs, joins, window functions, aggregations, and data transformation and how they are applied in real business scenarios&lt;/p&gt;

&lt;p&gt;In data analytics, SQL is not just a tool but is a core skill that connects raw data to meaningful insights. Mastering advanced SQL allows analysts to move from basic reporting to deeper, more impactful analysis&lt;/p&gt;

</description>
      <category>sql</category>
      <category>luxdev</category>
      <category>dataengineering</category>
    </item>
    <item>
      <title>Connecting Power BI to SQL Databases: A Practical Guide for Data Analysts</title>
      <dc:creator>Lawrence Murithi</dc:creator>
      <pubDate>Tue, 17 Mar 2026 12:03:47 +0000</pubDate>
      <link>https://forem.com/lawrence_murithi/connecting-power-bi-to-sql-databases-a-practical-guide-for-data-analysts-5745</link>
      <guid>https://forem.com/lawrence_murithi/connecting-power-bi-to-sql-databases-a-practical-guide-for-data-analysts-5745</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;In most modern organizations, data is one of the most valuable assets. Companies collect large amounts of information from sales systems, websites, customer platforms, and operational databases. To make sense of this information, businesses use tools that can transform this raw data into clear insights. One of the most widely used tools for this purpose is the Microsoft Power BI platform.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Power BI
&lt;/h2&gt;

&lt;p&gt;Power BI is a business intelligence and data visualization tool developed by Microsoft. It allows users to connect to different data sources, analyze data, and create interactive dashboards and reports. These reports help organizations monitor performance, understand trends, and support decision-making among other uses.&lt;/p&gt;

&lt;p&gt;Power BI is commonly used by data analysts, business managers, and decision makers because it can present complex data in simple visual forms such as charts, tables, maps, and dashboards.&lt;/p&gt;

&lt;p&gt;Most organizations store their operational and analytical data in SQL databases. SQL databases are designed to store large amounts of structured data in tables. They allow users to query, filter, update, and analyze data efficiently using Structured Query Language (SQL). SQL databases are reliable, secure, and scalable, hence they are widely used in business systems such as sales platforms, customer management systems, and inventory systems.&lt;/p&gt;

&lt;p&gt;Connecting Power BI to a database allows analysts to access this stored data directly. Instead of manually exporting data into spreadsheets, Power BI can retrieve the data automatically, refresh it when the database changes, and build dashboards that always reflect the latest information.&lt;/p&gt;

&lt;p&gt;This article explains how Power BI connects to SQL databases, how to connect to a local PostgreSQL database, how to connect to a cloud database such as Aiven PostgreSQL, and how the loaded data is modeled for analysis.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding the Power BI Interface
&lt;/h3&gt;

&lt;p&gt;Before connecting to a database, it is helpful to understand the Power BI Desktop interface. Power BI Desktop is the main application used for building reports and dashboards.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fccc89cx73itso4ddn7vt.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fccc89cx73itso4ddn7vt.jpg" alt="BI Desktop" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
The Power BI Desktop interface includes several sections such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ribbon (Top Menu) – Contains commands and tabs such as Get Data, Transform Data, and Publish.&lt;/li&gt;
&lt;li&gt;Report Canvas – The workspace where charts and dashboards are created.&lt;/li&gt;
&lt;li&gt;Visualizations Pane – Used to select and customize charts.&lt;/li&gt;
&lt;li&gt;Fields Pane – Displays the tables and columns loaded into Power BI.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can download Power BI desktop app &lt;a href="https://www.microsoft.com/en-us/power-platform/products/power-bi/desktop" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Connecting Power BI to a Local PostgreSQL Database
&lt;/h3&gt;

&lt;p&gt;PostgreSQL is one of the most popular open-source relational databases used in data analytics. Many organizations run databases locally on their own servers. &lt;br&gt;
The steps below explain how to connect Power BI to a local PostgreSQL database.&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 1: Open Power BI Desktop
&lt;/h4&gt;

&lt;p&gt;Start by opening Power BI Desktop on your computer.&lt;br&gt;
When the application opens, a blank report canvas appears. This is where you will build your report after loading the data.&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 2: Get Data
&lt;/h4&gt;

&lt;p&gt;On the Home tab of the ribbon, click Get Data.&lt;br&gt;
This button opens a list of available data sources. Power BI supports many data sources including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Excel&lt;/li&gt;
&lt;li&gt;SQL Server&lt;/li&gt;
&lt;li&gt;PostgreSQL&lt;/li&gt;
&lt;li&gt;Web APIs
The Get Data feature is the starting point for connecting Power BI to any data source. Other data sources are as shown on the image.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flsqplwvo6mi1vf0n859m.jpg" alt="Get Data" width="800" height="450"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  Step 3: Select PostgreSQL Database
&lt;/h4&gt;

&lt;p&gt;From the list of available data connectors, click &lt;strong&gt;more&lt;/strong&gt; to view more options. Scroll down, select &lt;strong&gt;PostgreSQL Database&lt;/strong&gt; and click &lt;strong&gt;Connect&lt;/strong&gt;.&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 4: Enter the Database Connection Details
&lt;/h4&gt;

&lt;p&gt;After selecting PostgreSQL and clicking connect, Power BI opens a connection window that requires connection details for the connection to go through.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwa7subvjsrzicalek1n.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdwa7subvjsrzicalek1n.jpg" alt="Credentials" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Server&lt;/strong&gt; – The location of the database server. If the database is on your computer, use localhost.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Database&lt;/strong&gt; – The name of the database you want to connect to.&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 5: Provide Login Credentials
&lt;/h4&gt;

&lt;p&gt;After a connection is made, Power BI will ask for authentication details.&lt;br&gt;
You will need to provide:&lt;br&gt;
&lt;strong&gt;Username&lt;br&gt;
Password&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;These credentials were set up during installation of the PostgreSQL and allows Power BI to securely access the database.&lt;/p&gt;

&lt;p&gt;Once the credentials are entered, click Connect.&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 6: Select Tables to Import
&lt;/h4&gt;

&lt;p&gt;After connecting successfully, Power BI opens the Navigator Window which displays all available tables in the database.&lt;br&gt;
You can preview the contents of each table before loading them.&lt;br&gt;
There are two options:&lt;br&gt;
&lt;strong&gt;Load&lt;/strong&gt; – Import the data directly.&lt;br&gt;
&lt;strong&gt;Transform Data&lt;/strong&gt; – Clean or modify the data before loading it.&lt;/p&gt;
&lt;h3&gt;
  
  
  Connecting Power BI to a Cloud Database (Aiven PostgreSQL)
&lt;/h3&gt;

&lt;p&gt;Many organizations now store their databases in the cloud. Cloud databases are accessible through the internet and provide benefits such as scalability, backups, and easier management.&lt;br&gt;
Aiven is a cloud platform that provides managed PostgreSQL databases.&lt;br&gt;
Connecting Power BI to a cloud database is not different to connecting to a local database, only that additional security steps are required.&lt;/p&gt;

&lt;p&gt;The steps below explain how to connect Power BI to an Aiven PostgreSQL database.&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 1: Get the Database Connection Details from Aiven
&lt;/h4&gt;

&lt;p&gt;Login to Aiven and inside the dashboard, you will find the connection information for your PostgreSQL service. These details are used by Power BI to locate and connect to the database.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgniq9zxf2r4e78vijr8d.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgniq9zxf2r4e78vijr8d.jpg" alt="Connection Details" width="800" height="289"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 2: Download and install the SSL Certificate
&lt;/h4&gt;

&lt;p&gt;Cloud database providers often require SSL encryption to secure the connection.&lt;br&gt;
An SSL certificate ensures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Data transferred between Power BI and the database is encrypted&lt;/li&gt;
&lt;li&gt;Unauthorized users cannot intercept the connection&lt;/li&gt;
&lt;li&gt;The database server identity is verified&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Aiven, download the certificate file(CA Certificate) from the Connection Information section of the service dashboard.&lt;br&gt;
Rename the downloaded file from &lt;strong&gt;ca.pem&lt;/strong&gt; to &lt;strong&gt;ca.crt&lt;/strong&gt; and install the Certificate on your PC.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzahcljjsav3r40i5mh96.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzahcljjsav3r40i5mh96.jpg" alt="SSL Certificate" width="597" height="763"&gt;&lt;/a&gt;&lt;br&gt;
Choose Local Machine as the location of the installation and click next.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx30qrvf497dbag9gsbad.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx30qrvf497dbag9gsbad.jpg" alt="Local Machine" width="793" height="775"&gt;&lt;/a&gt;&lt;br&gt;
Choose &lt;strong&gt;place all certificates in the following store&lt;/strong&gt; and browse certificate store to &lt;strong&gt;Trusted Root Certification Authorities&lt;/strong&gt;. &lt;br&gt;
Click &lt;strong&gt;ok&lt;/strong&gt; and &lt;strong&gt;finish&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyg4l0upupjwxaz519po5.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyg4l0upupjwxaz519po5.jpg" alt="Store" width="783" height="811"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Step 3: Connect Power BI
&lt;/h4&gt;

&lt;p&gt;Open Power BI desktop as before, click &lt;strong&gt;Get Data&lt;/strong&gt;, click &lt;strong&gt;more&lt;/strong&gt;, scroll down and select &lt;strong&gt;PostgreSQL Database&lt;/strong&gt;.&lt;br&gt;
Copy the &lt;strong&gt;Server Name&lt;/strong&gt; from the service URL(&lt;strong&gt;host_name:port_number&lt;/strong&gt;) on Connection Information and paste on Power BI.&lt;br&gt;
Input the name of your database and click &lt;strong&gt;ok&lt;/strong&gt;.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu18dtkx45ilpu9hofwse.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu18dtkx45ilpu9hofwse.jpg" alt="server &amp;amp; db" width="800" height="426"&gt;&lt;/a&gt;&lt;br&gt;
Copy the username and password from Aiven, input them on the Power BI credentials window that opens and click &lt;strong&gt;connect&lt;/strong&gt;.&lt;br&gt;
Once the connection is successful, a navigator window opens and displays all tables in the database. &lt;br&gt;
Select the tables you want to work with and click on &lt;strong&gt;load/transfrom data&lt;/strong&gt; depending on what you wish to do with the data.&lt;br&gt;
Transform data option is used to clean raw data e.g delete any duplicates and address null values using the most appropriate method.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj384cz97geuk12zvbe1s.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj384cz97geuk12zvbe1s.jpg" alt="Load data" width="800" height="425"&gt;&lt;/a&gt;&lt;br&gt;
Successfully loaded data displays on the data pane as shown on figure below. &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmoqoi3v0etj70udifbs3.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmoqoi3v0etj70udifbs3.jpg" alt="Tables" width="800" height="427"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  Creating Relationships Between Tables
&lt;/h4&gt;

&lt;p&gt;Once loaded, Power BI automatically detects relationships between tables based on matching columns using primary and foreign keys. Relationships not created can be manually created by dragging a column from one table onto the matching column in another table.&lt;br&gt;
These relationships allow Power BI to combine information across multiple tables. &lt;br&gt;
For example:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F17mn1jzfmmcng1bk54zg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F17mn1jzfmmcng1bk54zg.jpg" alt="Connection" width="543" height="237"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Model View, the tables appear as connected boxes. The relationships show how data flows between tables.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4ebu7s8y3tr1j5io4sqr.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4ebu7s8y3tr1j5io4sqr.jpg" alt="Relatioships" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Data Modeling and Why its Important
&lt;/h2&gt;

&lt;p&gt;Data modeling is the process of defining how data is stored, structured, and related within a database. It ensures that Power BI understands how different tables are related.&lt;/p&gt;

&lt;p&gt;Good data modeling allows Power BI to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Filter data correctly&lt;/li&gt;
&lt;li&gt;Calculate totals accurately&lt;/li&gt;
&lt;li&gt;Create meaningful visualizations&lt;/li&gt;
&lt;li&gt;Avoid duplicated values&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, when analyzing sales:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The sales table stores transaction records.&lt;/li&gt;
&lt;li&gt;The customers table provides customer information.&lt;/li&gt;
&lt;li&gt;The products table describes the items sold.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  why SQL skills are important for Power BI analysts
&lt;/h3&gt;

&lt;p&gt;Power BI is a powerful tool for building reports and dashboards, but it does not replace the need for strong data handling skills. Most business data is stored in SQL databases, and before that data can be visualized in Power BI, it must first be retrieved, cleaned, and structured properly. &lt;br&gt;
SQL skills give Power BI analysts a real edge by providing an easier way to grab just what you need without pulling everything into Power BI. &lt;br&gt;
Without SQL, analysts may rely too much on raw data, which can lead to slow reports, incorrect results, and inefficient workflows.&lt;br&gt;
SQL allows analysts to:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Retrieve Data&lt;/strong&gt;&lt;br&gt;
Analysts can write queries to select specific rows and columns relevant to their analysis from a database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- selecting only products name and price columns from products table&lt;/span&gt;

&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;product_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;products&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why this matters in Power BI:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduces the amount of data imported&lt;/li&gt;
&lt;li&gt;Improves performance&lt;/li&gt;
&lt;li&gt;Makes the model easier to manage&lt;/li&gt;
&lt;li&gt;Avoids unnecessary columns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Filter Data&lt;/strong&gt;&lt;br&gt;
In real-world scenarios, not all data is useful for analysis. Analysts often need to focus on specific time periods, regions, or business conditions. SQL thus makes it easy to filter datasets based on a specific criteria before loading them into Power BI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Retrieving only sales from 2024 onwards.&lt;/span&gt;

&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;sale_date&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="s1"&gt;'2024-01-01'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why this matters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduces dataset size&lt;/li&gt;
&lt;li&gt;Speeds up report loading&lt;/li&gt;
&lt;li&gt;Focuses analysis on relevant data&lt;/li&gt;
&lt;li&gt;Avoids unnecessary processing inside Power BI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Perform Aggregations&lt;/strong&gt;&lt;br&gt;
Aggregation is the process of summarizing data. In business analysis, analysts often need totals, averages, counts, and other summary metrics. SQL can summarize large datasets quickly by using functions such as GROUP BY, SUM, COUNT, and AVG.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Calculating total sales per product&lt;/span&gt;

&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;total_quantity&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;
&lt;span class="k"&gt;GROUP&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;product_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why aggregation in SQL is important:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Reduces data volume before loading&lt;/li&gt;
&lt;li&gt;Improves Power BI performance&lt;/li&gt;
&lt;li&gt;Simplifies data models&lt;/li&gt;
&lt;li&gt;Avoids heavy calculations in DAX&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Preparing data for Analysis
&lt;/h3&gt;

&lt;p&gt;Raw data must be cleaned or transformed before it is ready for visualization. &lt;br&gt;
SQL can be used to:&lt;/p&gt;
&lt;h4&gt;
  
  
  Joining Tables and Combining Data
&lt;/h4&gt;

&lt;p&gt;Business data is usually stored in multiple tables.&lt;br&gt;
SQL allows analysts to combine these tables using joins. Joined datasets in SQL can simplify the data model.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sales_amount&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;
&lt;span class="k"&gt;JOIN&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;
&lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="k"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why this is important:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Combines related data into one dataset&lt;/li&gt;
&lt;li&gt;Reduces the need for complex relationships in Power BI&lt;/li&gt;
&lt;li&gt;Makes analysis easier&lt;/li&gt;
&lt;li&gt;Prevents duplication errors&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Data Cleaning and Preparation
&lt;/h4&gt;

&lt;p&gt;Raw data is often messy. It may contain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Missing values&lt;/li&gt;
&lt;li&gt;Duplicate records&lt;/li&gt;
&lt;li&gt;Incorrect formats&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;SQL helps clean and prepare the data before it is loaded into Power BI hence leading to better insights.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Eliminating duplicates&lt;/span&gt;

&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="k"&gt;DISTINCT&lt;/span&gt; &lt;span class="n"&gt;customer_id&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;--Handling missing values&lt;/span&gt;

&lt;span class="k"&gt;SELECT&lt;/span&gt; 
  &lt;span class="n"&gt;COALESCE&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;phone_number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Not Provided'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;phone&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;customers&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why data cleaning matters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensures data accuracy&lt;/li&gt;
&lt;li&gt;Improves report reliability&lt;/li&gt;
&lt;li&gt;Reduces cleaning work in Power BI&lt;/li&gt;
&lt;li&gt;Prevents errors in calculations&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Creating Calculated Fields
&lt;/h4&gt;

&lt;p&gt;SQL allows analysts to create new columns based on existing data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="c1"&gt;-- Calculate total sales&lt;/span&gt;

&lt;span class="k"&gt;SELECT&lt;/span&gt; 
  &lt;span class="n"&gt;product_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;price&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;total_sales&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why calculated fields are useful:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prepares key metrics before loading&lt;/li&gt;
&lt;li&gt;Reduces need for DAX calculations&lt;/li&gt;
&lt;li&gt;Keeps logic centralized in the database&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Supporting Advanced Analysis
&lt;/h4&gt;

&lt;p&gt;SQL also supports more advanced operations such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Window functions (running totals, ranking)&lt;/li&gt;
&lt;li&gt;Subqueries&lt;/li&gt;
&lt;li&gt;Common Table Expressions (CTEs)&lt;/li&gt;
&lt;li&gt;Data transformations
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; 
  &lt;span class="n"&gt;sale_date&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="k"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sales_amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;OVER&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;ORDER&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="n"&gt;sale_date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;running_total&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;sales&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Power BI is a powerful tool that helps organizations transform raw data into meaningful insights. By connecting directly to SQL databases, Power BI allows analysts to access structured data stored in business systems and convert it into interactive dashboards and reports.&lt;br&gt;
SQL prepares the foundation, and Power BI builds the story on top of it. Strong SQL skills allow analysts to work more efficiently, produce accurate reports, and deliver better insights for decision-making.&lt;br&gt;
When SQL and Power BI are used together, they provide a powerful combination for modern data analysis and business intelligence.&lt;/p&gt;

</description>
      <category>luxdev</category>
      <category>dataengineering</category>
      <category>sql</category>
      <category>database</category>
    </item>
    <item>
      <title>Mastering SQL Joins and Window Functions</title>
      <dc:creator>Lawrence Murithi</dc:creator>
      <pubDate>Tue, 03 Mar 2026 10:36:56 +0000</pubDate>
      <link>https://forem.com/lawrence_murithi/mastering-sql-joins-and-window-functions-1f30</link>
      <guid>https://forem.com/lawrence_murithi/mastering-sql-joins-and-window-functions-1f30</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;SQL (Structured Query Language) is a powerful tool used to search, manage, and analyze large amounts of data. It is widely used by data enthusiasts, software developers and even marketing professionals.&lt;br&gt;
In real-world databases, data is not stored in one large table. It is divided into multiple related tables. This makes storage efficient and avoids duplication. To work effectively with such data, you must understand SQL joins and window functions. These two features allow you to combine data correctly and perform advanced analysis without losing important details.&lt;/p&gt;
&lt;h2&gt;
  
  
  SQL Joins
&lt;/h2&gt;

&lt;p&gt;A JOIN in SQL is used to combine rows from two or more tables based on a related column. This relationship is usually created using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A primary key (unique identifier in one table)&lt;/li&gt;
&lt;li&gt;A foreign key (reference to that key in another table)
Joins are essential when working with relational databases because data is often split across multiple tables.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Importance of Joins
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Combining related data from multiple tables&lt;/li&gt;
&lt;li&gt;Maintaining relational integrity&lt;/li&gt;
&lt;li&gt;Supporting one-to-many and many-to-many relationships&lt;/li&gt;
&lt;li&gt;Building meaningful reports and analytics&lt;/li&gt;
&lt;li&gt;Preventing unnecessary duplication of data&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The type of join you use directly affects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The number of rows returned&lt;/li&gt;
&lt;li&gt;Whether NULL values appear&lt;/li&gt;
&lt;li&gt;How business logic is interpreted
NB: Choosing the wrong join can lead to missing data, duplicated records, or incorrect analysis.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Types of SQL Joins
&lt;/h3&gt;
&lt;h4&gt;
  
  
  INNER JOIN
&lt;/h4&gt;

&lt;p&gt;The INNER JOIN returns only the rows that have matching values in both tables.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Combines records based on a related column&lt;/li&gt;
&lt;li&gt;Returns only matching rows&lt;/li&gt;
&lt;li&gt;Excludes non-matching rows
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fijwwf41l1fwvnmt9kowo.jpg" alt="Inner Join" width="800" height="106"&gt;
INNER JOIN is used when:&lt;/li&gt;
&lt;li&gt;You only need matched data&lt;/li&gt;
&lt;li&gt;You want to exclude incomplete relationships&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  LEFT (OUTER) JOIN
&lt;/h4&gt;

&lt;p&gt;The LEFT (OUTER) JOIN returns:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All rows from the left table&lt;/li&gt;
&lt;li&gt;Matching rows from the right table&lt;/li&gt;
&lt;li&gt;NULL values if no match exists
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fftfmhtuhwawp91s4otip.jpg" alt="Left Join" width="800" height="86"&gt;
LEFT JOIN is used when:&lt;/li&gt;
&lt;li&gt;You want all records from the main table&lt;/li&gt;
&lt;li&gt;You want to identify missing matches&lt;/li&gt;
&lt;li&gt;You need complete reporting from one side&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  RIGHT (OUTER) JOIN
&lt;/h4&gt;

&lt;p&gt;The RIGHT (OUTER) JOIN returns:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All rows from the right table&lt;/li&gt;
&lt;li&gt;Matching rows from the left table&lt;/li&gt;
&lt;li&gt;NULL where no match exists on the left
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjn4qq9vkqqibun7ys4i9.jpg" alt="Right Join" width="800" height="84"&gt;
NB: RIGHT JOIN works like LEFT JOIN but from the opposite direction.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  FULL (OUTER) JOIN
&lt;/h4&gt;

&lt;p&gt;The FULL JOIN returns:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All rows from both tables&lt;/li&gt;
&lt;li&gt;Matching records where possible&lt;/li&gt;
&lt;li&gt;NULL values where no match exists
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk7lesr3ojfu51sn1gj8g.jpg" alt="Full Join" width="800" height="84"&gt;
The FULL JOIN is used when:&lt;/li&gt;
&lt;li&gt;Comparing two datasets&lt;/li&gt;
&lt;li&gt;Identifying differences between systems&lt;/li&gt;
&lt;li&gt;Performing reconciliation tasks&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  CROSS JOIN
&lt;/h4&gt;

&lt;p&gt;A CROSS JOIN returns all possible combinations of rows thus can create very large results.&lt;br&gt;
If Table A has 5 rows and Table B has 10 rows:&lt;br&gt;
Result = 50 rows.&lt;br&gt;
It does not use a matching condition.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftbk5gfm1fjjiemhjcp68.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftbk5gfm1fjjiemhjcp68.jpg" alt="Cross Join" width="800" height="112"&gt;&lt;/a&gt;&lt;br&gt;
A CROSS JOIN is used to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generate combinations&lt;/li&gt;
&lt;li&gt;Create calendar expansions&lt;/li&gt;
&lt;li&gt;Test scenarios&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  SELF JOIN
&lt;/h4&gt;

&lt;p&gt;A self join joins a table to itself. Aliases are used to refer to the same tale&lt;br&gt;
Example:&lt;br&gt;
Employee table:&lt;br&gt;
| EmployeeID | ManagerID |&lt;br&gt;
To show each employee and their manager name, the table is joined to itself.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxkfb28zynixzjr1xj2wm.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxkfb28zynixzjr1xj2wm.jpg" alt="Self Join" width="800" height="103"&gt;&lt;/a&gt;&lt;br&gt;
Self joins are useful for hierarchical data.&lt;/p&gt;
&lt;h4&gt;
  
  
  NATURAL JOIN
&lt;/h4&gt;

&lt;p&gt;A natural join Joins all tables using columns that have the same name.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq7932nmokz5hfoco4y1k.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq7932nmokz5hfoco4y1k.jpg" alt="Natural Join" width="800" height="47"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Performance Considerations for Joins.
&lt;/h3&gt;

&lt;p&gt;Joins can affect performance, especially in large databases.&lt;br&gt;
Best practices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Index join columns (primary and foreign keys)&lt;/li&gt;
&lt;li&gt;Avoid unnecessary joins&lt;/li&gt;
&lt;li&gt;Filter data early using WHERE&lt;/li&gt;
&lt;li&gt;Understand execution plans&lt;/li&gt;
&lt;li&gt;Be careful with joins that multiply rows unintentionally&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Improper joins can cause:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Duplicate results&lt;/li&gt;
&lt;li&gt;Data inflation&lt;/li&gt;
&lt;li&gt;Slow query execution&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Window Functions
&lt;/h2&gt;

&lt;p&gt;Window functions allow us to perform advanced calculations across a group of related rows while keeping the original data. They are useful for ranking, running totals, moving averages, and analytical reporting.&lt;br&gt;
Window functions often remove the need for complex self-joins and provide an analytical layer within SQL.&lt;br&gt;
Window functions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Keep every row&lt;/li&gt;
&lt;li&gt;Add calculated values to each row&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Structure of a window function:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT column_1,
       function() OVER (
           PARTITION BY column
           ORDER BY column
       ) AS output_column
FROM table_name;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h4&gt;
  
  
  1.  OVER()
&lt;/h4&gt;

&lt;p&gt;The OVER() clause defines how the window function operates and controls:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Partitioning&lt;/li&gt;
&lt;li&gt;Ordering&lt;/li&gt;
&lt;li&gt;Optional frame boundaries&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  2.  PARTITION BY()
&lt;/h4&gt;

&lt;p&gt;The PARTITION BY divides rows into logical groups. If omitted, the entire dataset is treated as one group.&lt;/p&gt;
&lt;h4&gt;
  
  
  3.  ORDER BY()
&lt;/h4&gt;

&lt;p&gt;ORDER BY defines the sequence of rows inside each partition.&lt;/p&gt;

&lt;p&gt;It is essential for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ranking&lt;/li&gt;
&lt;li&gt;Running totals&lt;/li&gt;
&lt;li&gt;Time-based comparisons&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If ORDER BY is omitted, row processing order is undefined.&lt;/p&gt;
&lt;h4&gt;
  
  
  4. Frame Clause (ROWS vs RANGE)
&lt;/h4&gt;

&lt;p&gt;Used to define a range of rows(boundary) and commonly used for moving averages and cumulative calculations.&lt;br&gt;
In the ROWS subclause, the frame is defined by beginning and ending row positions while in the RANGE subclause, the frame is defined by a value range.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ROWS BETWEEN lower_bound AND upper_bound
RANGE BETWEEN lower_bound AND upper_bound
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Types of SQL Window Functions
&lt;/h3&gt;

&lt;p&gt;Window functions fall into three main categories.&lt;/p&gt;

&lt;h4&gt;
  
  
  1. Aggregate Window Functions
&lt;/h4&gt;

&lt;p&gt;These include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AVG() - Calculates moving averages.&lt;/li&gt;
&lt;li&gt;SUM() - Creates running totals.&lt;/li&gt;
&lt;li&gt;COUNT() - calculates the number of items found in a group.&lt;/li&gt;
&lt;li&gt;MIN() - returns the minimum value.&lt;/li&gt;
&lt;li&gt;MAX() - returns the maximum value.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some use cases of Aggregate window functions include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Department totals&lt;/li&gt;
&lt;li&gt;Running totals&lt;/li&gt;
&lt;li&gt;Moving averages&lt;/li&gt;
&lt;li&gt;Cumulative metrics&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  2. Ranking Window Functions
&lt;/h4&gt;

&lt;p&gt;They are used to assign position or rank.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ROW_NUMBER() - Assigns a unique number to each row. &lt;/li&gt;
&lt;li&gt;RANK() - Assigns rank with gaps when ties exist.&lt;/li&gt;
&lt;li&gt;DENSE_RANK() - Similar to RANK but does not skip numbers and better for ranking reports where gaps are not desired.&lt;/li&gt;
&lt;li&gt;PERCENT_RANK() - calculates the relative rank of a row within a group of rows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some use cases of Ranking window functions include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Top N per group&lt;/li&gt;
&lt;li&gt;Performance ranking&lt;/li&gt;
&lt;li&gt;Leaderboards&lt;/li&gt;
&lt;li&gt;Percentile analysis&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  3. Offset (Value) Window Functions
&lt;/h4&gt;

&lt;p&gt;They are used to access data from other rows.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LAG() - shows previous row value and used in time-based analysis.&lt;/li&gt;
&lt;li&gt;LEAD() - shows next row value and used in time-based analysis.&lt;/li&gt;
&lt;li&gt;FIRST_VALUE() - returns the first value in an ordered set of values within a partition.&lt;/li&gt;
&lt;li&gt;LAST_VALUE() - returns the last value in an ordered set of values within a partition.&lt;/li&gt;
&lt;li&gt;NTH_VALUE() - Divides rows into equal groups and useful in performance analysis and segmentation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some use cases of Offset window functions are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Month-over-month growth&lt;/li&gt;
&lt;li&gt;Time-series comparison&lt;/li&gt;
&lt;li&gt;Trend detection&lt;/li&gt;
&lt;li&gt;Sequential analysis&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;SQL joins and window functions are core tools for designing efficient and powerful queries.&lt;br&gt;
Joins allow you to combine data from multiple tables using defined relationships while Window functions provide an advanced analytical layer in SQL.&lt;/p&gt;

</description>
      <category>luxdev</category>
      <category>sql</category>
      <category>dataengineering</category>
    </item>
  </channel>
</rss>
