<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by William Mekomou on Medium]]></title>
        <description><![CDATA[Stories by William Mekomou on Medium]]></description>
        <link>https://medium.com/@williammekomou?source=rss-ab6ce9c45145------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YKZJFWS1dD8LqeCbitmuPw.png</url>
            <title>Stories by William Mekomou on Medium</title>
            <link>https://medium.com/@williammekomou?source=rss-ab6ce9c45145------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 16:24:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@williammekomou/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Schedule your BigQuery jobs with Play Framework 3 and Akka]]></title>
            <link>https://medium.com/google-cloud/schedule-your-bigquery-jobs-with-play-framework-3-and-akka-adf382998e99?source=rss-ab6ce9c45145------2</link>
            <guid isPermaLink="false">https://medium.com/p/adf382998e99</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[akka]]></category>
            <category><![CDATA[play-framework]]></category>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <dc:creator><![CDATA[William Mekomou]]></dc:creator>
            <pubDate>Sat, 06 Jul 2024 07:13:58 GMT</pubDate>
            <atom:updated>2024-07-06T07:13:58.190Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MUo1WVlgn8NyKoiF-8mecA.jpeg" /></figure><blockquote>Built on Akka, Play provides predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications.</blockquote><blockquote>BigQuery is a fully managed, AI-ready data analytics platform that helps you maximize value from your data and is designed to be multi-engine, multi-format, and multi-cloud.</blockquote><p>This article will show how to implement a BigQuery job with Play Framework and Akka. <strong>The job will run every day at midnight</strong>.</p><p>Before starting it is recommended to have the basics of <a href="https://www.baeldung.com/java-intro-to-the-play-framework">Play Framework</a> and <a href="https://cloud.google.com/bigquery/docs/introduction?hl=fr">Google Cloud BigQuery</a>.</p><h4>Sequence diagram</h4><p>In the diagram below, we see that the application will execute a BigQery query every midnight, which will update the <strong>filtered_table</strong> table. After the update, a response containing the number of bytes read is sent asynchronously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*JNYfqBNuxOOu8DoJr-p4_A.png" /><figcaption>sequence diagram</figcaption></figure><p>So we will need<br>- access to be able to execute BigQuery queries from Java code<br>- the Java project to execute our Job</p><h4>BigQuery Setup</h4><p>Assuming you have a Google Cloud account:<br><strong>a)</strong> Create a new project that we will call “Big Query Example”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*v45OD5h8jC0o4rL79ONBag.png" /><figcaption>Google Cloud project creation</figcaption></figure><p><strong>b)</strong> Ensure that the big Query API is enabled</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*fEH4Py1r9MK5A6vt4nq7dg.png" /></figure><p><strong>c)</strong> Create a service account to allow Java code to authenticate.<br>In IAM and admin &gt;&gt; Services accounts, click Create service account<br>- Make sure the “Big Query Example” project is selected<br>- Service account name: Big Query<br>- Service account ID: big-query<br>Click Create and Continue</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*dXlm7kEGV1z8K7aog72jOQ.png" /></figure><p><strong>d)</strong> Add the Big Query Admin role and click Done</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*I1YnD11psFSvsLZboi5GWw.png" /></figure><p><strong>e)</strong> You must have a screen like this without keys “No keys” in the Key ID column like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*Vu-WGydCWtTy4kuLg-FHLA.png" /></figure><p><strong>f)</strong> We will add a key by selecting “Manage keys”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*3xVBW60kZdYSMGo-zTVlcQ.png" /></figure><p>Then “Create new key”, choose “Json” and click “Create”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*j5EGv__akCfwU64VcBSb2A.png" /></figure><p>If all goes well, a .json file will be downloaded. Note these fields they will be used later: project-id, client-email, private-key.</p><p><strong>g) </strong>In BigQuery create a <strong>covid_data</strong> dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*v7eQBYXQUNdi9c2zNkG0Qw.png" /></figure><h4>Play Framework project</h4><p>Before you start You must install JDK 11 or higher and Sbt and have the basics of <a href="https://www.baeldung.com/java-intro-to-the-play-framework">Play Framework</a></p><p><strong>a) </strong>We will create a new project. For this, we will use the command</p><pre>sbt new playframework/play-java-seed.g8</pre><p>and fill like the image below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*k7N6-nwFqxQuhT-TMZ_VDg.png" /></figure><p><strong>scala_version</strong> and <strong>sbt_giter8_scaffold_version</strong> may differ depending on the machines.</p><p><strong>b)</strong> We will use the <a href="https://doc.akka.io/docs/alpakka/current/google-cloud-bigquery.html">Alpakka</a> library for Google Bigquery. <strong>Alpakka</strong> is a Reactive Enterprise Integration library for Java and Scala, based on Reactive Streams and Akka.</p><p>In the <em>build.sbt</em> file, adapt libraryDependencies to have this</p><pre>libraryDependencies ++= Seq(<br>  guice,<br>  &quot;com.lightbend.akka&quot; %% &quot;akka-stream-alpakka-google-cloud-bigquery&quot; % &quot;8.0.0&quot;,<br>)</pre><p>this will add the akka library which will later help us communicate with Bigquery.<br>For compatibility issues between Play 3 and the Jackson Library, we will add this</p><pre>dependencyOverrides += &quot;com.fasterxml.jackson.core&quot; % &quot;jackson-databind&quot; % &quot;2.14.2&quot;</pre><p>Finally, to allow sbt to find the akka repo when resolving dependencies, we will add this</p><pre>resolvers += &quot;Akka library repository&quot;.at(&quot;https://repo.akka.io/maven&quot;)</pre><p>Your full <em>build.sbt</em> should look like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d1dc030171633e4e17c93aa09f7193d/href">https://medium.com/media/4d1dc030171633e4e17c93aa09f7193d/href</a></iframe><p>to download the dependencies and make sure everything is ok run</p><pre>sbt compile</pre><p><strong>c)</strong> we will create the <em>app/services</em> folder and we will add the classes:</p><p><em>IBigQueryJob.java</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0495a33e7df7eb3ba71da4beceefa2ad/href">https://medium.com/media/0495a33e7df7eb3ba71da4beceefa2ad/href</a></iframe><p><em>BigQueryJobImpl.java</em></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e972ee91454d13e4a7932d7646ec741e/href">https://medium.com/media/e972ee91454d13e4a7932d7646ec741e/href</a></iframe><p>The <em>runJob()</em> function in our example will update the “filtered_table” table with the data read from the “covid19_open_data” table.</p><p><strong>d)</strong> Now that we have our function to execute the job, we will write the piece of code allowing us to execute this function regularly.<br>We will create the <em>app/schedulers</em> folder and we will add the classes:<br>- <em>JobSchedulerActor.java</em> in which we will indicate the routine to be executed every day at midnight in our case. Your code should look like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4d54c3b1ec8623538c31b1b6e3b99dd/href">https://medium.com/media/d4d54c3b1ec8623538c31b1b6e3b99dd/href</a></iframe><p>- <em>JobScheduler.java</em> which is our scheduler in which we will tell it to trigger every day at midnight. Your code will look like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c95c8be1fde30e95055e03c0947749e/href">https://medium.com/media/2c95c8be1fde30e95055e03c0947749e/href</a></iframe><p>The wait variable will calculate the remaining time it takes for it to trigger at midnight</p><p><strong>e)</strong> We need to activate our schedulers.<br>- create a <em>BigQueryModule.class</em> in the <em>app</em> folder. Your code should look like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48a75a05cfae4817fb0f61b5c6573390/href">https://medium.com/media/48a75a05cfae4817fb0f61b5c6573390/href</a></iframe><p>- reference this module in the <em>conf/application.conf</em> in which we will add this</p><pre>play.modules.enabled += &quot;BigQueryModule&quot;</pre><p><strong>f)</strong> add the BigQuery identifiers. Still in the <em>application.conf </em>file add this at the end</p><pre>alpakka.google {<br>  credentials {<br>    service-account {<br>      project-id = &quot;your project-id&quot;<br>      client-email = &quot;your client-email&quot;<br>      private-key = &quot;your private-key&quot;<br>    }<br>  }<br>}</pre><p>replace project-id, client-email, and private-key with the values ​​retrieved from the .json file obtained in the service account section above.</p><p><strong>g)</strong> Finally we will go to <em>conf/logback.xml</em> and add this in the <em>&lt;configuration&gt;</em> tag</p><pre>&lt;logger name=&quot;schedulers&quot; level=&quot;INFO&quot;/&gt;</pre><p>This will allow us to display the logs of the classes found in the schedulers package.</p><p>Your final tree should look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*HBjeEesceOONUELFLjhYOw.png" /></figure><p>Finally, we will execute <em>sbt run</em>. Then you will need to launch <a href="http://localhost:9000/"><em>http://localhost:9000/</em></a><br>Except that to test you have to wait until midnight. We are going to modify the code just for testing so that the scheduler starts right away and at 5-second intervals.</p><p>The JobScheduler class becomes</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/82e73a434ab9018c9f07ed1d01e08522/href">https://medium.com/media/82e73a434ab9018c9f07ed1d01e08522/href</a></iframe><p>Finally we have the following results</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*xt564DJ8SKi2eUPS3i4XXg.png" /></figure><p>and in BigQuery</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*WNZaG9gTmYUmlFdAmPOraA.png" /></figure><h3><strong>Conclusion</strong></h3><p>This article will show how to schedule our BigQuery tasks using Play Framework 3. This example is ideal for independent tasks. If the jobs depend on each other, a good solution would be to use Data Pipeline Tools like Airflow, Beam, Oozie, Azkaban, and Luigi.</p><p>The source code of the application is available on <a href="https://github.com/mekomou/play-big-query">GitHub</a>.</p><p><strong><em>Please clap for this article if you enjoyed reading it. For more about Google Cloud, data science, data engineering, and AI/ML and software architecture follow me on </em></strong><a href="https://www.linkedin.com/in/williammekomou/"><strong><em>LinkedIn</em></strong></a><strong><em>.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=adf382998e99" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/schedule-your-bigquery-jobs-with-play-framework-3-and-akka-adf382998e99">Schedule your BigQuery jobs with Play Framework 3 and Akka</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>