<?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>DEV Community: Muhammad Adnan Khan</title>
    <description>The latest articles on DEV Community by Muhammad Adnan Khan (@adnankhanxx).</description>
    <link>https://dev.to/adnankhanxx</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%2F1053059%2F72290f36-e238-4e3b-be9c-d07c24b849c6.jpg</url>
      <title>DEV Community: Muhammad Adnan Khan</title>
      <link>https://dev.to/adnankhanxx</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adnankhanxx"/>
    <language>en</language>
    <item>
      <title>AWS Kinesis - Stream Storage Layer</title>
      <dc:creator>Muhammad Adnan Khan</dc:creator>
      <pubDate>Mon, 29 Jan 2024 10:17:42 +0000</pubDate>
      <link>https://dev.to/aws-builders/aws-kinesis-stream-storage-layer-mi0</link>
      <guid>https://dev.to/aws-builders/aws-kinesis-stream-storage-layer-mi0</guid>
      <description>&lt;p&gt;In this blog post, we will discuss the AWS Kinesis data stream service to understand the high-level overview of the service, architecture, core components, and the use case of the AWS Kinesis service.&lt;/p&gt;

&lt;p&gt;AWS kinesis has the following sub-services:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;AWS kinesis Data Stream (KDS)&lt;/li&gt;
&lt;li&gt;AWS Kinesis Data Firehose&lt;/li&gt;
&lt;li&gt;AWS Kinesis Data Analytics&lt;/li&gt;
&lt;li&gt;AWS Kinesis Video Stream&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv78icb6ip4x4ajxada0h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv78icb6ip4x4ajxada0h.png" alt="Kinesis Layers" width="800" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our primary discussion would be around the Kinesis Data Stream the stream storage layer, will discuss the overview, the architecture, and other necessary details.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AWS Kinesis Data Stream (KDS)&lt;/strong&gt;&lt;br&gt;
KDS is a scalable service that scales elastically and near-real-time processing of streaming big data. It's a data ingestion layer that stores the value from 24 hours up to 8760 hours (365 days), by default it's 24 hours. Data inside the KDS is immutable once stored cannot modified, and the stored data cannot be removed from it until it expires.&lt;/p&gt;

&lt;p&gt;The KDS is composed of two layers.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Storage Layers&lt;/li&gt;
&lt;li&gt;Processing Layers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;1. Storage Layers&lt;/strong&gt;&lt;br&gt;
Is responsible for storing and managing the incoming data stream temporarily before it goes for further processing in the processing layer.&lt;br&gt;
&lt;strong&gt;2. Processing Layer&lt;/strong&gt;&lt;br&gt;
This layer is fed by the storage layer and is responsible for analyzing and transforming the data in real-time or near-real time. After processing the processing layer is responsible for notifying the storage layer to delete the data that is no longer needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Kinesis Data Stream - Architecture&lt;/strong&gt;&lt;br&gt;
A KDS is composed of the components which we will discuss one by one and how they correlate with one another.&lt;br&gt;
A KDS is composed of one or more shards.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Shards&lt;/strong&gt;: contains the sequence of data records that supports 5 transactions per second, The total data write rate of 1MB/S or 1000 messages per second whereas the data read rate is 2 MB/S.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data Records&lt;/strong&gt;: is composed of the Sequence ID, Partition key, and data blob.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fucie57ujq6vof250i3hn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fucie57ujq6vof250i3hn.png" alt="Inside Shard Story" width="800" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The partition key inside the data records decides to which shard the data will go and the blob is nothing but the original data itself.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: The sequence ID will be unique inside the partition.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fando30ui5lwc7tdolufc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fando30ui5lwc7tdolufc.png" alt="AWS Kinesis Data Stream - Architecture by [AWS](https://www.amazon.com/)" width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;producer&lt;/strong&gt; will put the records into the data stream.&lt;br&gt;
&lt;strong&gt;Consumers&lt;/strong&gt; will get the records from the data stream also known as the KDS applications.&lt;/p&gt;

