<?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 Aras Onal on Medium]]></title>
        <description><![CDATA[Stories by Aras Onal on Medium]]></description>
        <link>https://medium.com/@aras.onal?source=rss-e4e3ce7e5f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*CyOVcRAPb5s5G8FE.jpg</url>
            <title>Stories by Aras Onal on Medium</title>
            <link>https://medium.com/@aras.onal?source=rss-e4e3ce7e5f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 15:27:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aras.onal/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[Bulk Product Deletion and Product Entry Limitation Processes]]></title>
            <link>https://medium.com/trendyol-tech/bulk-product-deletion-and-product-entry-limitation-processes-b5a5af0121cc?source=rss-e4e3ce7e5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5a5af0121cc</guid>
            <category><![CDATA[couchbase]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[product]]></category>
            <category><![CDATA[rate-limiting]]></category>
            <dc:creator><![CDATA[Aras Onal]]></dc:creator>
            <pubDate>Tue, 12 Dec 2023 08:26:54 GMT</pubDate>
            <atom:updated>2023-12-12T08:26:54.176Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/796/1*VcrXyiAIUxaZ8UpV3YVvCQ.png" /></figure><p>As the Supplier Management Team (SPM), we are responsible for ensuring that sellers’ products are uploaded to Trendyol smoothly and as quickly as possible. In the initial stages of Trendyol’s growth, it was necessary to keep restrictions on sellers minimal to quickly onboard their products to get more web traffic and to offer more products. Content control becomes weaker, allowing you to quickly increase the number of your products in a short time.</p><p>Naturally, as a result, various problems arise both for customers and the technical team. From the customer’s perspective, it becomes very hard to find what they are looking for as many low-quality products take place on the site, leading to potential loss of customers. Technically, as the number of low-quality products increases, the cost of managing them, exporting them to excel sheet, and querying increases.</p><p>At the same time, you make your sellers who are new but offer quality products less visible, which negatively affects both the seller and the customer.</p><p>Let’s address the problems one by one. First, let’s start with the database problems created by unnecessary millions of products.</p><h4>Part 1: Single database with hundreds of millions of products</h4><p>In SPM team, a product means a combination of the seller ID and the barcode. Therefore, when a seller uploads a product to the system, a unique database record for that product is created. Initially, these uploaded products are stored in a single Couchbase database. Hundreds of millions of products uploaded by sellers are stored in this way. Couchbase keeps the data in RAM for fast access and also saves it permanently to disk. If you have a lot of data, after a while, as RAM becomes insufficient, Couchbase starts serving this data from disk instead of RAM. The percentage of data held in RAM is known as residency. If this rate is low, your query performance will also be low.</p><p>This is the fundamental model for writing and reading data used by our team: Client APIs write data to Couchbase, and through Couchbase-Elasticsearch Sync (CBES), we synchronize the data with our Elasticsearch (ES) indexes. Subsequently, the data becomes accessible for reading through APIs that utilize ES queries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kwNKVH_aO2hdCcfa3z158Q.png" /><figcaption>Basic write read model for our apis using couchbase and elasticsearch</figcaption></figure><p>Can you see the problem here? No matter how many replicas you create, in case of a failure, millions of data will be attempted to be recovered from a single source, any database script you run will have to process hundreds of millions of data, and your index definition processes will be slow.</p><p>At this point, our first focus was on how we could distribute this data. The solution we found was to distribute this data to different clusters according to the modulus of 10 of the seller ID. In other words, we created 10 new smaller clusters in the form of 1,2,3,…, 9,10. According to the modulus of the seller ID, we placed each sellers’ products in these clusters. For example, products belonging to seller 1231 were in the 1st cluster, products of seller 1234 were in the 4th cluster, etc. In this way, we distributed the data, which was previously in a single cluster, across 10 clusters, each becoming one-tenth the size of the original.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b92pWul-fmpkyM9UZsBkHQ.png" /><figcaption>Clusters after distributing the data</figcaption></figure><p>This approach provided us with several advantages:</p><ul><li>When there was a problem in one of these clusters, we knew that only a specific group of sellers was affected. For example, if there was a problem in the 4th cluster, we could definitively say that sellers ending in 4 were affected.</li><li>In case of a failure, it became very easy to perform operations on a cluster. Since the data was much smaller, operations like index definition and running processes on the database could be easily performed.</li><li>Of course, we defined replicas for each cluster as well.</li><li>For each of our clusters, we also established a corresponding Elasticsearch cluster, which is similarly based on the seller ID. As a result, our read operations can now retrieve products related to each seller from the corresponding cluster, determined by the modulus of 10 of the seller ID.</li></ul><p>This seemingly simple solution saved us from the risk of a single database. However, there is still an unresolved issue: how do we get rid of not used and not updated products in the database, and how do we prevent them from being imported?</p><h4>Part 2: How can we prevent a seller from entering too many products?</h4><p>I hear you mentioning rate limiting, but the primary purpose of rate limiting is to prevent too many products from being entered within a certain time frame. We need a structure where we can set limits based on the seller’s performance. Therefore, at this stage, we gave levels to sellers according to certain criteria and granted the right to enter a certain number of products at each level. For example;</p><ul><li>Level 0: 10,000 products</li><li>Level 1: 30,000 products</li><li>Level 2: 50,000 products</li><li>Level 3: 100,000 products</li><li>Level 4: 150,000 products</li><li>Level 5: Unlimited</li></ul><p>Whenever a seller creates a product, we check the total number of products at that moment and look at the limit value corresponding to the seller’s level. If the number of products a seller has does not exceed the limit allowed by their level, we permitted them to create new products. Sellers can move between levels based on their performance and gain the right to enter more products. If their level decreases, we automatically delete their products according to certain criteria to match the limit of their current level. If we can’t delete enough products, we encourage the seller to delete old products since they can’t add new ones.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w8IbJ54O8rv57AKh7pgm6g.png" /></figure><p>In the mini architecture we use here, we have a scheduler job system that runs on a specific day of the week. This job starts the process with a request to the limit API that manages the level tasks. The seller tag API, where the sellers’ levels are stored, is queried, and the current level information for each seller is obtained and recorded in the database.</p><p>Since this process is done once a week, if a seller’s level has dropped, both the current level information and the information before the level drop are recorded(levelBeforeDowngrade and levelDownDate field). The purpose of this is to define a time frame for the seller to improve their performance. That is, direct product deletion processes are not started at the end of the first week for a seller whose level has dropped; the seller is given the opportunity to see their situation. Currently, this period is 4 weeks. If the seller’s level continues to be lower than the original level for 4 weeks, that level becomes permanent, and the deletion process is marked to begin for that supplier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*euOFJCKBAYoqvHsqMJrdGQ.png" /><figcaption>Product creation process</figcaption></figure><p>After regularly processing these records into the database, we can now prevent a seller from creating a new product by checking their total number of products and the maximum number they are allowed to list based on their current level, whenever they attempt to add a new product.</p><h4>Part 3: How to delete product based on seller level?</h4><p>After establishing the level system and limiting the number of products a seller can list based on their performance, the next challenge is determining how to delete excess products when a seller’s level drops. It’s crucial to avoid randomly deleting products, as this could result in the removal of products that are currently on sale or have orders.</p><p>Two days after the sellers’ levels are pulled, another job begins. The purpose of this job is to initiate the product deletion process for sellers who have been at a lower level for 4 weeks. Let me illustrate with a scenario:</p><p>Assume you’re currently a Level 2 seller with a limit of 50,000 products and you currently have 10,000 products listed. If your performance is poor over four weeks and your level drops to Level 1, your new product limit will be 30,000. However, since you already have fewer products than this new limit, none of your products will be deleted, and you can continue to add products up to the new limit.</p><p>However, if you have 49,000 products, you now have 19,000 excess products. We start deleting as many of these as we can, following a structured approach.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HmUVh2tzZD9n8-1YYdpGaA.png" /><figcaption>Deletion process in detail.</figcaption></figure><p>Let’s discuss the architecture depicted here.</p><ol><li><strong>Kubernetes Job Triggering</strong>: Every Tuesday, a Kubernetes job is triggered, initiating the deletion process by sending a request to the limit API.</li><li><strong>Identifying Low-Performance Sellers</strong>: In Part 2, we had marked sellers showing low performance with another job. We query these sellers here.</li><li><strong>Queuing with message broker</strong>: The sellers identified from the query are queued.</li><li><strong>SPM Read API</strong>: This microservice allows us to query our products. We retrieve the product counts of the queued sellers from here.</li><li><strong>Request to Data Management Team</strong>: If the retrieved product counts exceed the limits corresponding to the seller’s level, we initiate the deletion process by sending a request to the Data Management Team.</li><li><strong>Preventing Seller from Deleting Products</strong>: During the product deletion process, we create a record with the seller ID to prevent the seller from deleting their products. If there’s an attempt to delete a product while this record exists, we don’t allow the process. This is to prevent excessive deletion of products.</li><li><strong>Role of Data Management Team</strong>: Their task is to identify products to be deleted and drop these onto a topic specified by us. If a seller’s product is to be deleted, we send an event to the Data Management Team specifying the number of products to be deleted. This event includes the seller ID, the number of products to be found for deletion, and the topic where the barcodes of these products to be deleted should be dropped.</li><li><strong>Use of ‘resultTopic’ Field</strong>: Notice the ‘resultTopic’ field in the event sent to the Data Management Team. This is because some sellers might have millions of products to be deleted, while others might only need a hundred to be deleted. A seller with a million products to be deleted could significantly slow down the deletion process for a smaller seller. Therefore, based on the number of products to be deleted, messages are dropped into one of three different topics. This way, in the topic labeled ‘low count’, only sellers with a small number of products are processed, while ‘medium’ and ‘high count’ topics handle sellers with a larger number of products to be deleted. This ensures efficient and scalable processing of deletion requests.</li></ol><p>The process of the Data Management Team selecting which products to delete operates as a completely separate procedure from the SPM team. This clear division ensures that the product deletion process is handled independently, allowing for specialized focus and expertise in each respective area. The data management team then identifies which of these excess products can be deleted based on various criteria, such as:</p><ul><li>Products that have not made a sale in the past few years.</li><li>Products that have not been updated in the past few years.</li><li>Archived products (unused but not deleted by the seller, just stored in the archive).</li></ul><h4>Part 4: Bulk deletion for all suppliers for once</h4><p>To delete sellers who have significantly more products than their limit and to achieve substantial space savings in the database, we initiated a one-time deletion process for all sellers. This approach not only cleared out unsold, unlisted, outdated, and archived products from the sellers but also freed up nearly 40% of space in the database. As a result, hundreds of millions of products were deleted.</p><h4>Conclusion</h4><p>By implementing this structure, we achieved significant space savings and also ensured that new product listings are based on the sellers’ performance. This led to reduced database costs and improved query performance. We managed to increase the memory residency rate on Couchbase back above 90%, thereby reducing the reliance on hard disk access.</p><p><a href="https://jobs.lever.co/trendyol?lever-via=1-4_Fw7XHl&amp;lever-social=job_site">Trendyol jobs</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5a5af0121cc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/bulk-product-deletion-and-product-entry-limitation-processes-b5a5af0121cc">Bulk Product Deletion and Product Entry Limitation Processes</a> was originally published in <a href="https://medium.com/trendyol-tech">Trendyol Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[İdeal Kafka Producer Parametreleri]]></title>
            <link>https://medium.com/@aras.onal/i%CC%87deal-kafka-producer-parametreleri-961a1d860408?source=rss-e4e3ce7e5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/961a1d860408</guid>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[producer]]></category>
            <dc:creator><![CDATA[Aras Onal]]></dc:creator>
            <pubDate>Sat, 25 Mar 2023 00:29:52 GMT</pubDate>
            <atom:updated>2023-03-25T00:39:29.951Z</atom:updated>
            <content:encoded><![CDATA[<p>Olur da unutursam diye ideal canlı ortam parametreleri ne olmalı, nasıl yüksek yüklerde stabil çalışan bir kafka producer tanımlayabiliriz bunun hakkında biraz yazayım. Malum ne zaman neye geçeceğimiz belli olmuyor. Belki başka birinin de işine yarar veya bir yanlış düzeltiriz.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zaPhthLdxrnhZmGrs6PQcw.png" /></figure><p>Yazı trendyol tech blogundan bağımsız olacak, orada yayınlanacak formatta değil ve Türkçe. Daha çok benim günlüğüm olarak düşünebilirsiniz.</p><p>Öncelikle, yüksek yüklerde en çok sıkıntı yaşayacağınız yer kafka producer olacak. eğer hata senaryolarına karşı yeterince alan bırakmazsanız bolca buffer hatası veya expired(süre doldu mesajı kaybettim) hatası alıyorsunuz.</p><p>Başlangıç noktası olarak client versiyonu 2+ seçmemiz lazım. bu versiyon sonrası <strong>delivery.timeout.ms </strong>parametresi ekleniyor, işleri kolaylaştırıyor.</p><p>Kafka mesaj yollarken mesajları bir bufferda biriktiriyor, daha sonra bu buffer üzerinden mesajları yollamaya çalışıyor. Dolayısıyla ilk öğrenmemiz gereken, ne kadarlık bir mesajı ne kadar yük ile yolluyoruz. <strong>buffer.memory </strong>kriz anında, brokerlar indiğinde, kafkaya erişemediğinizde bu parametre yeterince büyük verilmezse çok kolay veri kaybediyorsunuz. <strong>Buffer overflow</strong> hatası atıyor.</p><p>Bunu öğrenmek basit, <strong>buffer.memory</strong>’i 1 byte olarak verirseniz exception alıyorsunuz. Kafka java kütüphanesi, ne kadarlık bir alan gerektiğini söylüyor. benzerini diğer dillerde de deneyebilirsiniz.</p><p>Java örneğimiz için 60–70 bytelik bir mesaj -denediğim-yaklaşık 300 byte yer kaplıyor. Diyelim ki producer’i kullandığınız yer dakikada 1000 mesaj alıyor. Yani sizin kafkanın indiği bir durumda 1 dakika boyunca bufferda mesaj tutabilmek istiyorsanız minimum 300 kilobyte buffera ihtiyacınız var. Uygulamanın ne kadar dayanmasını istiyorsanız, dediğim şekilde bir hesap yapıp bu parametreyi öyle verin.</p><p>Devam ediyoruz <strong>batch.size</strong> ve <strong>linger.ms</strong>. Bunlara dokunmazsanız kafka mesajları batching yapmadan yolluyor. Anlamı, buffera düşen mesaj doğrudan beklenmeden yollanıyor. bunun nesi kötü diyecek olursanız, her bir mesaj yollamanın servera erişmesi gerektiğinden bir <strong>latency</strong> oluşturuyor, sistemin genel throughput(tp)’sini düşürüyor. Bunların ideali ne olmalı diyorsanız confluentin güzel bir kaynağı var:</p><p><a href="https://assets.confluent.io/m/6b6d4f8910691700/original/20190626-WP-Optimizing_Your_Apache_Kafka_Deployment.pdf">https://assets.confluent.io/m/6b6d4f8910691700/original/20190626-WP-Optimizing_Your_Apache_Kafka_Deployment.pdf</a></p><p>Bu iki parametreyi verdiğiniz anda kafka mesajları yollamadan önce <strong>linger.ms </strong>kadar bekleyip, mesajları biriktirip öyle yollamaya çalışıyor. İdeali linger için 100 civarı, batch size ise 100–200 bin. Linkte daha detaylı bilgi bulabilirsiniz.</p><p><strong>max.request.size </strong>mesaj kaybetmemek için çok kritik. Kesinlikle yolladığınız mesajın maksimum boyutunu kontrol edin. Bunun ayarlamazsanız varsayılanı tek bir mesaj için 1MB. Eğer olur da büyük bir json basıyorsanız kafkaya ve bu 1MB’dan büyükse mesajı kaybediyorsunuz ve log atmıyor(eski versiyonlarda en azından), başıma geldi.</p><p><strong>delivery.timeout.ms, request.timeout.ms,</strong> <strong>metadata.max.age.ms bunların r</strong>astgele verilmemesi ve <strong>buffer.memory</strong> ile orantılı verilmesi gerekiyor.</p><p>Mesajı yollamaya çalışıyoruz, <strong>request.timeout</strong> bu mesajın ne kadar süre yollanmaya çalışacağını söylüyor. Diyelim ki sürekli hata alıyoruz, ne zamana kadar, <strong>delivery.timeout.ms</strong> bu limite ulaşana kadar. Yani bu parametre mesaj yollama sürecine genel bir limit koyuyor. delivery timeout’a ulaşıldığı anda expired hatası alıp mesajı kalıcı olarak kaybediyorsunuz. Bu nedenle delivery timeout’un yeterince büyük verilmesi önemli.</p><p><strong>metadata.max.age.ms</strong> bu da eğer cluster’a yeni bir kafka broker eklenirse bunu hızlıca algılayabilmesi için ne kadar sürede bir metadatayı güncellemesi gerektiğini kontrol ediyor. 5 dakika çok uzun bence, daha düşük verilebilir.</p><p>Buraya kadar yazdıklarımı birleştirelim.</p><p>Mesajımız 70 byte olsun, kafkada maliyeti 300 byte (java için)<br>dakikada 10 bin mesaj alalım. Sistemimizin bir çökme anında 20 dakika boyunca mesaj kaybetmeden bu mesajları saklamasını istiyoruz.</p><p>20 dakikalık saklama maliyeti 60 milyon byte = 60 mb’lık buffer’a ihtiyac var.<br> <strong>delivery.timeout.ms</strong> = 1,200,000 (20 dk’nın ms karsılıgı)<br> <strong>buffer.memory</strong> = 67,108,864(64MB)<br> <strong>batch.size</strong> = 100000(100KB)<br> <strong>linger.ms</strong> = 150</p><p>Bunlar temel parametrelerimiz. Bunlara ek olarak, çift gönderilen mesajları engellemek ve brokerlerin replicalı çalışmasını sağlamak için bir kaç parametremiz daha var.</p><p><strong>enable.idempotence</strong> true olmalı, yollanan mesajlara, çift mesajları anlayabilmek için sıra numarası ekliyor. <br><strong>max.in.flight.requests.per.connection </strong>5 olmalı. Kafka aynı anda 5 paralel mesaja kadar sıra koruma garantisi veriyor.<br><strong>acks</strong> = all. Idempotence açınca bu da all olmak zorunda. Yolladığınız mesajlar replicaya kaydedilmeden mesajı kaydedilmiş saymıyor.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=961a1d860408" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Apache NiFi for Migrating Data]]></title>
            <link>https://medium.com/trendyol-tech/using-apache-nifi-for-migrating-data-fe1c224c7b16?source=rss-e4e3ce7e5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe1c224c7b16</guid>
            <category><![CDATA[apache-nifi]]></category>
            <category><![CDATA[data-migration]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Aras Onal]]></dc:creator>
            <pubDate>Fri, 11 Oct 2019 07:42:11 GMT</pubDate>
            <atom:updated>2019-10-11T07:42:11.533Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*Cpv-1X_PE7bAzZj7G0u4xA.jpeg" /></figure><p>Apache NiFi is designed to automate the flow of data between software systems. It consists of several data processors that allows us to do some operation in the processor and conveys the results to next data processor as an input thus creating a flow for processing data. In this article, we focus on query and update Sql processors along with Http request processor for querying some api. We created example domain for demonstration of NiFi.</p><h3><strong>Problem</strong></h3><p>We have relational database table in PostgreSQL and in this table, approximately 13 million records have null column in it. We want to fill these columns by querying another API and fetching specific attribute from response it returns.</p><h3>Installing NiFi</h3><p>Installing NiFi is pretty straightforward. We used Docker for installation process:</p><p><strong>docker run — name nifi -p 8084:8080 -d apache/nifi:latest</strong></p><p>Port can be adjusted as you like. After executing the command, NiFi starts at 8084 port.</p><h3>Solution</h3><p>With NiFi, a workflow for querying and updating purposes can be created with using processors. Querying database and Http request can be done in processor. Therefore, we will create flow using processors.</p><p>Let’s say our table has name <strong>TableA</strong> and it has two fields in it as <strong>product_id</strong> and <strong>brand_id</strong>. In our case, all brand_id’s in this table are <strong>null</strong>. We use product_id in each row to query the some API and fetching brand_id from the response and updating corresponding column in TableA with brand_id information.</p><p>1 We start with adding our first processor for querying the table, <strong>ExecuteSql</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*qYN0x1FffCRVUwtVWyeCUw.png" /><figcaption>ExecuteSQL processor</figcaption></figure><p>The first state of our processor is stopped. There is no data input or output. We then configure processor by right clicking and selecting <strong>configure:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p6p_eooqJwxGk0BRm71uJw.png" /><figcaption>Configuring ExecuteSQL Processor</figcaption></figure><p>In our first step, we need to query database. We do this by fetching product_id with null brand_id filtering. Thus, whenever the processor works, it fetches 100 rows from TableA which has null brand_id in it and conveys the result set to the next processor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*wFFWf2KWJlKYVP-hQEBZDg.png" /><figcaption>Scheduling Configuration</figcaption></figure><p>We also configure scheduling. We want our processor to work in every 10 seconds and execute SQL query we configured before.</p><p>2ExecuteSQL processor produces data in Avro format, however we need JSON for further steps. Luckily, we have <strong>ConvertAvroToJSON </strong>processor for this purpose:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*bXuYaXlzVLCOM6THH44RnA.png" /><figcaption>ConvertAvroToJSON Processor</figcaption></figure><p>There is one little catch here. As you can see, we need queues for binding two different processors together. When you bind two different processors, they are automatically created. Basically, result of the <strong>ExecuteSql</strong> processor is passed to success queue and <strong>ConvertAvroToJSON</strong> processor consumes from it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*bOkYg8syOjWZV5CkSsdatA.png" /><figcaption>ConvertAvroToJSON Processor Configuration</figcaption></figure><p>We also configure processor for outputting data as JSON array. After this processor works, we have data like this:</p><p><strong><em>[{“product_id” : “some-id-1”}, {product_id: “some-id-2”}]</em></strong></p><p>3From second step, JSON array is produced consisting of product_id’s. In order to query the api we need to process data one by one. For this purpose, we add <strong>SplitJson</strong> processor for splitting incoming JSON array by comma and processing each product_id individually.</p><p>As stated in problem section, we need to query some api with product_id<strong> </strong>and getting brand_id from the response. However, product_id which is produced by SplitJson processor, can’t be used directly. We need make an attribute out of it. For creating attribute, <strong>EvaluateJsonPath</strong> is used. Basically, this processor takes product_id and creates a placeholder for it. In our example, we mapped product_id to $.product_id. So whenever we need to use product_id, using $product_id is sufficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*yElTA-q6DmQudgt7EbIpGw.png" /><figcaption>Splitted JSON array elements are passed to EvaluateJsonPath for creating product_id attribute</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/473/1*eqRwJODPKisoPG0uqnDV7w.png" /><figcaption>EvaluateJsonPath configuration. $.product_id is used as a placeholder for product_id</figcaption></figure><p>4 In this step, querying the api can be done with using <strong>InvokeHTTP</strong> processor. Results coming from <strong>EvaluateJsonPath</strong> is passed to <strong>InvokeHTTP</strong> processor. Attribute $.product_id can be used in query URL</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*TI-TZDK_rp_grtFCJ0W9lA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*u_KYB0g0imrouPi-IfkK_A.png" /><figcaption>InvokeHTTP processor configuration</figcaption></figure><p>As seen in image, <strong>$product_id</strong> attribute we created from previous processor can be referenced in query. Thus, it is possible to query the api for each individual product_id and producing separate responses.</p><p>5 Querying the api gives us some response and we need to fetch brand_id from it for updating our table. In this situation, again using <strong>EvaluateJsonPath</strong> processor and creating <strong>$.brandId</strong> attribute for further steps is way to go.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/1*70X1WfQ5evqSflSmJZ9PAA.png" /><figcaption>Response coming from InvokeHTTP processor is passed to EvaluateJsonPath</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*cCcCcns4ZEZzC-hHTtdOcQ.png" /><figcaption>Creating brandId attribute from brandId field in EvaluateJsonPath processor</figcaption></figure><p>We configure another <strong>EvaluateJsonPath</strong> processor to create<strong> </strong>$.brandId<strong> </strong>attribute from brandId field in api response.</p><p>6 Now that we have both product_id and brand_id, we can update our database with them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RjfCVMtxiroYYLHx91CNsA.png" /><figcaption>PutSQL processor along with logging processors</figcaption></figure><p>$brandId attribute coming from <strong>EvaluateJsonPath</strong> and $product_id from previous steps can be directly used in sql query we put together in <strong>PutSQL</strong> processor. Also, LogMessage processor can be added along with success and failure queue bindings for tracking the status of the flow as seen in image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8iPaQCKqCBeglkLe3nx-HQ.png" /><figcaption>Using brandId and productId attributes for updating TableA</figcaption></figure><p>Just logically binding processors together, migration can be done in a fast manner.</p><p>Thanks for reading.</p><p>For further reference, <a href="https://nifi.apache.org/">https://nifi.apache.org</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe1c224c7b16" width="1" height="1" alt=""><hr><p><a href="https://medium.com/trendyol-tech/using-apache-nifi-for-migrating-data-fe1c224c7b16">Using Apache NiFi for Migrating Data</a> was originally published in <a href="https://medium.com/trendyol-tech">Trendyol Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>