<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Muhammet Yasin ARLI</title>
    <description>The latest articles on DEV Community by Muhammet Yasin ARLI (@muhammetyasinarli).</description>
    <link>https://dev.to/muhammetyasinarli</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1462269%2F7b8e2396-5e33-4289-858a-5ffc39da45bd.jpeg</url>
      <title>DEV Community: Muhammet Yasin ARLI</title>
      <link>https://dev.to/muhammetyasinarli</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/muhammetyasinarli"/>
    <language>en</language>
    <item>
      <title>Database Partitioning vs. Sharding vs. Replication</title>
      <dc:creator>Muhammet Yasin ARLI</dc:creator>
      <pubDate>Sat, 04 May 2024 09:59:27 +0000</pubDate>
      <link>https://dev.to/muhammetyasinarli/database-partitioning-vs-sharding-vs-replication-2bbm</link>
      <guid>https://dev.to/muhammetyasinarli/database-partitioning-vs-sharding-vs-replication-2bbm</guid>
      <description>&lt;h2&gt;
  
  
  Database Partitioning vs. Sharding vs. Replication
&lt;/h2&gt;

&lt;p&gt;The history of partitioning, sharding, and replication dates back several decades and is closely tied to the evolution of database technology and the increasing demand for efficient handling of large amounts of data. These strategies play a crucial role in supporting modern applications and ensuring the effective management of complex datasets.&lt;/p&gt;

&lt;p&gt;Partitioning, sharding, and replication are different strategies used to improve a database’s performance, scalability, and reliability. Each serves a unique purpose and addresses different aspects of database management.&lt;/p&gt;

&lt;h2&gt;
  
  
  Partitioning
&lt;/h2&gt;

&lt;p&gt;Over time, tables containing large amounts of data may begin to experience performance issues with long-running queries and data manipulation (DML) operations. In these situations, dividing the dataset into smaller, more manageable parts can be an effective solution. This approach can enhance query performance, reduce storage requirements, and boost scalability by enabling parallel processing.&lt;/p&gt;

&lt;p&gt;Database partitioning involves splitting a logical database into distinct, independent parts. By doing so, you can manage data more effectively and optimize performance in complex database systems.&lt;/p&gt;

&lt;p&gt;There are typically two main strategies for database partitioning: vertical partitioning and horizontal partitioning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vertical Partitioning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Vertical partitioning refers to dividing a database table into multiple segments, each containing a subset of the columns from the original table. The main reason for using vertical partitioning is to manage columns that are frequently updated. By separating these columns into a different table or partition, you avoid updating the rest of the data unnecessarily.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ap4n-Dh-yqQKtka0WHgETvg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2Ap4n-Dh-yqQKtka0WHgETvg.png" alt="Vertical Partitioning"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Horizontal Partitioning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Horizontal partitioning is a database optimization technique that divides a table into multiple partitions based on rows. Each partition contains a subset of the original table’s rows, which can improve query performance and manageability by distributing data across different partitions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AvxehRGdMUXtFT9j6BvzXeQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AvxehRGdMUXtFT9j6BvzXeQ.png" alt="Horizontal Partitioning"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Sharding
&lt;/h2&gt;

&lt;p&gt;Sharding is a subset of partitioning where different shards are distributed across distinct machines or nodes. This structure offers several benefits, including improved scalability, higher availability, enhanced parallel processing, and faster query execution.&lt;/p&gt;

&lt;p&gt;Sharding is a strategy more commonly used in NoSQL databases, but it is also used in some modern RDBMS. For instance, solutions like Citus and TimescaleDB enable sharding and horizontal scaling with PostgreSQL. MySQL NDB Cluster automatically shards (partitions) tables across nodes.&lt;/p&gt;

&lt;p&gt;Benefits of sharding:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Sharding distributes data across multiple machines, allowing the system to scale horizontally by adding more shards as data and traffic increase.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Queries can be distributed across different shards, enabling parallel processing and faster execution times.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shards can be managed independently, optimizing hardware resources such as CPU, memory, and storage.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Sharding allows data to be distributed across different locations, beneficial for serving global user bases and reducing latency.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Shards can be tailored to specific workloads or data types, enabling more flexible data management and organization.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Replication
&lt;/h2&gt;