&lt;p&gt;The consumer applications generally run on a fleet of EC2 instances. There are two types of consumers in KDS:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Classic/Shared Fan-out consumers (SFO)&lt;/li&gt;
&lt;li&gt;Enhanced Fan-out consumers (EFO)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The SFO works on the Poll/Pull mechanism where it extracts the records from the shard, whereas the EFO works on the push mechanism the consumer subscribes to the shard and the shard automatically pushes the data into the consumer application.&lt;br&gt;
The default throughput of each shard in 2MB/s in shared fan-out all the consumers will share the same throughput of 2 MB/S but in Enhanced Fan-out each consumer will receive its own throughput of 2 MB/S. Suppose we have 5 consumers all of them are reading the data from Shard1 then in SFO the 5 consumers will get the throughput of 2 MB/s but in EFO the 5 consumers will get the 10 MB/S as each one will have separate 2 MB/S.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EFO vs SFO characteristics&lt;/strong&gt;&lt;br&gt;
The EFO has a latency of 70ms which will be the same for all the consumers while the SFO has around 200ms and will increase with each consumer for example if there are 5 consumers then in EFO the latency will remain at 70ms but in EFO the latency can increase up to 1000ms. In EFO the maximum consumer limit can be up to 20, in SFO the limitation is up to 5 consumers. The cost of EFO is also higher compared to the SFO. The records delivery model in SFO is using HTTP while in EFO HTTP/2 is used.&lt;br&gt;
Now we get the high-level overview of the Amazon Kinesis Data Stream service. Let's discuss the pricing model of the KDS now.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pricing KDS&lt;/strong&gt;&lt;br&gt;
The following are the points you should consider while using the KDS service for which you'll be charged.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There's an hourly charge incurred based on the number of shards.&lt;/li&gt;
&lt;li&gt;Separate charges when the producer puts the data in the stream.&lt;/li&gt;
&lt;li&gt;Charge based on per hour, when the data retention period is extended from the default 24 hours.&lt;/li&gt;
&lt;li&gt;If Enhanced Fan-out is being used, charges are based on the amount of data and the number of consumers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/streams/latest/dev/introduction.html"&gt;https://docs.aws.amazon.com/streams/latest/dev/introduction.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.com/Data-Engineering-AWS-Gareth-Eagar/dp/1800560419"&gt;https://www.amazon.com/Data-Engineering-AWS-Gareth-Eagar/dp/1800560419&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>kinesis</category>
      <category>awsbigdata</category>
      <category>stream</category>
      <category>dataengineering</category>
    </item>
    <item>
      <title>Data Evolution - Databases to Data Lakehouse</title>
      <dc:creator>Muhammad Adnan Khan</dc:creator>
      <pubDate>Fri, 19 Jan 2024 12:14:16 +0000</pubDate>
      <link>https://dev.to/aws-builders/data-evolution-databases-to-data-lakehouse-d0j</link>
      <guid>https://dev.to/aws-builders/data-evolution-databases-to-data-lakehouse-d0j</guid>
      <description>&lt;p&gt;In this blog post, we will discuss the evolution of the data and data analytics solution and how fast things have changed recently. We will discuss all the details from the granular details to better understand the concepts later on.&lt;br&gt;
&lt;strong&gt;Data in new oil!&lt;/strong&gt;&lt;br&gt;
Let's first understand what data is. how it become useful for many organizations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data&lt;/strong&gt; is a term that is often used to describe the information that can be in some stored format and can be transmitted. It can be in the form of text, number, or some fact.&lt;/p&gt;

