Building a Data Lake on Google Cloud Platform

Md Hishaam Akhtar on 2022-02-28

Building a Data Lake on Google Cloud Platform

Ever since computers have come into the picture, we have tried to find ways for the computer to store some information. This information that is stored on a computer, which is also called data, is done in several forms. Data has become so important that information has now become a commodity that is available at our fingertips.

Data has been stored in computers in a variety of ways over the years, including databases, blob storage, and other methods. In order to do effective business analytics, the data created by modern applications must be processed and analyzed. And the volume of data produced is enormous! It’s critical to store petabytes of data effectively and have the necessary tools to query it in order to work with it. Only then can the analytics on that data produce meaningful results.

Big data is a discipline that deals with methods for analyzing, methodically extracting information from, or otherwise dealing with data volumes that are too massive or complicated for typical data-processing application software to handle. To handle the data generated by modern applications, the application of Big Data is very necessary.

With that in mind, this blog aims to provide a small tutorial on how to create a data lake that reads any changes from an application's database and writes it to the relevant place in the data lake. The tools we shall use for this are as follows:

Architecture of the Data Lake

The first step is to use Debezium to read all the changes happening in a relational database and push all that to a Kafka Cluster.

Debezium is an open-source distributed platform for change data capture. Debezium can be pointed at any relational database and it can start capturing any data change as it happens in real-time. It is very fast and durable. It is maintained by Red Hat.

Firstly, we shall use docker-compose to set up a Debezium, MySQL, and Kafka on our machine. You can also use independent installations of those. We shall be using the mysql image provided to us by Debezium as it contains data already inside it. In any production environment, proper clusters of Kafka, MySQL, and Debezium can be used. The docker compose file is as below:

The DEBEZIUM_VERSION can be set as 1.8. Also, make sure to set MYSQL_ROOT_PASS, MYSQL_USER and MYSQL_PASSWORD.

Before we go forward, we shall look at the structure of the database inventory which is provided to us by the debezium image. To enter the command line of the database:

Inside the shell, we can make use of show tables; command. The output should be something like this:

Sample Tables in MySQL

We can check the contents of the customer table by using select * from customers; command. The output should be something like this:

Data for Customers Table

Now, after the containers have been created, we will be able to activate a Debezium source connector for Kafka Connect. The data format we shall be using is the Avro data format. Avro is a row-oriented remote procedure call and data serialization framework developed within Apache’s Hadoop project. It uses JSON for defining data types and protocols, and serialises data in a compact binary format.

Let’s create another file with the configurations for our Debezium Connector.

As we can see, we have configured the details of the database in this as well as the database to read changes from. Make sure to change the values of MYSQL_USER and MYSQL_PASSWORD to whatever you had configured earlier. Now, we shall run a command to register this in Kafka Connect. The command is as follows:

Now, the Debezium should be able to read the database changes from Kafka.

The next step involves reading the data from Kafka using Spark and Hudi and putting them into Google Cloud Storage Bucket in Hudi file format. Before we start using them, let’s understand what Hudi and Spark are.

Apache Hudi is an open-source data management framework used to simplify incremental data processing and data pipeline development. This framework more efficiently manages business requirements like data lifecycle and improves data quality. Hudi enables you to manage data at the record-level on cloud based data lakes to simplify Change Data Capture (CDC) and streaming data ingestion and helps to handle data privacy use cases requiring record level updates and deletes. Data sets managed by Hudi are stored in a cloud storage bucket using open storage formats, while integrations with Presto, Apache Hive and/or Apache Spark gives near real-time access to updated data using familiar tools.

Apache Spark is an open-source unified analytics engine for large-scale data processing. Spark provides an interface for programming clusters with implicit data parallelism and fault tolerance. Originally developed at the University of California, Berkeley’s AMPLab, the Spark codebase was later donated to the Apache Software Foundation, which has maintained it since.

Now, since we are building a solution on Google Cloud, the best way to go about this would be to use Google Cloud Dataproc. Google Cloud Dataproc is a managed service for processing large datasets, such as those used in big data initiatives. Dataproc is part of Google Cloud Platform, Google’s public cloud offering. Dataproc helps users process, transform and understand vast quantities of data.

Inside the Google Dataproc instance, Spark and all the required libraries are preinstalled. After we have created the instance, we can run the following spark job in it to complete our pipeline:

This would run a spark job that fetches the data from the Kafka that we pushed earlier to and writes it to a Google Cloud Storage Bucket. We have to specify the Kafka Topic, the Schema Registry URL and other relevant configurations.

Conclusion

There are several ways in which a data lake can be architected. I have tried to show how to build a data lake using Debezium, Kafka, Hudi, Spark and Google Cloud. Using a setup like this, one can easily scale the pipeline to manage huge data workloads! For more details into each technology, the documentation can be visited. The Spark Job can be customized to have much more fine-grained control. The Hudi shown here can also be integrated with Presto, Hive or Trino. The number of customizations are endless. This article provides one with a basic intro on how one can build a basic data pipeline using the above tools!

If you’ve enjoyed this story, please click the 👏 button and share it, so that others can find it as well! Also, feel free to leave a comment below.

Groww Engineering publishes technical anecdotes, the latest technologies, and better ways to tackle common programming problems. You can subscribe here to get the latest updates.