&lt;p&gt;Data replication involves creating several copies of the same data and distributing them across different servers. This practice ensures data availability, reliability, and resilience for an organization. By storing data copies in various locations, organizations can safeguard against data loss due to unexpected events such as disasters, outages, or other disruptions. If one copy becomes inaccessible, another copy can be quickly utilized as a backup, enabling continued operations without significant downtime.&lt;/p&gt;

&lt;p&gt;Replication and sharding are often used together. When combined, sharding divides the database into smaller partitions to scale it, while replication maintains multiple copies of each partition to enhance data reliability and availability. This approach allows the system to efficiently handle large volumes of data and remain resilient against potential failures.&lt;/p&gt;

&lt;h2&gt;
  
  
  MongoDB Sharded Cluster Architecture
&lt;/h2&gt;

&lt;p&gt;Finally, I want to show the MongoDB sharded cluster architecture that sharding and replication are used together. Below is a diagram from MongoDB’s official documentation. This method enables MongoDB to efficiently handle large volumes of data while remaining robust and reliable, ensuring seamless operation even in the face of challenges.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A_wT_nXwnim9UJC27G_atiQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2A_wT_nXwnim9UJC27G_atiQ.png" alt="sharded-cluster-components"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A MongoDB sharded cluster consists of the following components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Shards: Data is divided across multiple shards, and each shard is a replication set, which consists of one primary node and one or more secondary nodes. The primary node handles read and write operations, while the secondary nodes replicate the primary’s data and can take over as primary if necessary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Mongos: The mongos is a query router, providing an interface between client applications and the sharded cluster.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Config servers: Config servers store metadata and configuration settings for the cluster.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.mongodb.com/docs/manual/core/sharded-cluster-components" rel="noopener noreferrer"&gt;MongoDB Sharded Cluster Components&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.couchbase.com/resources/concepts/data-replication" rel="noopener noreferrer"&gt;Couchbase Concepts: Data Replication&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.macrometa.com/distributed-data/sharding-vs-partitioning" rel="noopener noreferrer"&gt;Sharding vs. Partitioning by Macrometa&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.cockroachlabs.com/blog/what-is-data-partitioning-and-how-to-do-it-right" rel="noopener noreferrer"&gt;What is Data Partitioning and How to Do It Right by Cockroach Labs&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>## The CAP Theorem (Brewer’s Theorem) in NoSQL Databases</title>
      <dc:creator>Muhammet Yasin ARLI</dc:creator>
      <pubDate>Wed, 01 May 2024 20:53:10 +0000</pubDate>
      <link>https://dev.to/muhammetyasinarli/-the-cap-theorem-brewers-theorem-in-nosql-databases-2lbj</link>
      <guid>https://dev.to/muhammetyasinarli/-the-cap-theorem-brewers-theorem-in-nosql-databases-2lbj</guid>
      <description>&lt;p&gt;&lt;em&gt;The CAP theorem, first introduced by Eric Brewer in 2000 and formalized in 2002, outlines the trade-offs between consistency, availability, and partition tolerance in distributed systems. This theorem serves as a guide for designing robust systems that can manage the complexities of distributed data.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AhIZiZINape0a0H84OHKQog.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AhIZiZINape0a0H84OHKQog.png" alt="CAP theorem Euler diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;According to the CAP theorem, a distributed data system cannot simultaneously provide consistency, availability, and partition tolerance. It can only guarantee two of the three at any given time.&lt;/p&gt;

&lt;p&gt;Before diving into the CAP theorem, let’s define some key terms:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt;: Consistency ensures that all nodes in a distributed system show the same view of the data at all times. When data is updated or written, all subsequent read requests return the latest version of the data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Availability&lt;/strong&gt;: Availability means the system is consistently operational and can quickly handle read and write requests. It ensures users can access data and perform transactions even when some nodes are down.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Partition Tolerance&lt;/strong&gt;: Partition tolerance refers to the system’s ability to function despite network partitions or disruptions in communication between different parts of the system. In other words, a partition-tolerant system can handle network failures that cause communication breakdowns between different parts of the system, without completely ceasing operation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Node&lt;/strong&gt;: In a distributed system, a node is an individual server or instance that stores data and performs operations such as read and write requests. Each node operates independently but can communicate with other nodes through a network.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cluster&lt;/strong&gt;: In distributed systems, a cluster consists of multiple nodes working together to provide efficient, reliable, and scalable services for applications and data management.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;How does the CAP theorem apply to NoSQL databases?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When examing popular nosql databases, it is observed that partition tolerance of CAP is generally esential.&lt;/p&gt;