&lt;p&gt;It not just a new term, but it has been used by our ancients in different forms either in the form of oral tradition, in paper written form, or can be in any electronic form stored somewhere.&lt;br&gt;
Before the invention of writing, people carried information in some oral form, in the form of stories, knowledge, and history transferred from generation to generation. Later on, this fashion was converted into written form on stones and leathers, and with the invention of the printing press in the 15th century the information was stored in books and documents. This thing keeps changing with time from the printing press to library catalogs, then punch cards, early computers, databases and now we are in the era of big data where everyone has a personal device where each click generates data and that's stored somewhere in the world. &lt;br&gt;
Around 328.77 million TBs of data is generated each day which is around 120 Zettabytes in 2023 and expected to raise 180 Zettabytes by 2025.&lt;/p&gt;

&lt;h2&gt;
  
  
  Welcome to the world of data
&lt;/h2&gt;

&lt;p&gt;Now you have the history of data and how fast it has evolved, with all this evolution many organizations utilized it for different purposes to get the edge over competitors.&lt;br&gt;
The data generated by you, are used by the organizations to generate profit. Every industry is using it whether it's some social media platform, the e-commerce store, or some movie platform. They track the history of data, analyze the patterns and make recommendations to the user to keep them engaged in their platform and sell their content or product. It's not just these industries the data has use cases in healthcare, oil &amp;amp; gas, pharma, and many other industries you name.&lt;br&gt;
This is why the data is called the new oil, it drives the world.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Big Data Era
&lt;/h2&gt;

&lt;p&gt;The journey of data processing and analytics systems has evolved over several decades. In the 1980s, where data would be processed in nightly runs in batch streams.&lt;br&gt;
with the increase in the use of databases, the organizations found themselves in tens or even hundreds of databases, supporting the business. These databases were transactional databases or OLTP. As a result, in 1990s the data warehousing comes into the picture for analytical purposes.&lt;br&gt;
The early 21st century witnessed the era of big data when the data was growing exponentially and in different formats structured, unstructured, and semi-structured by modern digital platforms mobiles, web, sensors, IoT devices, social media, and many others, which need to be stored somewhere to perform the analysis. Well, at that time in the early 2010s, a new technology for big data processing became popular. Hadoop is an open-source framework for processing large-scale datasets on clusters of computers. These clusters contain machines with an attached disk that manages the terabytes of data under a single distributed file system Hadoop distributed file system (HDFS). The main bottleneck of these on-prem systems Hadoop and Spark is scalability, which requires a high upfront payment, along with other factors like latency, hardware management, and complexity factors.&lt;br&gt;
During this time, the cloud-based &lt;strong&gt;data warehouses&lt;/strong&gt; (Redshift, Big query, Snowflake, and Synapse) came into the picture which involved fewer managerial tasks and resolved the issues of scalability and latency and usage-based cost model.&lt;br&gt;
After that, the trend of the modern data stack started to evolve into a &lt;strong&gt;data lake architecture&lt;/strong&gt; that comes with high durability, inexpensive, and limitless cloud object stores. Where you can store any type of data without any transformation. Data lakes become the single source of truth for organizations. In this approach, all the data is ingested into the data lake, and a hot subset of data is moved from the data lake to the data warehouse to support low latency.&lt;br&gt;
By integrating the best capabilities of both the data warehouse and data lake a new architecture came into the picture called &lt;strong&gt;data Lakehouse&lt;/strong&gt;. which overcame the bottlenecks of the data lake and data warehouse like supporting any type of data, supporting ACID transactions, and low latency which the data lake can't support.&lt;/p&gt;

&lt;p&gt;Now let's discuss each of the defined above and the associated services used in AWS.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;OLTP&lt;/strong&gt; (Online Transaction Processing)&lt;br&gt;
is a source system where the business transactions are stored.&lt;br&gt;
AWS Service: RDS, Aurora, DynamoDB and other services&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;OLAP&lt;/strong&gt; (Online Analytical Processing)&lt;br&gt;
 the systems used for analytical purposes.&lt;br&gt;
