<?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 Abhishek Agarwal on Medium]]></title>
        <description><![CDATA[Stories by Abhishek Agarwal on Medium]]></description>
        <link>https://medium.com/@_abhishek09_?source=rss-52d87995a0bb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DG4ikRaW4jKuq3gtFcCzrQ.png</url>
            <title>Stories by Abhishek Agarwal on Medium</title>
            <link>https://medium.com/@_abhishek09_?source=rss-52d87995a0bb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 18:34:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@_abhishek09_/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[Apache Kafka Case Studies]]></title>
            <link>https://medium.com/@_abhishek09_/apache-kafka-case-studies-d89409086c50?source=rss-52d87995a0bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/d89409086c50</guid>
            <category><![CDATA[case-study]]></category>
            <category><![CDATA[message-queue]]></category>
            <category><![CDATA[event-streaming]]></category>
            <category><![CDATA[apache-kafka]]></category>
            <dc:creator><![CDATA[Abhishek Agarwal]]></dc:creator>
            <pubDate>Sun, 05 Jun 2022 09:17:05 GMT</pubDate>
            <atom:updated>2022-06-05T10:50:14.770Z</atom:updated>
            <content:encoded><![CDATA[<p>Apache Kafka is one of the widely used open-source distributed event streaming platform for high-performance data pipelines, streaming analytics, data integration, and mission-critical applications.</p><p>Before getting into the case studies, let’s understand a few terminologies first:</p><ol><li><strong>Broker</strong>: A Kafka cluster is composed of multiple brokers(servers). Each broker contains certain topic partitions.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/192/1*L0FgDlwlTx0LimL5l4wvFQ.png" /></figure><p>2. <strong>Topic</strong>: a particular stream of data similar to a table in a database(without all the constraints). You can have as many topics as you want. A topic is identified by its name. Topics are further split into partitions and the data is stored inside the offsets of each partition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*z7uvJLgiV7QVVIMKGSdkOQ.png" /></figure><p>3. <strong>Producer</strong>: Producers write data to topics(which is made of partitions). Producers automatically know to which broker and partition to write to.</p><p>4. <strong>Consumer</strong>: Consumer read data from a topic. Consumers know which broker to write to read from. Data is read in order within each partition(not across different partitions).</p><p>5. <strong>Kafka Streams</strong>: Library for building streaming applications.</p><p>6. <strong>Kafka Connect</strong>: Data integration framework for Kafka.</p><p>Now you are ready to dive into individual Kafka case studies</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1zvOjZW3NvsfQ5CTUnUFQg.jpeg" /></figure><h3><strong>Video Analytics — MovieFlix</strong></h3><p>MovieFlix is a company that allows you to watch TV shows &amp; movies on demand. The business wants the following capabilities:</p><p><em>a. Make sure the user can resume the video where they left it off.</em></p><p><em>b. Build a user profile in real time.</em></p><p><em>c. Recommend a user profile in real time.</em></p><p><em>d. Store all the data in an analytics store.</em></p><p><strong>How would you implement this?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*zZkvYjazNB7rXan1A5bkFQ.png" /></figure><p><strong>show_position topic</strong>:</p><ul><li>Is a topic that can have multiple producers</li><li>Should be highly distributed if high volume(&gt; 20 partitions)</li><li>Key for the topic can be “<em>user_id</em>” (because we want all the data from the a particular user to be ordered). Hence, all of a user’s data will go to a single partition only using this key and data is read in order within each partition</li></ul><p><strong>recommendations topic:</strong></p><ul><li>The kafka streams recommendation engine may source data from the analytical store for historical training</li><li>May be a low volume topic</li><li>Key for this topic can be <em>“user_id”</em></li></ul><h3><strong>IoT — GetTaxi</strong></h3><p>GetTaxi is a company that allows people to match with taxi drivers on demand. The business wants the following capabilities:</p><p><em>a. The user should match with a close by driver.</em></p><p><em>b. The pricing should surge if the number of drivers are low or the number of users is high.</em></p><p><em>c. All the position data before and during the ride should be stored in an analytics store so that the cost can be computed accurately.</em></p><p><strong>How to implement this?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*jaIhbC0rndDk9nAPJEdE5Q.png" /></figure><p><strong>taxi_position &amp; user_position topics:</strong></p><ul><li>Are topics that can have multiple producers</li><li>Should be highly distributed if high volume(&gt; 30 partitions)</li><li>Key for these topic can be chosen as <em>“user_id”</em></li><li>Data is ephemeral and probably doesn’t need to be kept for a long time</li></ul><p><strong>surge_pricing topic:</strong></p><ul><li>The computation of this topic comes from the Kafka Streams application</li><li>It may be regional and therefore that topic may be of high volume</li></ul><h3><strong>CQRS(Command Query Responsibility Segregation)— MySocialMedia</strong></h3><p>MySocialMedia is a company that allows people to post images and others to react by using “likes” and “commands”. The business wants the following capabilities:</p><p><em>a. Users should be able to post, like &amp; comment.</em></p><p><em>b. Users should see the total number of likes &amp; comments per post in real time.</em></p><p><em>c. High volume of data is expected on the first day of launch.</em></p><p><em>d. Users should be able to see ‘trending’ posts.</em></p><p><strong>How this can be implemented?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*2l9wQic7TGDqk4EQH4t-qw.png" /></figure><p><strong>posts topic:</strong></p><ul><li>Can have multiple producers</li><li>Should be highly distributed if high volume(&gt;30 partitions)</li><li>Probably will have a high retention period for its data</li></ul><p><strong>likes &amp; comments topics:</strong></p><ul><li>Topics with multiple producers</li><li>Should be highly distributed as the volume of data is expected to be much greater</li><li>Key can be <em>“post_id” </em>(so that all the likes and comments for each post can be in a single partition that will help the Kafka streams to make aggregation easy)</li></ul><h3><strong>Finance application — MyBank</strong></h3><p>MyBank is a company that allows real-time banking for its users. It wants to deploy a brand new capability to alert users in case of large transactions. The transactions already exists in their database. The business wants the following capabilities are this feature:</p><p><em>a. Thresholds can be defined by the users</em></p><p><em>b. Alerts must be sent in real time to the users</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*Yw20RjzH_O7cK1dUo0lBYw.png" /></figure><p><strong>bank_transactions topic:</strong></p><ul><li>Kafka Connect is a great way to expose data from existing database</li><li>There are tons of CDC(Change Data Captures) connectors for existing databases like PostgreSQL, Oracle, MySQL, mongoDB etc</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d89409086c50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LVM2 volumes on shared volume groups]]></title>
            <link>https://medium.com/@_abhishek09_/lvm2-volumes-on-shared-volume-groups-58d37f8b3e57?source=rss-52d87995a0bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/58d37f8b3e57</guid>
            <category><![CDATA[lvmlockd]]></category>
            <category><![CDATA[lvm]]></category>
            <category><![CDATA[shared-vg]]></category>
            <dc:creator><![CDATA[Abhishek Agarwal]]></dc:creator>
            <pubDate>Sun, 17 Apr 2022 09:46:52 GMT</pubDate>
            <atom:updated>2022-04-17T09:46:52.020Z</atom:updated>
            <content:encoded><![CDATA[<p>Wait….</p><p>If you are here to know about LVM2, get a kick start or learn the concept of LVM(Logical Volume Manager) shared volumes then I am sorry to disappoint you but this read won’t be of much help to you.</p><p>This blog post is to help answer those questions which can arise in any storage administrator’s mind but cannot answer those without getting their hands dirty with LVM shared volumes using <em>lvmlockd</em>.</p><p>Personally, as a developer, I thought if all this information was available to me it would have saved me a lot of time. Therefore here it is to help out all of you folks out there to implement HA solutions around shared lvm volumes active in exclusive mode(active only on one node at a time).</p><p><strong>Prerequisites:</strong></p><ol><li><a href="https://linuxconfig.org/linux-lvm-logical-volume-manager"><em>LVM</em></a> basics and how it works</li><li>LVM locking mechanism using <a href="http://manpages.ubuntu.com/manpages/bionic/man8/lvmlockd.8.html"><em>lockd</em></a></li></ol><p><strong>Environment:</strong></p><ul><li>Two ubuntu 20.04 LTS nodes attached to two shared disks. Block device details on both the nodes:</li></ul><pre>ubuntu@ip-172-31-85-197:~$ lsblk<br>NAME                 MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT<br>loop0                  7:0    0    25M  1 loop /snap/amazon-ssm-agent/4046<br>loop1                  7:1    0  55.5M  1 loop /snap/core18/2253<br>loop2                  7:2    0  61.9M  1 loop /snap/core20/1242<br>loop3                  7:3    0  42.2M  1 loop /snap/snapd/14066<br>loop4                  7:4    0  67.2M  1 loop /snap/lxd/21835<br>nvme1n1              259:0    0 139.7G  0 disk <br>nvme0n1              259:1    0     8G  0 disk <br>└─nvme0n1p1          259:2    0     8G  0 part /<br>nvme2n1              259:3    0    20G  0 disk <br>└─shared--vg-lvmlock 253:0    0   256M  0 lvm  <br>nvme3n1              259:4    0    20G  0 disk</pre><ul><li>Having all the lock modules(<em>lvmlockd</em> &amp; <em>sanlock</em>) installed and configured correctly on all the nodes.</li></ul><p><strong>Test cases for shared volume groups:</strong></p><ul><li>Create a local volume group(with no protection) on a shared disk and see if it’s visible on every node where disk is shared.</li></ul><pre>// create local vg on shared disk on node 1<br>ubuntu@ip-172-31-85-197:~$ sudo vgcreate local-shared-vg /dev/nvme3n1<br>  Physical volume &quot;/dev/nvme3n1&quot; successfully created.<br>  Volume group &quot;local-shared-vg&quot; successfully created</pre><pre>// vgs output on node 1<br>ubuntu@ip-172-31-85-197:~$ sudo vgs<br>  VG              #PV #LV #SN Attr   VSize   VFree  <br>  local-shared-vg   1   0   0 wz--n- &lt;20.00g &lt;20.00g</pre><pre>// vgdisplay on node 1<br>ubuntu@ip-172-31-85-197:~$ sudo vgdisplay<br>  --- Volume group ---<br>  VG Name               local-shared-vg<br>  System ID             <br>  Format                lvm2<br>  Metadata Areas        1<br>  Metadata Sequence No  1<br>  VG Access             read/write<br>  VG Status             resizable<br>  MAX LV                0<br>  Cur LV                0<br>  Open LV               0<br>  Max PV                0<br>  Cur PV                1<br>  Act PV                1<br>  VG Size               &lt;20.00 GiB<br>  PE Size               4.00 MiB<br>  Total PE              5119<br>  Alloc PE / Size       0 / 0   <br>  Free  PE / Size       5119 / &lt;20.00 GiB<br>  VG UUID               cZ9JWg-rR8W-77em-qGxk-36xK-doOZ-SvsYzo</pre><pre>// vgs output on node 2<br>ubuntu@ip-172-31-91-92:~$ sudo vgs<br>  VG              #PV #LV #SN Attr   VSize   VFree  <br>  local-shared-vg   1   0   0 wz--n- &lt;20.00g &lt;20.00g000000</pre><pre>// vgdisplay on node 2<br>ubuntu@ip-172-31-91-92:~$ sudo vgdisplay<br>  --- Volume group ---<br>  VG Name               local-shared-vg<br>  System ID             <br>  Format                lvm2<br>  Metadata Areas        1<br>  Metadata Sequence No  1<br>  VG Access             read/write<br>  VG Status             resizable<br>  MAX LV                0<br>  Cur LV                0<br>  Open LV               0<br>  Max PV                0<br>  Cur PV                1<br>  Act PV                1<br>  VG Size               &lt;20.00 GiB<br>  PE Size               4.00 MiB<br>  Total PE              5119<br>  Alloc PE / Size       0 / 0   <br>  Free  PE / Size       5119 / &lt;20.00 GiB<br>  VG UUID               cZ9JWg-rR8W-77em-qGxk-36xK-doOZ-SvsYzo</pre><ul><li>Create lv and change its state on a local unprotected(either by <a href="http://manpages.ubuntu.com/manpages/bionic/man7/lvmsystemid.7.html"><em>lvmsystemid</em></a><em> </em>or by lvm conf filters).</li></ul><pre>// creating lv from node 2<br>ubuntu@ip-172-31-91-92:~$ sudo lvcreate -n local-shared-lv -L 1G local-shared-vg<br>  Logical volume &quot;local-shared-lv&quot; created.<br>ubuntu@ip-172-31-91-92:~$ sudo lvs<br>  LV              VG              Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert<br>  local-shared-lv local-shared-vg -wi-<strong>a</strong>----- 1.00g</pre><pre>// deactivating from node 1<br>ubuntu@ip-172-31-85-197:~$ sudo lvchange -an local-shared-vg/local-shared-lv<br>ubuntu@ip-172-31-85-197:~$ echo $?<br>0<br>ubuntu@ip-172-31-85-197:~$ sudo lvs<br>  LV              VG              Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert<br>  local-shared-lv local-shared-vg -wi-<strong>-</strong>----- 1.00g</pre><p><strong>Note:</strong> On a local VG with no protection on a shared disk, the LVs on them can be activated/deactivated/created/deleted/modified from any node where the VG is accessible.</p><ul><li>Delete/manipulate the hidden lv <em>“lvmlock” </em>that is internally<em> </em>created by sanlock when a shared vg is created.</li></ul><pre>ubuntu@ip-172-31-91-92:~$ sudo lvchange -ay shared-vg/lvmlock<br>  Operation not permitted on hidden LV shared-vg/lvmlock.<br>ubuntu@ip-172-31-91-92:~$ sudo lvremove shared-vg/lvmlock<br>  Operation not permitted on hidden LV shared-vg/lvmlock.</pre><ul><li>Try to list shared devices in lockd VGs from hosts not using lvmlockd.</li></ul><pre>// output from node 3 having access to shared disk<br>ubuntu@ip-172-31-180-34:~$ vgs --options vg_all --reportformat json --units b<br>  {<br>      &quot;report&quot;: [<br>          {<br>              &quot;vg&quot;: [<br>              ]<br>          }<br>      ]<br>  }</pre><p>However, we we see the shared vg with — shared option for reporting and display commands like the — foreign option does for foreign VGs. <br><strong>Note: </strong>From a host not using lvmlockd, lockd VGs are ignored in the same way as foreign VGs.</p><pre>// vgs output on node 1<br>ubuntu@ip-172-31-180-34:~$ sudo vgs --shared<br>  VG              #PV #LV #SN Attr   VSize   VFree  <br>  shared-vg         1   0   0 wz--ns &lt;20.00g &lt;19.75g</pre><ul><li>Try to create/remove a LV on a lockd VG from a host where the lockspace is not found(i.e the host did not have the <em>vgchange — lock-start</em> command executed).</li></ul><pre>// stop the lockspace for shared vg on the host first<br>ubuntu@ip-172-31-85-197:~$ sudo vgchange --lock-stop</pre><pre>// try to create a new lv on the above vg<br>ubuntu@ip-172-31-85-197:~$ sudo lvcreate -n shared-vg -L 1G shared-lv2<br>  Cannot access VG shared-vg due to failed lock.</pre><pre>// try to remove an old deactivated lv on the above vg<br>ubuntu@ip-172-31-85-197:~$ sudo lvremove shared-vg/shared-lv<br>  Cannot access VG shared-vg due to failed lock.</pre><p><strong>Note:</strong> Similar scenario can happen in case of node failures. Here, we try to simulate a node failure scenario case</p><pre>// hard reboot the host<br>ubuntu@ip-172-31-85-197:~$ sudo reboot -h now<br>Connection to ec2-34-207-128-38.compute-1.amazonaws.com closed by remote host.<br>Connection to ec2-34-207-128-38.compute-1.amazonaws.com closed.</pre><pre>// list the vgs in the host after reboot<br>ubuntu@ip-172-31-85-197:~$ sudo vgs<br>  Skipping global lock: lockspace not found or started<br>  Reading VG shared-vg without a lock.<br>  VG              #PV #LV #SN Attr   VSize   VFree  <br>  shared-vg         1   3   0 wz--ns &lt;20.00g &lt;17.74g</pre><pre>// try to change the state of a previously created lv<br>ubuntu@ip-172-31-85-197:~$ sudo lvchange -ay shared-vg/shared-lv<br>  Cannot access VG shared-vg due to failed lock.</pre><ul><li>Try to activate/deactivate thin volumes on different nodes.</li></ul><pre>// list lvs on <br>ubuntu@ip-172-31-85-197:~$ sudo lvs<br>  LV                VG              Attr       LSize   Pool            Origin Data%  Meta%  Move Log Cpy%Sync Convert                                                              <br>  shared-lv         shared-vg       -wi-a-----   1.00g                                                               <br>  shared-thin-lv    shared-vg       Vwi-a-tz-- 100.00m shared-thinpool        0.00                                   <br>  shared-thinpool   shared-vg       twi-aotz--   1.00g                        0.00   11.04</pre><pre>// lv status on node 1<br>ubuntu@ip-172-31-85-197:~$ sudo lvdisplay<br>  --- Logical volume ---<br>  LV Path                /dev/shared-vg/shared-lv<br>  LV Name                shared-lv<br>  VG Name                shared-vg<br>  LV UUID                P2qnc2-9wPa-ZXj1-JEiL-4BRO-0Ytd-6sR0Rx<br>  LV Write Access        read/write<br>  LV Creation host, time ip-172-31-85-197, 2022-04-04 12:30:42 +0000<br>  LV Status              available<br>  # open                 0<br>  LV Size                1.00 GiB<br>  Current LE             256<br>  Segments               1<br>  Allocation             inherit<br>  Read ahead sectors     auto<br>  - currently set to     256<br>  Block device           253:3<br>   <br>  --- Logical volume ---<br>  LV Name                shared-thinpool<br>  VG Name                shared-vg<br>  LV UUID                r6cz3j-ALVJ-G2jq-f5po-qeAV-1QXd-lgDgPL<br>  LV Write Access        read/write (activated read only)<br>  LV Creation host, time ip-172-31-85-197, 2022-04-04 13:27:37 +0000<br>  LV Pool metadata       shared-thinpool_tmeta<br>  LV Pool data           shared-thinpool_tdata<br>  LV Status              <strong>available</strong><br>  # open                 2<br>  LV Size                1.00 GiB<br>  Allocated pool data    0.00%<br>  Allocated metadata     11.04%<br>  Current LE             256<br>  Segments               1<br>  Allocation             inherit<br>  Read ahead sectors     auto<br>  - currently set to     256<br>  Block device           253:6<br>   <br>  --- Logical volume ---<br>  LV Path                /dev/shared-vg/shared-thin-lv<br>  LV Name                shared-thin-lv<br>  VG Name                shared-vg<br>  LV UUID                1HkC6t-26Ce-xRqP-9f7G-LCKt-fhPK-pwsSqE<br>  LV Write Access        read/write<br>  LV Creation host, time ip-172-31-85-197, 2022-04-04 13:27:37 +0000<br>  LV Pool name           shared-thinpool<br>  LV Status              <strong>available</strong><br>  # open                 0<br>  LV Size                100.00 MiB<br>  Mapped size            0.00%<br>  Current LE             25<br>  Segments               1<br>  Allocation             inherit<br>  Read ahead sectors     auto<br>  - currently set to     256<br>  Block device           253:8</pre><pre>// deactivate the shared-thin-lv on node 1<br>ubuntu@ip-172-31-85-197:~$ sudo lvchange -an shared-vg/shared-thin-lv</pre><pre>// activate shared-thin-lv on node 2<br>ubuntu@ip-172-31-91-92:~$ sudo lvchange -ay shared-vg/shared-thin-lv<br>  LV locked by other host: shared-vg/shared-thinpool<br>  Failed to lock logical volume shared-vg/shared-thin-lv.</pre><p><strong>Note: <br></strong>1. Shared activation (i.e active on all nodes) is not compatible with LV type thin-pool<strong>. </strong>LV types that cannot be used concurrently from multiple hosts include thin, cache, raid, mirror, and snapshot.</p><p>2. For thin volumes, both the volume as well as thin pools need to activated/deactivated for making it fully operational on one node.</p><pre>// activate the thin-pool in shared mode<br>ubuntu@ip-172-31-85-197:~$ sudo lvchange -asy shared-vg/shared-thinpool<br>  Shared activation not compatible with LV type thin-pool of shared-vg/shared-thinpool</pre><pre>// deactivate both thin pool and volume on node 1<br>ubuntu@ip-172-31-85-197:~$ sudo lvchange -an shared-vg/shared-thinpool<br>ubuntu@ip-172-31-85-197:~$ sudo lvchange -an shared-vg/shared-thin-lv</pre><pre>// activate thin pool and volume on node 2<br>ubuntu@ip-172-31-91-92:~$ sudo lvchange -ay shared-vg/shared-thinpool<br>ubuntu@ip-172-31-91-92:~$ sudo lvchange -ay shared-vg/shared-thin-lv</pre><ul><li>Mount a deactivated lv on a host.</li></ul><pre>// deactivate lv on the host where it is already activated<br>ubuntu@ip-172-31-91-92:~$ sudo lvchange -an shared-vg/shared-lv</pre><pre>// format the volume with ext4 filesystem<br>ubuntu@ip-172-31-91-92:~$ sudo mkfs.ext4 shared-vg/shared-lv<br>mke2fs 1.45.5 (07-Jan-2020)<br>The file shared-vg/shared-lv does not exist and no size was specified.</pre><pre>// deactivated volume is not visible to the host as a device mapper object<br>ubuntu@ip-172-31-91-92:~$ ls -l /dev/mapper<br>total 0<br>lrwxrwxrwx 1 root root       7 Apr  7 05:40 shared--vg-lvmlock -&gt; ../dm-0</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58d37f8b3e57" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>