alanchn31/Movalytics-Data-Warehouse
alanchn31/Movalytics-Data-Warehouse has 167 GitHub stars and 37 forks. GitHot measured 0 stars in 24 hours, 0 in 7 days, and 0 in 15 days. Last checked 2026-11-11 11:59 UTC. Last push 2020-06-16.
Data pipeline performing ETL to AWS Redshift using Spark, orchestrated with Apache Airflow
측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalMovalytics
Project Description
This project is a case study for a start-up, involved with recommending movies to users as a service, as well as investigating certain factors contributing to the success of movies.
The aim of this project, is to perform Extract, Transform, Load, on movies data, to answer questions the business may have about its users, such as:
- What is the highest rated movie of all time?
- Which genre of movies are the most popular with users?
- Trends in box office earnings - Does releasing a movie at a certain quarter/month of a year, lead to higher box office earnings?
- Which genres are the highest earning of all-time, normalized against a consumer price index?
The movies data and metadata comes from Movielens, extracted from a Kaggle dataset: https://www.kaggle.com/rounakbanik/the-movies-dataset. The data contains 26 million user ratings of over 270,000 users on a collection of over 45,000 movies.
In addition, Consumer Price Index of Admission to Movies, Theaters, and Concerts in U.S. City Average is extracted from: https://fred.stlouisfed.org/series/CUSR0000SS62031. This will help us normalize box office earnings against inflation over the years.
Architecture
The technical architecture for this project is as show below:
- Data Extraction is done using Kaggle API and using GET request to St Louis Fred's CPI dataset.
Set up an EC2 instance with python and pip installed. Then, runpip install kaggle. To download the movielens dataset, run
kaggle datasets download -d "rounakbanik/the-movies-dataset"
For St Louis Fred's Consumer Price Index dataset, run
wget https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23e1e9f0&chart_type=line&drp=0&fo=open%20sans&graph_bgcolor=%23ffffff&height=450&mode=fred&recession_bars=on&txtcolor=%23444444&ts=12&tts=12&width=1168&nt=0&thu=0&trc=0&show_legend=yes&show_axis_titles=yes&show_tooltip=yes&id=CUSR0000SS62031&scale=left&cosd=1999-01-01&coed=2020-04-01&line_color=%234572a7&link_values=false&line_style=solid&mark_type=none&mw=3&lw=2&ost=-99999&oet=99999&mma=0&fml=a&fq=Monthly&fam=avg&fgst=lin&fgsnd=2009-06-01&line_index=1&transformation=lin&vintage_date=2020-05-31&revision_date=2020-05-31&nd=1999-01-01
Next, copy the files downloaded from the EC2 instance to S3. Make sure that it has the aws-cli installed. Run
aws configureand thenaws s3 cp {FILE} s3://{S3_BUCKET}/{S3_FOLDER}/to transfer the files to S3. Note that if the situation changes such that this becomes a daily job, we can write a shell script containing these commands, and add the command to run this shell script in our Airflow data pipelineRun the ETL pipeline, scheduled using Airflow. Data Processing is done using Spark, and data is eventually ingested into Redshift.
Choice of Technologies
For data processing (data transformation step), Spark is chosen because of its parellel processing capabilities. Should the amount of data proliferate to 100x, more worker nodes can be added to the spark cluster to scale out.
For orchestrating the steps in the pipeline, Airflow is chosen as it allows building of data pipelines that are straghtforward and modular. Airflow allows tasks to be defined in a Directed Acyclic Graph (DAG) with dependencies of tasks between one another. This allows running of tasks to be optimized. It also enables the pipeline to be run on a schedule (for eg, daily) should the need arise. Finally, it has an intuitive UI that allows users to check the steps in the data pipeline should any part of the pipeline fail.
Redshift is chosen as the cloud Data Warehouse as it is highly scalable. Should our data grow in size, we can provision more nodes or scale up, to handle the larger volume of data.
Docker is used to encapsulate package dependencies the code may have, to allow the code to run on any machine
Data Model
- The data model for this project is as shown below:
The approach taken, is to normalize the data. This will lead to more efficient UPDATES and DELETES as and when required.
ETL Pipeline
The ETL process runs through an Airflow DAG:
The process is as follows:
- We create the tables and staging tables (if they do not exist)
- We perform an update and insert, based on new data coming in
- Run a data quality check (check that tables have more than 1 row and there are no null ids)
Potential Improvements
- The assumption that I have made is that the data volume will not increase subtantially and the pipeline is only required to run once
- What if data is increased by 100x?
- We can run a increase the number of worker nodes on the spark cluster, to improve performance of compute. Furthermore, airflow schedules can be utilized to pull only a subset of the data at a time, to reduce volume of data handled at any one time.
- What if data pipeline needs to be run by 7am daily?
- We can turn on the EC2 machine and run the pipeline before 7am daily. Currently, the schedule of the airflow pipeline is set to ingest only once. We can set it to a daily schedule, to ingest new data coming in daily. We should add a new node to our Airflow DAG, to download data using API/get request and transfer to S3. In addition, to handle heavy workloads when backdating, CeleryExecutor should be used to run processes in a distributed fashion, ensuring there is no single point of failure. Furthermore, We can make use of Airflow's SLA feature, to send alerts should pipeline not have succeeded before a certain time (for eg, 6:00am)
- What if the database needs to be accessed by 100+ users?
- Redshift should not have an issue handling many users, but we should be careful to scale up/scale out with more nodes whenever necessary. To provide efficiency to queries, we can seek to understand common queries users have, so we can tweak our data model. Aggregated data tables can be provided beforehand to reduce query times. We can also assign sort keys according to users querying needs for each table.
Development
Setting up
Build the docker/pull docker image
# Build the docker image docker build -t {IMAGE_NAME} .Alternatively, pull the docker image I have pushed to Dockerhub:
# Build the docker image docker pull alanchn31/alanchn31-capstone-udacity-de-nd:1Replace the webserver image in docker-compose-LocalExecutor.yml to the image name of the Docker image you have built/pulled.
webserver: image: alanchn31/alanchn31-capstone-udacity-de-nd:1Run
docker-compose -f docker-compose-LocalExecutor.yml up -d. Your airflow server should be initiated and will be up and running. Visithttps://{your ec2 ip address}:8080to view Airflow UI
Add necessary connections and variables in Airflow UI
There are 4 variables to be defined:
movie_s3_config. It is defined as a json format as follows:{ 'aws_key': {AWS_KEY}, 'aws_secret_key: {AWS_SECRET_KEY}, 's3_bucket': {AWS_S3_BUCKET}, 's3_key': {AWS_S3_KEY} }- The AWS_S3_BUCKET is the S3 bucket with S3_KEY (folder) containing the csv files:
- credits.csv (from Kaggle Movielens dataset)
- links.csv (from Kaggle Movielens dataset)
- movies_metadata.csv (from Kaggle Movielens dataset)
- ratings.csv (from Kaggle Movielens dataset)
- consumer_price_index.csv (from Fred St Louis dataset)
- The AWS_S3_BUCKET is the S3 bucket with S3_KEY (folder) containing the csv files:
db_user(user name of user with access to Redshift database)db_pass(password of user with access to Redshift database)redshift_conn_string(Redshift JDBC connection string for spark dataframe to write to Redshift)
In addition, define the Hook to connect to Redshift:
Conn Id: `redshift`.
Conn Type: `Postgres`.
Host: Enter the endpoint of your Redshift cluster, excluding the port at the end.
Schema: This is the Redshift database you want to connect to.
Login: Enter Redshift user
Password: Enter Redshift password
Port: Enter `5439`.
After configuring, visit Airflow UI and enable DAG to start the data pipeline
Acknowledgements
Many thanks to:
- Udacity - for providing the project template and points of consideration :clap:
- Rounak Banik - for providing me with the dataset I extracted from Kaggle and used :clap:
- St Louis Fred - for providing me with the consumer price index data :clap:
관련 프로젝트 살펴보기
Asabeneh/30-Days-Of-Python
30 Days of Python 프로그래밍 챌린지는 Python 프로그래밍 언어를 30일 동안 배우기 위한 단계별 가이드입니다. 이 챌린지는 100일 이상 걸릴 수 있습니다. 자신의 속도에 맞춰 진행하세요. 다음 동영상도 도움이 될 수 있습니다: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,560 스타grafana/grafana
개방적이고 조합 가능한 옵저버빌리티 및 데이터 시각화 플랫폼입니다. Prometheus, Loki, Elasticsearch, InfluxDB, Postgres 등 여러 소스의 메트릭, 로그, 트레이스를 시각화합니다.
77,830 스타redis/redis
실시간 데이터 기반 애플리케이션을 구축하는 개발자에게 Redis는 가장 선호되고, 가장 빠르며, 기능이 가장 풍부한 캐시, 데이터 구조 서버이자 문서 및 벡터 쿼리 엔진입니다.
77,395 스타apache/superset
Apache Superset는 데이터 시각화 및 데이터 탐색 플랫폼입니다.
75,473 스타