AWS Service: AWS Redshift&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;*&lt;em&gt;ETL *&lt;/em&gt;(Extract Transform Load)&lt;br&gt;
used to transfer the data from OLTP to OLAP system.&lt;br&gt;
AWS Services: AWS Glue and AWS Pipeline&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data warehouse&lt;/strong&gt;&lt;br&gt;
Is a single source of truth to store the structure-only data with ACID properties, used for analytical purposes.&lt;br&gt;
AWS Service: Redshift&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data lake&lt;/strong&gt;&lt;br&gt;
is a central repository to store the data from multiple source systems in any structure, it doesn't support ACID transactions and has high latency.&lt;br&gt;
AWS Service: S3 &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Lakehouse&lt;/strong&gt;&lt;br&gt;
combination of data warehouse and data lake best capabilities with support of ACID and low latency with support to store any type of data.&lt;br&gt;
AWS Service: Redshift Spectrum and Lake Formation.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Will continue the series to explore each of the AWS Services mentioned above in depth the architecture, the working mechanism, and how to use multiple services to build a data warehouse, data lake, and data Lakehouse by using AWS.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>dataengineering</category>
      <category>database</category>
      <category>datalake</category>
    </item>
    <item>
      <title>DBT + REDSHIFT = ❤</title>
      <dc:creator>Muhammad Adnan Khan</dc:creator>
      <pubDate>Mon, 27 Mar 2023 17:30:11 +0000</pubDate>
      <link>https://dev.to/aws-builders/dbt-redshift--3ci4</link>
      <guid>https://dev.to/aws-builders/dbt-redshift--3ci4</guid>
      <description>&lt;p&gt;In recent time you have heard about the DBT (Data Build Tool) a lot, Let's explore the power of the DBT with Amazon Redshift. We will develop the Data pipelines using DBT, Redshift as our data warehouse and Power BI for visualization.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is DBT?&lt;/strong&gt;&lt;br&gt;
Let's first understand what exactly DBT is and its use case.&lt;br&gt;
Data Build Tool aka DBT is an open-source tool that helps you in applying transformation using the best practices of Analytics engineering.&lt;br&gt;
I'm not going to explain the terms Extract Transform Load (ETL) and Extract Load Transform (ELT) I assume that you're familiar with these terms. The Transformation step in being applied in DBT.&lt;br&gt;
There're two ways to access DBT.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;DBT Core&lt;/li&gt;
&lt;li&gt;DBT Cloud&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you're GUI kind of person go with DBT cloud and if you love to work with terminals, then go with DBT Core. However, the Commands would not be that difficult familiarity with basic commands like ls, cd, pwd and some dbt commands are enough to work. For this project I'll go with DBT Core.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Redshift&lt;/strong&gt;&lt;br&gt;
Redshift is a cloud-based warehouse service provided by Amazon. It uses a Massive Parallel Processing (MPP) architecture, which distribute the data and processing across multiple nodes to improve query performance.&lt;/p&gt;

&lt;p&gt;Photo by Daniel Josef on Unsplash&lt;/p&gt;

&lt;p&gt;It contains the cluster which is composed of leader and compute nodes you can further read about its architecture in detail here.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fdpfou5vldcaapuaskjft.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fdpfou5vldcaapuaskjft.png" alt="Redshift architecture by Hevo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Power BI&lt;/strong&gt;&lt;br&gt;
Power BI is business intelligence tool by Microsoft. You can highly interactive visualization by just drag and drop. Provides plenty of data connection options as well.&lt;br&gt;
If you're interested in Power BI you can further learn about it here.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dataset&lt;/strong&gt;&lt;br&gt;
The dataset I'm using is the Sakila database. You can find the scripts to create tables and insert data to tables in following repository.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: These scripts are specific to Amazon Redshift. Probably these scripts will throw an error on other databases.&lt;/p&gt;

&lt;p&gt;1- &lt;strong&gt;Create environment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;you should create a specific python environment for this project in order to avoid any conflicts.&lt;br&gt;
If you don't have virtualenv library already installed, then run.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip install virtualenv&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In order to create a virtual environment, you can run the following command.&lt;/p&gt;

&lt;p&gt;python -m venv &lt;/p&gt;

