<?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 Kshitij Bhadage on Medium]]></title>
        <description><![CDATA[Stories by Kshitij Bhadage on Medium]]></description>
        <link>https://medium.com/@kshitijmb?source=rss-3a2024ab9b1d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*8-ZV48ChWD-DM0V4YiZqiQ.png</url>
            <title>Stories by Kshitij Bhadage on Medium</title>
            <link>https://medium.com/@kshitijmb?source=rss-3a2024ab9b1d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 06:41:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kshitijmb/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[Make parallel REST API calls in Apache Spark for huge data and some optimization techniques]]></title>
            <link>https://medium.com/@kshitijmb/process-massive-load-of-rest-api-calls-in-apache-spark-and-some-optimization-techniques-3a00990b49ea?source=rss-3a2024ab9b1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a00990b49ea</guid>
            <category><![CDATA[parallel-processing]]></category>
            <category><![CDATA[pyspark]]></category>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[dataproc]]></category>
            <category><![CDATA[rest-api]]></category>
            <dc:creator><![CDATA[Kshitij Bhadage]]></dc:creator>
            <pubDate>Thu, 07 Apr 2022 13:32:03 GMT</pubDate>
            <atom:updated>2022-04-09T04:55:49.900Z</atom:updated>
            <content:encoded><![CDATA[<h3>Context</h3><p>Our SuperApp has a customer base of more than 100 million to which we need to send one-time and recurring campaigns to the targeted audience.</p><p>Our requirement was to create an application that should be capable to send promotional campaigns through various communication channels like SMS, email and/or push (more to be added later) to the targeted audiences. I decided to go with Spark on a Dataproc Cluster which is a GCP managed Hadoop ecosystem using Pyspark, as Spark is a good option for distributed processing.</p><p>Note: Each campaign is expected to have a target of at least 5 million audiences and should be able to scale up to 100 million for some specific campaigns.</p><h3><em>Initial Design</em></h3><p>Below is the high-level implementation plan I initially designed,</p><ul><li>Get customer IDs to which the campaigns are to be sent and get other attributes needed.</li><li>Make bulk API calls to a secure service that will give me personal &amp; demographic details of those customers.</li><li>Dynamically format the message contents for all the channels and send notifications using respective APIs. Also, to store the responses in the Bigquery Audit table which will then be further used for analytics.</li></ul><blockquote>Machine specifications</blockquote><ul><li>Machine Type: n1-standard-8(8GB memory)</li><li>1 Master Node, 2 Primary Nodes and 2 Secondary Nodes(Autoscaling to 10 primary and 10 secondary nodes)</li></ul><blockquote>Flow Chart</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*e3uuALPUbvvOEm8NLvBEHg.jpeg" /><figcaption>Initial High-level implementation design</figcaption></figure><blockquote>Explanation</blockquote><ul><li>Read the customer IDs from the BQ campaign table</li><li>Get attributes of the customer Hash like consent to send notifications to channels, orderId, etc from another BQ lookup table</li><li>Now, create a list of 1000 customer IDs per row to make a bulk API call to get customer personal and demographic data. This was achieved using the collect() operation and windowing function</li><li>Through a UDF, make the REST API call and store back the bulk responses and explode the list so every customer data is now a single row</li><li>Through a UDF, dynamically do message formatting for the channels and make API calls to the respective channels.</li><li>Store the responses from the channel APIs in a single frame using union() operation and store all the results in a BQ audit table.</li></ul><blockquote>Trial &amp; errors</blockquote><ul><li>When a small campaign of a few thousand was run, the job ran fine and it took 20–25 mins to complete the campaign. But as I kept increasing the load, the job time started increasing exponentially and also started getting Out Of Memory errors(OOM) after waiting for hours to complete the job</li><li>Also tried increasing the machine specs to n1-standard-16 and n1-standard-32 but job time was not decreasing and started taking a few hours to run a campaign of 60K-70K customers, which is a pretty bad performance.</li><li>Also increased executor memory, driver memory, cores, etc but issues persisted.</li></ul><blockquote>Observations</blockquote><ul><li>I was using cache() which stores the frame in the memory of the executors which actually hit the performance. I was using collect() and windowing functions in a python loop to get a chunk of 1000 customers. It was very inefficient as collect operation runs in driver node and for large data, it would hit OOM</li><li>I was using excessive use of UDF, which hits the performance big time (there was no other way I could think of)</li><li>Max autoscaling reached due to shuffling which means more resources were utilized</li></ul><p>Basically, with the above results, it was impossible to run a large campaign. Optimisation was needed to be done, so I decided to improvise the implementation itself.</p><h3>Upgraded Design</h3><blockquote>Machine specifications</blockquote><ul><li>Machine Type: n1-standard-16(16GB memory)</li><li>1 Master Node, 2 Primary Nodes and 2 Secondary Nodes (Autoscaling to 10 primary and 10 secondary nodes)</li></ul><blockquote>Flow Chart</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*VlejkMRsqPZ4qvkIHT9r8w.jpeg" /><figcaption>Upgraded High-level implementation design</figcaption></figure><blockquote>Explanation</blockquote><ul><li>Build a query to get customer ids and their attributes by using inner join and run the query in BQ and load the data in a frame</li><li>Build a query to get list of 1000 customer ids per row to make bulk API calls and run it in BQ</li><li>Through an UDF, make the REST API call and store back the bulk responses and explode the list so every customer data is now a single row</li><li>Through an UDF, dynamically do message formatting for the channels and make API calls to the respective channels</li><li>Store the responses from the channel APIs in a frame and store all the results in a BQ table</li><li>Added multithreading to send notifications to channels in parallel</li></ul><blockquote>Benefits &amp; Observations</blockquote><ul><li>Step 1 and step 2 happening in parallel</li><li>No cache needed</li><li>No need to run collect() operation as it is taken care by BQ engine</li><li>Repartitioning helps in improving in overall performance</li></ul><blockquote>Final status</blockquote><ul><li>Easily able to run millions audience campaign and job time reduced to few minutes.</li><li>Maximum tested for <strong>30 Million</strong> audiences and job finished in <strong>25 mins</strong> (Load testing at the time of writing). Planning to test for 100 million + campaign</li><li>Full potential of scaling not required so reduction in resource consumption</li><li>No OOM error</li></ul><h3>Conclusion</h3><ul><li>It is easy to write Spark code but difficult to optimise the operations</li><li>Need to know correct usgae of repartition as it can degrade your applications if not correctly used</li><li>It is really important to understand OOM error as it can become difficult to resolve it</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a00990b49ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure Eventhub to GCP pubsub cross-clouds real-time migration]]></title>
            <link>https://medium.com/@kshitijmb/azure-eventhub-to-gcp-pubsub-cross-clouds-real-time-replication-dd3dc47bcc12?source=rss-3a2024ab9b1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd3dc47bcc12</guid>
            <category><![CDATA[google-dataflow]]></category>
            <category><![CDATA[azure-databricks]]></category>
            <category><![CDATA[azure-event-hub]]></category>
            <category><![CDATA[azure-functions]]></category>
            <category><![CDATA[pub-sub]]></category>
            <dc:creator><![CDATA[Kshitij Bhadage]]></dc:creator>
            <pubDate>Sat, 08 Jan 2022 11:35:00 GMT</pubDate>
            <atom:updated>2022-04-04T04:00:34.514Z</atom:updated>
            <content:encoded><![CDATA[<h3>Requirement/ Use-Case</h3><p>Get the event streaming data present in Azure Eventhub to GCP pubsub in real-time with no data loss and modifications.</p><h4>Azure Eventhub</h4><ul><li>Event Hubs is a fully managed, real-time data ingestion service that is simple, trusted, and scalable.</li><li>Allow existing Apache Kafka clients and applications to talk to Event Hubs without any code changes — you get a managed Kafka experience without having to manage your own clusters.</li></ul><h4>GCP Pubsub</h4><ul><li>Pubsub is a fully managed Ingest analytic events and streams data in real-time.</li><li>It is no-ops, secure, scalable messaging or queue system.</li></ul><h3><strong>Method 1: Using Azure Functions</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DDoxwWy9g01gp70JPg1jwg.png" /><figcaption>Eventhub to pubsub using Azure functions</figcaption></figure><h4>Azure Functions</h4><ul><li>Develop more efficiently with an event-driven, serverless compute platform that helps solve complex orchestration problems.</li><li>Build and debug locally without additional setup, deploy and operate at scale in the cloud, and integrate services using triggers and bindings.</li></ul><h4>Process</h4><ul><li>Initialize the properties of the event hub topic in the Azure Functions configuration file.</li></ul><ol><li>Script file: Where the function code is to be written. Named as __init__.py</li><li>triggers &amp; bindings: <a href="https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings?tabs=csharp">Triggers and bindings in Azure Functions</a></li></ol><ul><li>Sample file:</li></ul><pre>{<br>  &quot;scriptFile&quot;: &quot;__init__.py&quot;,<br>  &quot;bindings&quot;: [<br>    {<br>      &quot;type&quot;: &quot;eventHubTrigger&quot;,<br>      &quot;name&quot;: &quot;events&quot;,<br>      &quot;direction&quot;: &quot;in&quot;,<br>      &quot;eventHubName&quot;: &quot;eventhub-test&quot;,<br>      &quot;connection&quot;: &quot;eventhubtobqnamespace_RootManageSharedAccessKey_EVENTHUB&quot;,<br>      &quot;cardinality&quot;: &quot;many&quot;,<br>      &quot;consumerGroup&quot;: &quot;$Default&quot;,<br>      &quot;dataType&quot;: &quot;binary&quot;<br>    }<br>  ]<br>}</pre><ul><li>Sample code:</li></ul><pre>async def run(events, eventhub_output):</pre><pre>## Code to publish events to pubsub topic using pubsub client library</pre><pre>def main(events: List[func.EventHubEvent], eventhub_output :func.Out[str]):</pre><pre>loop = asyncio.get_event_loop()<br> loop.run_until_complete(run(events, eventhub_output))</pre><h4>Observations</h4><ul><li>Event movement was in real-time with very little to no delay.</li><li>But events were getting dropped by Azure Functions and there was severe data loss.</li><li>As eventhub guarantees at least one delivery, it was observed that it used to ingest duplicate records.</li></ul><h3><strong>Method 2: Using Azure Databricks</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kal4JzBrBrwEnJw5F_6MzA.png" /></figure><h4><strong>Process</strong></h4><ul><li>Create an Azure databricks cluster with autoscaling enabled.</li><li>Start a spark streaming job.</li><li>Consume events from the eventhub topic and store the result in a dataframe.</li><li>Finally, write the result to pubsub using the <a href="https://spark.apache.org/docs/latest/structured-streaming-programming-guide.html#foreach">forEach</a> or <a href="https://spark.apache.org/docs/latest/structured-streaming-programming-guide.html#foreachbatch">forEachBatch</a> method.</li></ul><p>Note: The trick is to use the above methods correctly else streaming will be very slow.</p><ul><li>Sample code</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6K3i1xtLvFwG8VkLMJqRJQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G370OR9M5JkdyDJPevlQrQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AymqnbhqCXLLghxgH01hhw.jpeg" /></figure><h4>Observations</h4><ul><li>This method worked well with near real-time publishment and no data loss and/or duplication.</li><li>Cannot consume multiple topics in a single job. Basically would need to create multiple jobs if multiple topics are to be consumed. Because each job requires a connection string with the topic name present.</li></ul><h3>Method 3: Using GCP Dataflow</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xbCXBXo5-jXLCm6iNuyPKA.png" /></figure><h4>Dataflow</h4><ul><li>Cloud Dataflow works best for processing streaming with speed. Keeping in mind the core principle of sending real-time transactions to customers, with dataflow we will be able to synchronize or replicate data reliably and with minimal latency across heterogeneous data sources in our use cases azure event hub to power streaming processing.</li><li>As the number of events increases in future phases, cloud dataflow will be able to horizontally and vertically scale automatically by choosing the appropriate number of workers required to process the real-time transactions.</li></ul><h4>Process</h4><ul><li>Apache beam has Kafka IO inbuilt connector. As Eventhub is built in line with Kafka we can use this connector to consume data from eventhub topics.</li><li>Convert events from multiple topics and flatten them to pubsub format.</li><li>Write the records to pubsub topic in batch mode with a delay of a second.</li></ul><h4>Observations</h4><ul><li>There was no lag, data loss, or duplication observed during the processing.</li><li>There is no real-time way to publish to pubsub. It happens only in a batch of 100 records.</li></ul><p>Note: There are some fundamental differences between Kafka and eventhub and it is necessary to know them to avoid data loss and have correct checkpointing. <a href="https://docs.microsoft.com/en-us/azure/event-hubs/apache-kafka-frequently-asked-questions#:~:text=Kafka%20consumer%20groups%20on%20Event,standard%20Event%20Hubs%20consumer%20groups.&amp;text=They%20are%20Managed%20with%20create,entities%20of%20an%20event%20hub">Frequently asked questions — Azure Event Hubs for Apache Kafka</a></p><h3>Tabular comparison</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sl0XPsILVlc4gEfVF1k91A.png" /><figcaption>Comparison between Azure Functions/ Databricks/Dataflow to event replication across clouds</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd3dc47bcc12" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GCP Data Engineer exam preparation, important tips and my emotional journey from failing to…]]></title>
            <link>https://medium.com/@kshitijmb/gcp-data-engineer-exam-preparation-important-tips-and-my-emotional-journey-from-failing-to-132d91dc75f8?source=rss-3a2024ab9b1d------2</link>
            <guid isPermaLink="false">https://medium.com/p/132d91dc75f8</guid>
            <category><![CDATA[certification]]></category>
            <category><![CDATA[gcp]]></category>
            <category><![CDATA[gcp-certification]]></category>
            <category><![CDATA[motivation]]></category>
            <category><![CDATA[data-engineering]]></category>
            <dc:creator><![CDATA[Kshitij Bhadage]]></dc:creator>
            <pubDate>Mon, 27 Jul 2020 15:31:43 GMT</pubDate>
            <atom:updated>2020-08-01T05:47:57.603Z</atom:updated>
            <content:encoded><![CDATA[<h3>GCP Data Engineering exam preparation, tips(study materials &amp; practice exams), and my journey from failing to passing experience</h3><p>Hi All,</p><p>This is my first post on medium and I would like to apologize in advance for the length of the post but I just wanted to share my journey. I am sure that you’ll learn something here.</p><p>In this post, I have shared the GCP Professional Data Engineering exam experience. Also, shared some study material &amp; practice exams in between the post. Do read the post and let me know in the comment section whether you liked it or not.</p><figure><img alt="GCP Data Engineer exam experience, tips and practice questions" src="https://cdn-images-1.medium.com/max/700/1*xrKNRB5xCQpY_IKWtXq3VA.png" /><figcaption>GCP Data Engineering exam preparation, tips(study materials &amp; practice exams), and my journey from failing to passing experience.</figcaption></figure><p>My name is Kshitij and I recently appeared for the GCP Professional Data Engineer Certification exam. But this was not the first time I appeared for it. I had attempted it back once and I failed. And recently appeared for the same exam, and I passed.</p><p>Before starting, I would like to talk about my background. Currently, I work in a Cloud startup which provides cloud-native solutions to the customers and solve their data problems. I started my IT journey 3 years ago from a very prestigious MNC service company straight from college. I worked as a Software Developer and then I decided to change my expertise in the Data domain.</p><p>Initially, I worked in very traditional and orthodox banking technology and I wanted to move out of it. So, I got a project in GCP for a Data Engineer role. I had no background or knowledge of the technologies used or the skills required for Data Engineers. My colleagues told me to do a course on GCP. I started the GCP Data Engineering Course from Coursera which is a very wonderful course. When I completed the course, I thought that I know all that is required and I can go for the GCP PDE certification exam. I was over-confident. I thought whatever I learned is enough for the certification exam. I gave some practice tests on Udemy and appeared for the Official GCP Professional Data Engineer exam. On the day of the exam, I was very confident, in fact, overconfident that I can clear it in the first attempt. When I was appearing for the exam, as the questions kept popping, the complexity of the questions kept on increasing(As the questions are dynamic and complexity increases) and the topics that questions covered were more than what was taught in GCP Data Engineering Course in Coursera. When I reached around 30–40 questions I was broken because I knew I will not pass the exam. And so it happened, I failed. It hurt me a lot. I lost the money. Moreover, I lost my confidence.</p><p>I was completely heartbroken but I decided to give the exam again. But this time, I did not let my ego rule over me. I knew that I needed more preparation and more self-belief to re-appear for the exam. Because in this exam, it’s not just your knowledge but your confidence, your skills, your patience is tested. Then, I understood why this exam has so much value and recognition.</p><p>After the blunder in December 2019, when I failed for the first time, I decided to focus on the skills and not on the certification exam. I started learning more about GCP services and I started working on them practically. I did some cross services implementations and lots of hands-on practice. I practice on my own, did some POCs which boosted my confidence. This was the best way to learn any technology.</p><p>After gaining a significant understanding of GCP and a lot of practice and work, I decided to re-appear for the exam in June 2020.</p><p>Now, I will share what study material was used to prepare for the exam.</p><p>I first started revising all the concepts from the previous Coursera course and then I went for the Linux Academy course. Please find the link below.</p><p><strong>Coursera course:</strong> <a href="https://www.coursera.org/professional-certificates/gcp-data-engineering">https://www.coursera.org/professional-certificates/gcp-data-engineering</a></p><p><strong>Linux Academy Course:</strong> <a href="https://linuxacademy.com/course/google-cloud-certified-professional-data-engineer/">https://linuxacademy.com/course/google-cloud-certified-professional-data-engineer/</a></p><p>Let me assure you that the above study materials are very very important but not enough. You need more practice and more variety of questions to solve.</p><p>Next, you need to follow all the links provided in the Github repo.</p><p><a href="https://github.com/sathishvj/awesome-gcp-certifications/blob/master/professional-data-engineer.md">sathishvj/awesome-gcp-certifications</a></p><p>Try and read as many posts or study materials as possible from this link. They will help you.</p><p>And the most important study material is the <strong>GCP official Documentation</strong>.</p><p><strong>GCP official documentation: </strong><a href="https://cloud.google.com/docs">https://cloud.google.com/docs</a></p><p>No study material is as good as this and there is no replacement. But it’s impossible to read all the topics so some good guys created a google doc which collects some important topics to be covered for the exam. Please find the links below,</p><p><strong>Sheet links:</strong></p><p>1) <a href="https://docs.google.com/spreadsheets/d/1LUtqhOEjUMySCfn3zj8Arhzcmazr3vrPzy7VzJwIshE/edit?source=post_page-----bb6a0812a1b1----------------------#gid=845776089">Important Documentation links</a></p><p>2) <a href="https://docs.google.com/document/d/1zSv7n7xYrsNRVKiQTEml4yiP8CP9kQKBajff3BvKLwQ/edit">Important Documentation links</a></p><p>Now, if you follow all the above resources then you are good with your preparation but you still need to practice solving some exam questions. For that, you can appear for the GCP official practice exam and Linux Academy practice exam. Please find the links for the same.</p><p><strong>GCP official practice exam:</strong> <a href="https://cloud.google.com/certification/practice-exam/data-engineer">https://cloud.google.com/certification/practice-exam/data-engineer</a></p><p><strong>Linux Academy practice exam:</strong> <a href="https://linuxacademy.com/course/google-cloud-certified-professional-data-engineer/">https://linuxacademy.com/course/google-cloud-certified-professional-data-engineer/</a></p><p>Keep re-appearing for the above exams until you keep scoring more than 95% constantly. The purpose is not to mug the questions but it will help you understand the variety of the scenarios covered, help you understand the scenarios, and how to choose the best correct solution.</p><p>Below is some extra exam preparation which is not easily available but is very important. These materials turned out to be turning points in the exam preparation.</p><p>Finally, just a few days before the exam date go through the below links.</p><p><strong>More practice questions:</strong></p><ol><li><a href="https://www.examtopics.com/exams/google/professional-data-engineer/">Exam Questions &amp; Answers</a> (Solve each question and search for the correct answer(s) in the discussion tab)</li><li><a href="https://docs.google.com/forms/d/e/1FAIpQLSe9qR0aXWX54BkTZi134hVGkBE-hNwDI5b8SCEbqNInyLs2rQ/viewform">Data Engineering practice exam on Google Forms</a></li></ol><p><strong>GCP cheatsheet:</strong> <a href="https://www.slideshare.net/GuangXu5/gcp-data-engineer-cheatsheet">GCP Data Engineering cheatsheet</a> (Read each point very carefully)</p><p>I didn’t do anything more than this. I just prepared all the above links.</p><p>Just recently, in July 2020, I re-appeared for the GCP Data Engineer remote proctored exam. I appeared for the exam with the above preparation materials and a lot of confidence and self-trust.</p><p>I will not go into the details of the exam as it was tough and it is supposed to be. But honestly speaking, before finishing the exam itself while I was solving questions, I was super confident (not overconfident) that I will pass this time. This was the level of boost I got after systematic preparation and also because I worked hard and trusted my instincts. I finish reviewing all the questions (took me around 1 hr 50 mins) and clicked the submit button and when I saw I was passed the message, my happiness went over the roof. I felt very proud of myself and why should I not? I officially became a Certified Professional Data Engineer, dude. I was, is, and always be a big deal for me.</p><p>So, what’s the point of this big post?</p><p>No matter what happens, whether you fail for the first or 100th of times in this exam or at any point in life, you should need to be able to pick yourself up. Learn from each mistake and be better than the previous time. Because at the end of the line, it brings immense happiness and a sense of joy &amp; confidence.</p><p>Many fail this exam for the first time and are hesitant to re-appear. I would like to advise them that if they follow the above path and keep faith in themselves then they will clear this or as a matter of fact, any exam/situation in the world.</p><p>I wish everyone who is preparing for the exam all the very best and keep the faith. Trust yourself and you’ll eventually get there. Peace.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=132d91dc75f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>