This capstone project was developed under the scope of the Data Engineer Zoomcamp by DataTalksClub (the biggest Data community in the internet - DTC).
The goal of this project is to retreive the trending tweets in Nigeria on a periodic basic.
The trending data is gotten from twitter trends Api and saved to a data lake(google cloud storage).
The trends are gotten every 15 minutes and this process is ochestrated with PREFECT.
With pyspark running in a docker container, a batch process is submitted every 15mins to carry out the following functions:
- Fetch the current day trending keywords from the data lake
- Extract top trending keywords by volume in the last 2 hours
- Extract newly emerging trending keywords in the last 1 hour
- Save both top trending and emerging trends to a data warehouse (bigquery)
For this project I decided to use the following tools:
- Docker - TO build containers for running the Spark master and workers;
- Prefect - For orchestrating the full pipeline;
- Terraform - As a Infrastructure-as-Code (IaC) tool;
- Google Cloud Storage (GCS) - for storage as Data Lake;
- BigQuery- for the project Data Warehouse;
- Spark - for Batch processing and data transformation;
- Google Data studio - for visualizations.
You can explore the final dashboard here.
The environment variables are sectioned into 3
- prefect - this contains variables related to prefect
- GCP - this contains variabled related to google cloud platform e.g project_id
- Twitter - this contains variable related to the twitter api e.g consumer_key
create a .env file with the following config
GCP_CREDENTIALS_BLOCK_NAME=twitter-gcs-cred
TWITTER_BUCKET_BLOCK_NAME=twitter-gcs-cred
PROJECT_ID=***** SERVICE_ACCOUNT_CREDENTIALS=./twitter_project.json GCS_BUCKET_NAME=twitter_data_twitter-project-381411
CONSUMER_KEY=76s********
CONSUMER_SECRET=Bd************
ACCESS_TOKEN=2*****************
ACCESS_TOKEN_SECRET=***********
from project root directory run
sudo apt install python3-venvpython3 -m venv envsource env/bin/activatepip install -r requirements.txt
sudo apt-get updatesudo apt-get install docker.iosudo groupadd dockersudo gpasswd -a $USER dockersudo service docker restart
on your home directory run the following commands
mkdir bincd binwget https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-linux-x86_64 -O docker-composechmod +x docker-composecd ~nano .bashrcadd this line to the .bashrc to export the bin path to the environment variables : export PATH="${HOME}/bin:${PATH}"which docker-compose
create a project on GCP
create a service account with cloud storage, bigquery permissions
download the service accouint credentials json and save it as twitter_project.json in the project roor directory
from project directory, run the following commands
export GOOGLE_APPLICATION_CREDENTIALS=./twitter_project.jsongcloud auth activate-service-account --key-file $GOOGLE_APPLICATION_CREDENTIALS
insatlling terrafoam on the local machine or cloud platform from the home directory
cd binwget https://releases.hashicorp.com/terraform/1.3.7/terraform_1.3.7_linux_amd64.zipsudo apt install unzipunzip terra*rm terraform_*- cd to the project directory
- in the terrform variables.tf file, replace the project default value with your gcp project id
- from projec directory, run the following commands
terraform initterraform planterraform apply
from project root directory
cd sparksource build.shdocker compose up -dchmod +x run-docker.sh
prefect orion start
prefect block register -m prefect_gcp
python gcp_storage_block.py
prefect agent start --work-queue default
prefect deployment build ./injest_tweet.py:etl_gcp -n 'scheduled_twitter_prefect_deployment' --cron "*/15 * * * *" -a
.png)