&lt;p&gt;to activate the environment, run&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;environment-name&amp;gt;/Scripts/activate.bat&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once the environment activated, the environment name will appear in your command line before the path.&lt;br&gt;
Environment Activation&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The commands differ for different OS, the above-mentioned commands are specific to windows.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;2- &lt;strong&gt;DBT installation &lt;/strong&gt;&lt;br&gt;
It's time to install the DBT, before installation of DBT make sure you've Python version 3.7 or above it doesn't support version below 3.7 as per their documentation, may be these changes with time to time. you can read about the supported versions here.&lt;br&gt;
We're using the redshift so we will use the redshift adapter, if you're planning to use some other adapter then command will vary accordingly. if you're going along run the following command for redshift&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip install dbt-redshift&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Most of the things are handled by the DBT on its own related to the project you can create or initialize a project by just running the command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dbt init&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The above command will create a project along with the boilerplate. easy peasy right? okay then what's next.&lt;/p&gt;

&lt;p&gt;3-&lt;strong&gt;RedShift Cluster Setup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before preceding next, we will setup our Amazon Redshift cluster and allow the public accessibility. Public accessibility isn't recommended you can use the VPC but for demo purposes we can proceed.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create Redshift cluster.&lt;/li&gt;
&lt;li&gt;Add inbound rules in security&lt;/li&gt;
&lt;li&gt;Allow accessibility&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once the cluster is setup, open the cluster properties of the cluster note down the Endpoint and connect it locally, I already have aqua data studio, so I connected through it.&lt;br&gt;
Connection to Redshift&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Redshift cost varies by different factor, so make sure to create a billing alert, so you can receive updates regarding the cost. Furthermore, you can read here.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once you connected to your warehouse then create a schema called stg inside database and run the scripts of tables creation and insertion, the repository of the scripts is mentioned above.&lt;br&gt;
Now you've the data in staging layer and you want to load it into warehouse. The data is already cleansed so there's no need to introduce the transformation layer between staging and target layer.&lt;/p&gt;

&lt;p&gt;As per the requirements of the clients we have to decide to go with sort of Galaxy schema.&lt;/p&gt;

&lt;p&gt;Model Time to build models but ML models, I'm talking about the DBT models where you define your core logic. Inside the Models directory create two sub directories for dimension and fact. In each sub-directory create a schema.yml file. &lt;/p&gt;

&lt;p&gt;This schema file contains the information about the source and contain some tests. This is how the schema file for customer dimension will look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: 2

models:
  - name: dim_customer
    description: "Dim customer to join customer with city,address and country"
    columns:
      - name: customer_id
        description: "The primary key for this table"
        tests:
          - unique
          - not_null

sources:
  - name: stg
    database: dev
    schema: stg
    tables:
      - name: customer
      - name: address
      - name: city
      - name: country
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The best practice while developing your model is to use Common Table Expression (CTE) as it enhances the readability of the code though it's not necessary.&lt;br&gt;
Now let's create a customer dim which contains the details of the customer, the details from address,city and country source tables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;with customer_base as(
    SELECT *,
    CONCAT(CONCAT(customer.FIRST_NAME,' '),customer.LAST_NAME)  AS FULL_NAME,
    SUBSTRING(customer.EMAIL FROM POSITION('@' IN customer.EMAIL)+1 FOR CHAR_LENGTH(customer.EMAIL)-POSITION('@' IN EMAIL)) AS DOMAIN,
    customer.active::int as ACTIVE_INT,
    CASE WHEN customer.ACTIVE=0 then 'no' else 'yes' end as ACTIVE_DESC,
    '{{ run_started_at.strftime("%Y-%m-%d %H:%M:%S")}}' as DBT_TIME
    FROM
    {{ source('stg','customer')}} as customer

),
address as (
    SELECT * FROM
    {{ source('stg','address')}}

),
city as (
    SELECT * FROM
    {{ source('stg','city')}}

),
country as (
    SELECT * FROM
    {{ source('stg','country')}}

)

