<?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 Smritigupta on Medium]]></title>
        <description><![CDATA[Stories by Smritigupta on Medium]]></description>
        <link>https://medium.com/@smritigupta1811?source=rss-f418ef0a21ed------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*laOJXWA9mzcTZK7f</url>
            <title>Stories by Smritigupta on Medium</title>
            <link>https://medium.com/@smritigupta1811?source=rss-f418ef0a21ed------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 19:38:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@smritigupta1811/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[Partitioning and Sharding]]></title>
            <link>https://medium.com/@smritigupta1811/partitioning-and-sharding-973ad5ca6f0d?source=rss-f418ef0a21ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/973ad5ca6f0d</guid>
            <dc:creator><![CDATA[Smritigupta]]></dc:creator>
            <pubDate>Fri, 07 Apr 2023 13:57:40 GMT</pubDate>
            <atom:updated>2024-04-07T09:05:29.085Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Partitioning</strong><br>It refers to splitting the data in a database into multiple smaller databases within the same instance.</p><p><strong>Sharding</strong><br>It refers to distributing (splitting/replicating) the data across multiple instances.</p><blockquote><strong>Important Points:</strong><br>(1) A shard can have multiple partitions in it. But a partition can reside in only one shard.<br>(2) If a database is partitioned, it does not imply that it is sharded. But if a database is sharded, it implies that the database has definitly been partitioned.</blockquote><p><strong><em>Usecase</em></strong><em> : </em>There is an “Employee” database maintaining the record of all the employees in an organization. The database is present on one server.</p><p><strong><em>Problem</em></strong><em> : </em>With the hiring of more employees, database storage is increasing. The operations on the employee database are also getting increased.</p><p><strong><em>Solution </em></strong>: We can scale the system vertically. It means we can increase the storage capacity, CPU, and memory in the server. But we can’t increase the storage or memory beyond a limit. Vertical scaling has a hardware limitation. That is when the concept of sharding and partitioning comes into the picture. They are tightly coupled in a database. We don’t need to implement both. It is dependent on the requirement.</p><p><strong><em>Assumption while using sharding and partitioning </em></strong>: Employee database’s data is partitioned/sharded on the employee Id.</p><p><strong>Alternative 1 :</strong></p><p>We can partition the database into multiple databases in one server only. When we request the details of a particular employee, the partition corresponding to that record is fetched. So the request is forwarded to that partition, and the data is fetched.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*DmOwlZYHeyu4_eLlj9v-ng.jpeg" /><figcaption>Distribution using partitioning</figcaption></figure><p><strong>Alternative 2:</strong></p><p>We can distribute the data across two shards without partitioning . If we have more read operations, we should replicate the complete data in another server instead of splitting the database. This will increase the parallel processing of read queries. When we request the details of a particular employee, the partition corresponding to that record is fetched. With the partition detail, we find the shard in which it is present. So the request is forwarded to that shard, and the data is fetched.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*qJOIP663TjqUW-89BeGKPg.jpeg" /><figcaption>Distribution using sharding</figcaption></figure><p><strong>Alternative 3</strong><em>:</em></p><p>We have split <em>10000</em> records into four partitions of <em>2500 </em>records each. We have distributed these partitions among two shards. When we request the details of a particular employee, the partition corresponding to that record is fetched. With the partition detail, we find the shard in which it is present. So the request is forwarded to that shard, and the data is fetched.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*7_MK56JyBKppMNV_F3Xkxg.jpeg" /><figcaption>Data distribution using both partitioning and sharding</figcaption></figure><p>We can distribute the data using any of the alternatives depending upon usecase and considering their effectiveness and cost.</p><p><strong>Pros of Sharding and Partitioning </strong><br>(1) It handles large read/write workloads and high throughput requirements. <br>(2) The overall storage capacity is increased.<br>(3) By replicating the data, sharding can increase the availability of the database. It ensures that the operations are not affected if one shard goes down.<br>(4) Partitioning allows the databases to scale out, without redesigning the original database schema.</p><p><strong>Cons of Sharding and Partitioning</strong><br>(1) The queries can be operationally complex if data is on different servers or different partitions. <br>(2) Maintainence and data consistency will be a little challenging.<br>(3) If one partition/shard is lost, the data concerned inside that partition/shard will also be lost.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=973ad5ca6f0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[RowStore vs ColumnStore Databases]]></title>
            <link>https://medium.com/@smritigupta1811/rowstore-vs-columnstore-databases-4a53b3bb71d1?source=rss-f418ef0a21ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a53b3bb71d1</guid>
            <dc:creator><![CDATA[Smritigupta]]></dc:creator>
            <pubDate>Fri, 07 Apr 2023 07:22:24 GMT</pubDate>
            <atom:updated>2023-04-07T07:28:07.266Z</atom:updated>
            <content:encoded><![CDATA[<p>Before going into the concept of RowStore and ColumnStore Database, there are a few storage concepts that we need to look into.</p><p><strong>Row_id</strong>: It is the system-maintained id, required to uniquely identify a row. In most of the databases, it is equivalent to primary_key. In some databases( like Postgres) row_id column is created and maintained by the system.</p><p><strong>Pages</strong> -&gt; Pages are also called logical blocks in a disk. Pages are fixed-size memory locations. Rows are stored on these logical pages. It can fit many rows. The number of rows we can save on a page is dependent on the size of the row, column, and domain type of the column used.</p><p><strong>IO</strong> -&gt; It is a read/write request to the physical disk. It is the speed with which the data transfer takes place between the hard disk drive and RAM. We try to minimize the number of IOs.</p><p>We are storing the tables on the disk in the form of rows. The number of rows that can be inserted into one block depends on the row and the block size. A row can be stored in one or more than one blocks.</p><p>RowStore :</p><blockquote>In such databases, the table records are stored in a sequence of rows. The whole row is stored in a contagious memory location. One row will store the data for 1 table record, the other row will store the data for another record, and so on.</blockquote><p>ColumnStore :</p><blockquote>In such databases, the table records are stored in a sequence of columns. The entries of one column are stored in a contagious memory location. One row will store the data for 1 column, the other row will store the data for another column and so on.</blockquote><p>Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*8PyH9zww_8MlP8zcN1HfXA.png" /><figcaption>Employee table</figcaption></figure><p>For Rowstore the data will be stored as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*SHjHAdUV9Zb2Eon5989IXQ.png" /></figure><p>For Columnstore the data will be stored as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*OmLfLfHrIKePCNmqhpxcyQ.png" /></figure><p>Let us look at some queries below and observe how the working of the two databases differ.</p><blockquote><strong><em>(1) Select * from emp_id where id = 1</em></strong></blockquote><p>RowStore: We will have <strong><em>x</em></strong> no of IOs to get the row where id =1. Once that row is retrieved, all the details for that record will be available in this row only. In this way, we will be able to fetch the desired result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*hop9p4EepKGqTSJ-zrskGQ.png" /><figcaption>Rowstore</figcaption></figure><p>ColumnStore: We will first check the row where the id details are present. From that, we will get the row_id where id =1. Using this row_id(1001), we will fetch the details from every row with that particular row_id. In this way, we will be able to get the desired result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*ie_4vH_W150boWD5FYIEng.png" /><figcaption>Columnstore</figcaption></figure><p><strong>Observation</strong> -&gt; For SELECT * query, using the columnstore databases will be less efficient with respect to rowstore databases. In the case of columnstore, the more the number of columns there, the more IO requests will be there. In the case of rowstore, it will be comparatively less as we will get complete record detail from one row itself.</p><blockquote><strong><em>(2) Select first_name from emp where ssn = 666;</em></strong></blockquote><p>RowStore: We will search for the row where ssn = 666. Once we get that row, we will fetch the first name. In this way, we will get the desired result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*6DV3cpJrF3jom2-9paG_lQ.png" /><figcaption>Rowstore</figcaption></figure><p>ColumnStore: We will first check the row where ssn details are saved. From that, we will get the row_id where ssn = 666. Using this row_id(1006), we will fetch the desired result from the row where first_name is stored.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*yEt9TlrQ-0wW6y1FFtYxqw.png" /><figcaption>Columnstore</figcaption></figure><p><strong>Observation </strong>-&gt; In the case of columnstore, we are getting the exact details based on columns used in the query. No extra data is stored. However, in the case of rowstore, along with the desired column, we are getting other column details too. We need the information in only one column. If the number of columns is more, then extra data will be stored, which may be irrelevant. In such cases, we prefer columnstore over rowstore. However, if we are fetching the details of more than one column, then rowstore is preferred.</p><blockquote><strong><em>(3) Select sum(salary) from emp;</em></strong></blockquote><p>RowStore: We will search for the salary details from every row. Once all the values are fetched, we will apply the aggregate function to it and get the desired result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/1*mLlh8dgXBikyRvmOvX901A.png" /><figcaption>Rowstore</figcaption></figure><p>ColumnStore: We will get all the salary data from only one row. We can apply the aggregate function on the values retrieved from this row and get the desired result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*bgP7SBd3K6ALmt5KqGguHg.png" /><figcaption>Columnstore</figcaption></figure><p><strong>Observation </strong>-&gt; In the above query, we use the aggregation function SUM that applies to a column. All the data for a particular column is present in one place. IO requests will be fewer in number. Columnstore databases will be efficient here. On the other hand, the rowstore databases&#39; performance will not be good. IO operation will be directly proportional to the number of rows. We will also get irrelevant data.</p><p><em>Apart from other queries, there are certainly other factors that should be considered.</em></p><blockquote><strong>Write to the disk</strong></blockquote><p>If we are inserting rows in rowstore databases, it will be more efficient. We will be inserting a complete record detail at once. In columnstore databases, we will insert the record detail in every row corresponding to the column. The latter one is a very costly operation. For this reason, rowstore databases are preferred for OLTP (Online Transaction Processing) and column databases for OLAP (Online Analytical Processing).</p><blockquote><strong>Compression</strong></blockquote><p>Data compression is required to reduce database storage size. It is also needed to improve the performance of the existing data. The record contains the value of different domain types. Hence size also differs for them. So, it is challenging to apply compression functions on rowstore column databases. On the other hand, for columnstore, the consequent values are of the same type. Hence the compression operation is preferred on columnstore databases.</p><h4>Conclusion: Both of the databases have their own pros and cons. There are various factors that governs the selection of a particular database. General consideration is if you are doing a lot of analytics then use columnstore databases. If we are doing a lot of transactions then use rowstore databases. So it is always dependent on the usecase.</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a53b3bb71d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Real Time Streaming and why Kafka is preferred over RabbitMQ]]></title>
            <link>https://medium.com/@smritigupta1811/real-time-streaming-and-why-kafka-is-preferred-over-rabbitmq-5316ad6ad4eb?source=rss-f418ef0a21ed------2</link>
            <guid isPermaLink="false">https://medium.com/p/5316ad6ad4eb</guid>
            <dc:creator><![CDATA[Smritigupta]]></dc:creator>
            <pubDate>Mon, 14 Mar 2022 13:15:55 GMT</pubDate>
            <atom:updated>2022-03-14T13:15:55.621Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong><em>Introduction</em></strong></h3><p>Today, we are dealing with a large amount of data generated in several applications. The problem that is there in front of us is processing of the large volume of <em>data</em>. We first collect the data, then process it and finally store the obtained results. The outcome of the processing is available after a specific time. The insights derived from the processing are valuable but not all insights are equal. Some insights are highly valuable shortly after the data is initially generated and its value diminishes fast with the time. In many cases the data points are highly time sensitive. We expect some unified set of functionalities from our application. We need to integrate different services, systems of the application. For real time data the integration becomes more critical. We need to formulate some critical decision criteria to evaluate best messaging service. These include <em>time sensitivity, decoupling, reliability, scalability</em>. Time sensitivity is a critical element of real time data integration. Data should be available in time-critical manner. Next is decoupling. It should be achieved in order to maintain flexibility for the producer and consumer in case they need some modification. The goal is to minimize the dependency among producers and consumers. Then we come across reliability. Reliability is all about failure free operations. Another important criteria is scalability. The application should be horizontally scalable.</p><p>Real time streaming requires the interaction of the devices with each other and there comes the role of messaging services. We use messaging services like <strong>KAFKA</strong> and <strong>RabbitMQ</strong> to exchange the needed information. At a high level, they provide similar functionality, but there are some important differences between them which makes Kafka preferable over RabbitMQ. Understanding the two will help us draw the concerned inference.</p><h3><strong>What is Kafka and rabbitMQ?</strong></h3><p>Before learning about the two services, first we need to look into the two types of messaging pattern.</p><p>(a) <strong>Point to point</strong> :- In this pattern message is sent from the producer P and can be received by one or more than one consumer. The message is inserted in the queue. There can be multiple messages present in the queue. One message can be consumed by only one consumer. Others won’t be able to consume the same message. Basically we can have multiple consuming apps but each message can be consumed by only one consumer.</p><p>(b) <strong>Publish/ Subscriber model</strong> :- This pattern comprises of a topic along with a queue. There is one producer and multiple consumers and the same message can be received by all concerned consuming apps. Producer sends some messages by putting the message in the topic. This topic will broadcast the message to all the queues that is connected with this topic. The topic is the link between the publisher and consumer.</p><p>Now let’s understand Kafka and RabbitMQ</p><p><strong><em>Kafka</em></strong></p><p>Apache Kafka is an open-source distributed event streaming platform. It is a message bus developed for high-ingress data streams. It is a durable message broker that helps applications to process, store and re-process streamed data. Kafka has a routing key to send messages to a topic. It is an implementation of Pub-Sub model.</p><p>Apache Kafka consists of producer, topics, partitions, consumers, brokers, clusters. The producer send records to clusters which store the record and pass the message to the consumer. The broker acts as a<strong> </strong>Kafka server. The messages are stored in the same sequence as they arrive at the broker. The topics are used in Kafka. Each topic is further split into one or more than one partition. A producer appends the record to a partition and the consumer subscribe to the changes.</p><p>Ex: In case of any payment service the topic will be the one dealing with the events related to payment. The partition can serve for read and write functionality. They can either implement these functionalities by using two partitions (one for read and other for write) or a single partition. C1 can be the service which needs both reading and writing while C2 only needs reading of the payment detail</p><p>(1) There are two partitions. Message specific to event 1 is send to partition 1 and one specific to event 2 is sent to partition 2. Since C1 wants to consume messages from both the events it will subscribe to both of the partition while C2 will subscribe to P1 partition only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*Dx2rgLLo2JLyUOQtZqCnYQ.png" /></figure><p>(2) There is a single partition for both events. Since C2 only needs the event 2 so it need some filtering to get message from required event only.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*-C2lO0WOnHFjCQr67ib-kQ.png" /></figure><p><strong><em>RabbitMQ</em></strong></p><p>RabbitMQ is a general purpose message broker that supports protocols including MQTT, AMQP, and STOMP. It can handle background jobs or act as a message broker. It is a variation of pub-sub model, point to point patterns. RabbitMQ implements both point to point and publisher/subscriber approach. It implements the latter approach using exchanges.</p><p>The RabbitMQ architecture includes producers, exchanges, queues, and consumers. A producer pushes messages to an exchange, which then routes messages to queues (or other exchanges). Each consumer wishing to subscribe to an exchange creates a queue. The message exchange then queues produced messages for consumers to consume</p><p>Ex: Let’s say there is a service that provides read and write facility. There are two message exchange that deals with read functionality and then there is another message exchange that deals with write functionality. Consumer C1 wants both reading and writing so it will create the queue that will take messages for both the exchanges. C2 since need only reading functionality so it will create a queue that will take messages from only one exchange</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*wvBatX4Mk0-930v8MpajoQ.png" /></figure><p>After learning about the Kafka and RabbitMQ let us evaluate why Kafka is preferred over RabbitMQ for real time stream processing.</p><h3><strong>What makes Kafka best tool for real time processing:</strong></h3><p>Kafka has below features which make it best tool for real time processing</p><p><strong>Distribution:</strong> Kafka is natively distributed which fits to distribution nature of stream processing. Kafka divides incoming data to partition ordered by offset which are physically distributed over the cluster. Then these partition can feed the stream processor in distributed manner.</p><p><strong>Scalability: </strong>Kafka scales easily without downtime by handling scalability in all four dimensions, i.e. event producers, event connectors, event processors and event consumers.</p><p><strong>Storing Streams of Records in a Fault-Tolerant Durable Way: </strong>In Kafka, data is written to disk in a fault-tolerant way using replication of data. Kafka allows producers to wait for acknowledgment for completion, and a write is not considered complete until it is fully replicated and guaranteed to persist even if the server written to fails. Kafka will perform the same whether you have 50 KB or 50 TB of persistent data on the server. As a result, we can think of Kafka as a kind of special purpose distributed file system dedicated to high-performance, low-latency commit log storage, replication, and propagation.</p><p><strong>Performance: </strong>Apache Kafka uses Sequential Disk I/O to improve speed when constructing queues. Kafka can handle millions of messages in a single second. The Kafka producer does not wait for acknowledgments from the broker and send data as fast as broker can handle. It has high throughput for both publishing and subscribing to messages. It maintains stable performance even if many Terabytes of messages are stored.</p><p><strong>Reliability:</strong> Kafka serves as a buffer between data sources and the stream processor to handle a big load of data. Kafka just simply store all the incoming data and consumers are responsible for the decision how much and how fast they want to process data. This ensure reliable load-balancing that the stream processor will be not overwhelmed by too many data. Kafka retention policy also allows to easy recover from failures during processing (Kafka retain all the data for 7 days by default). Each consumers keep track on offset of last processed message. For this reason if some consumer fails, it is easy to rollback to the point right before failure and start processing again without loosing information or need to reprocess all stream from beginning.</p><h3>Why RabbitMQ is not a good choice for Real-Time Messaging</h3><p>RabbitMQ is best service in terms of decoupling as compared to Kafka. It is fast, but in terms of handling large amounts of events, it is not as fast as Kafka. There is a trade-off between performance with reliability, including persistence, delivery acknowledgements, publisher confirms, and high availability. We can have speed, but at the sacrifice of reliability and robustness for it.</p><p>Suppose there is an application that needs to stream real-time data to our client application. With RabbitMQ, it is a simple setup. The client will act as a consumer of a message queue. We will create a publisher on the server to constantly publish data to the message queue whenever some new data is available. Now as more and more users uses the application we can have following issues.</p><p>At some point of time, the message queues will start to accumulate an increasing number of unacknowledged messages or even the number of ready messages can grow rapidly. The unacknowledged messages are the one that are not yet being pushed to the consumer. These messages indicate that the consumer is not processing the messages fast enough such that the messages are getting queued up on the client application. RabbitMQ prefetches messages from the message queue in order to increase the overall performance since it can fetch messages in the background. The increasing ready count on the message queue indicates the consumer is not able to consume as fast as we were producing messages. If this situation persists, the message queue size will make it difficult for RabbitMQ since it is constantly writing to the secondary storage (I.e. Hard drive, SSD). The increasing I/O demands will impact the performance.</p><p>Now to solve the slow consumer problem we can configure every message and the queue with a short <strong>time to live</strong> value. It will control, for how long the message should be there in queue before it expires and ultimately removed. With the use of TTL feature in RabbitMQ, we can solve the slow consumer and unbounded queue growth issue but it will introduce another issue which is concerned with the reliability.</p><p>If we configure the TTL value to be too small, sometimes our client applications would miss the most up to date messages. In a real-time streaming application, one of the primary goals of your client application is to display the most up to date information. When there are many updates to the same data element, it is acceptable to throw away the stale updates and only display the latest updates. This is known as the conflation technique. If we configure the TTL feature, we are doing the opposite. We were keeping the oldest updates and letting the most recent updates expire. Since the message queue is a first-in-first-out queue, the oldest updates will be consumed before the newest updates. Once the update message gets pushed onto the queue, it must be consumed. In the case of a slow consumer, that consumer might still be consuming an old update while the latest updates expire. We have to tune the TTL value such that it is large enough not to cause the latest update messages to be lost. The TTL value also determines the maximum size of your queue. The larger the value the more messages in your message queue for slower consumers. With the TTL feature enabled, we can no longer guarantee that our client application gets the latest update.</p><p>Above issues leads to the inference that either we can pick reliability over performance or performance above reliability. Basically we can manage to achieve one functionality but on the cost of other one. For real time processing we can’t compromise on the requirement of both reliability and performance.</p><h3><strong>Conclusion</strong></h3><p>Although RabbitMQ is flexible and good at sending and broadcasting messages but it is advisable to not use it. Real-time data applications are based on time-sensitive updates and RabbitMQ does not guarantee this as we have seen from above example. Hence for the same reason we should pick Kakfa for real time stream processing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5316ad6ad4eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>