&lt;p&gt;Because one key reason NoSQL databases have gained popularity is their ability to scale horizontally, unlike relational databases, which typically scale by upgrading the database server (vertical scaling). This approach can be costly and limited.&lt;/p&gt;

&lt;p&gt;NoSQL databases enable horizontal scaling by spreading data across multiple nodes, which helps manage large data volumes and high traffic more efficiently. Consequently, NoSQL databases have become a top choice for modern applications that require large data handling and high performance.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AgyEgQhs7QdD2MgNGC1wrzQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AgyEgQhs7QdD2MgNGC1wrzQ.png" alt="Vertical scaling vs. horizontal scaling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In NoSQL databases, data is shared across multiple nodes, necessitating constant communication and data exchange. The system must continue running even if there are network issues or disconnections. Achieving a true CA (consistency and availability) scenario without sacrificing partition tolerance is not feasible in a distributed system.&lt;/p&gt;

&lt;p&gt;Besides partition tolerance is essential for NoSQL databases, many NoSQL databases like Cassandra and MongoDB can be configured to align with either CP or CA.&lt;/p&gt;

&lt;h2&gt;
  
  
  MongoDB: A Practical Example
&lt;/h2&gt;

&lt;p&gt;To illustrate how NoSQL databases navigate the trade-offs posed by the CAP theorem, let’s examine MongoDB, a popular NoSQL database.&lt;/p&gt;

&lt;p&gt;MongoDB uses a replica set for replication. The primary server manages write operations and replicates changes to the secondary servers. Replication involves maintaining multiple copies of data across different servers, ensuring data remains secure and accessible even if one server experiences an issue.&lt;/p&gt;

&lt;p&gt;If the primary server fails, an automatic election process enables one of the secondary servers to become the new primary. Once the original primary server recovers, it becomes a secondary server.&lt;/p&gt;

&lt;p&gt;By default, MongoDB clients send all read and write requests to the primary node, ensuring consistency within the system. However, if a client loses connection with the primary node or if the primary node becomes disconnected from the cluster, availability may be compromised.&lt;/p&gt;

&lt;p&gt;Thus, in its default configuration, MongoDB offers consistency and partition tolerance but may not maintain high availability in certain scenarios.&lt;/p&gt;

&lt;p&gt;If your priority is availability rather than consistency, you should not use this method.&lt;/p&gt;

&lt;p&gt;You can adjust the &lt;a href="https://www.mongodb.com/docs/manual/core/read-preference/#read-preference-modes" rel="noopener noreferrer"&gt;read preference mode &lt;/a&gt;to read from any available node, which enhances availability. However, this configuration can compromise consistency because the secondary nodes might not have the latest data updates from the primary node.&lt;/p&gt;

&lt;p&gt;This trade-off allows MongoDB to provide availability and partition tolerance but at the expense of consistency in some scenarios.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In conclusion, the CAP theorem provides a useful framework for understanding the trade-offs inherent in distributed systems. By making informed choices about your database’s configuration and understanding how the CAP theorem applies, you can optimize your system to suit your application’s requirements and achieve a balance that meets your business objectives.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.cockroachlabs.com/blog/vertical-scaling-vs-horizontal-scaling/" rel="noopener noreferrer"&gt;Cockroach Labs: Vertical Scaling vs. Horizontal Scaling&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.mongodb.com/docs/manual/replication/" rel="noopener noreferrer"&gt;MongoDB Documentation: Replication&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/CAP_theorem" rel="noopener noreferrer"&gt;Wikipedia: CAP Theorem&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
  </channel>
</rss>