SELECT 
customer_base.CUSTOMER_ID,
customer_base.STORE_ID,
customer_base.FIRST_NAME,
customer_base.LAST_NAME,
customer_base.FULL_NAME,
customer_base.EMAIL,
customer_base.DOMAIN,
customer_base.ACTIVE_INT AS ACTIVE,
customer_base.ACTIVE_DESC,
customer_base.create_date,
customer_base.last_update,
customer_base.DBT_TIME,

address.ADDRESS_ID::INT,
address.address,
city.city_id,
city.city,
country.country_id,
country.country

FROM customer_base

LEFT JOIN ADDRESS AS address
 ON customer_base.address_id= address.address_id

LEFT JOIN CITY AS city
 ON address.city_id=city.city_id

LEFT JOIN COUNTRY AS country
 ON country.country_id=city.country_id
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how the models are defined is DBT and in parallel if you open your project.yml file at the very bottom of the file it contains the detail about models that how the tables will be materialized.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;models:
  project:
    # Config indicated by + and applies to all files under models/example/
    example:
      +materialized: view

    dimension:
      +materialized: table
      +schema: dwh

    fact:
      +materialized: incremental
      +schema: dwh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The properties define inside the models has more preference than the one defined in project.yml&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Similarly, like customer dimension we defined other dimensions and facts however the facts are materialized incrementally so that it can save cost while rerunning the models again and again, as fact has large number of records.&lt;br&gt;
Now you defined all the models and your target destination in the DBT profile it's time to run the models. To run the models hit the following command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dbt run -m dimensions&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This command will run all the models in dimensions directory. However, if you want to run the specific model then try this command.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dbt run -s model_name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once you run this command and everything is defined correctly then data will be inserted into your target directory dwh in my case.&lt;br&gt;
That's how you can build your DBT pipeline. If you have good knowledge of SQL and a bit of Python, then you are good to develop complex pipelines on your own.&lt;/p&gt;

&lt;p&gt;Finally, our warehouse is ready, users can now perform the analysis as per their requirements. Now there's requirement from the user to build a dashboard upon that cleansed data. We have access to Power BI desktop. In order to make a connection with Redshift we have to provide the following details in Power BI.&lt;/p&gt;

&lt;p&gt;server-name: End point of your Redshift&lt;br&gt;
Database: dbname&lt;br&gt;
username: username&lt;br&gt;
password: password&lt;/p&gt;

&lt;p&gt;Once you provide the following details then you'll either direct query the source or can import the tables. In import tables, data is cached inside Power BI and in direct query, it'll directly hit the source to fetch data. &lt;/p&gt;

&lt;p&gt;Now you can play around and build an amazing dashboard for your user. for the demo purpose I've built this, but it can far improve by utilizing the DAX functions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fj3u0ww9qcsqij6ayu2yo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fj3u0ww9qcsqij6ayu2yo.png" alt="Power BI Desktop"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find the code related to the project codes &lt;a href="https://github.com/Adnan-Khanx/Sakila_dbt" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That's it, Tada :D.&lt;/p&gt;

&lt;p&gt;Conclusions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a separate environment for the project, choose your adopter beforehand.&lt;/li&gt;
&lt;li&gt;Define the tests and documentations&lt;/li&gt;
&lt;li&gt;Run individual models if you're working on cloud, it can add cost if you run all the models&lt;/li&gt;
&lt;li&gt;Modularize your logic, so you use the same logic at multiple places by reference.&lt;/li&gt;
&lt;li&gt;The property defined inside model holds more value than defined inside &lt;em&gt;project.yml&lt;/em&gt; file, it basically overwrites those properties&lt;/li&gt;
&lt;li&gt;Go for incremental materialization, if your data is quite large.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>aws</category>
      <category>redshift</category>
      <category>dbt</category>
      <category>powerbi</category>
    </item>
  </channel>
</rss>
