{"id":2104782,"date":"2022-02-16T22:49:00","date_gmt":"2022-02-16T20:49:00","guid":{"rendered":"http:\/\/nhub.news\/?p=2104782"},"modified":"2022-02-17T00:03:35","modified_gmt":"2022-02-16T22:03:35","slug":"getting-started-with-apache-cassandra","status":"publish","type":"post","link":"http:\/\/nhub.news\/ru\/2022\/02\/getting-started-with-apache-cassandra\/","title":{"rendered":"Getting Started With Apache Cassandra"},"content":{"rendered":"<p style=\"text-align: justify;\"><b>In this hands-on primer on the powerful open-source NoSQL database Apache Cassandra, our discussion includes the CAP theorem and how to structure data.<\/b><br \/>\nJoin the DZone community and get the full member experience. Apache Cassandra\u00ae is a distributed NoSQL database that is used by the vast majority of Fortune 100 companies. By helping companies like Apple, Facebook, and Netflix process large volumes of fast-moving data in a reliable, scalable way, Cassandra has become essential for the mission-critical features we rely on today. In this post, we will: Relational database management systems (RDBMS) dominated the market for decades. Then, with the rise of Big Tech like Apple, Facebook, and Instagram, the global datasphere skyrocketed 15-fold in the last decade. RDBMS simply weren\u2019t ready to cope with the new data volume or new performance requirements. Figure 1. Skyrocketing data needs. NoSQL was not only invented to cope with massive volumes of data but also to tackle the challenge of both velocity (speed requirements) and variety (all the different types of data and data relations in the market). Other than tabular databases like Cassandra, we\u2019ve also seen the rise of other types of NoSQL databases, such as: Known for its performance at scale, Cassandra is regarded as the Lamborghini of the NoSQL database world: it is essentially infinitely scalable. There is no leader node, and Cassandra is a peer-to-peer system. For example, at Netflix, Cassandra runs 30 million ops\/second on its most active single cluster and 98% of streaming data is stored on Cassandra. Apple runs 160,000+ Cassandra instances with thousands of clusters. There are eight features that make Cassandra powerful: In Cassandra, all servers are created equal. Unlike traditional architecture, where there is a leader server for write\/read and follower servers for read-only, leading to a single point of failure, Cassandra\u2019s leader-less (peer-to-peer) architecture distributes data across multiple nodes within clusters (also known as data centers or rings). Figure 2. Apache Cassandra structure. A node represents a single instance of Cassandra, and each node stores a few terabytes of data. Nodes \u201cgossip\u201d or exchange state information about themselves and other nodes across the cluster for data consistency. When one node fails, the application contacts another node, ensuring 100% uptime. In Cassandra, data is replicated. The replication factor (RF) represents the number of nodes used to store your data. If RF = 1, every partition is stored on one node. If RF = 2, then every partition is stored on two nodes, and so on. The industry standard is a replication factor of three, though there are cases that call for using more or fewer nodes. The famous \u201cCAP\u201d theorem states that a distributed database system can only guarantee two out of these three characteristics in case of a failure scenario: Consistency, Availability, and Partition Tolerance: Any database system, including Cassandra, has to guarantee partition tolerance: It must continue to function during data losses or system failures. To achieve partition tolerance, databases have to either prioritize consistency over availability \u201cCP,\u201d or availability over consistency or \u201cAP\u201d. Cassandra is usually described as an \u201cAP\u201d system, meaning it errs on the side of ensuring data availability even if this means sacrificing consistency. But that\u2019s not the whole picture. Cassandra is consistently configurable: You can set the consistency level you require and tune it to be more AP or CP according to your use case. Cassandra\u2019s innate architecture can handle and distribute massive amounts of data across thousands of servers without experiencing downtime. Each Cassandra node and even each Cassandra driver knows data allocation in a cluster (it\u2019s called token-aware), so your application can contact any server and receive fast answers. Figure 3. Data distribution across multiple nodes. Figure 4. Overall data structure on Cassandra. Cassandra stores data in partitions, representing a set of rows in a table across a cluster. Each row contains a partition key \u2013 one or more columns that are hashed to determine how data is distributed across the nodes in the cluster. Why partitioning? Because this makes scaling so much easier! Big data doesn\u2019t fit in a single server. Instead, it\u2019s split into chunks that are easily spread over dozens, hundreds, or even thousands of servers, adding more if needed. Once you set a partition key for your table, a partitioner transforms the value in the partition key to tokens (also called hashing) and assigns every node with a range of data called a token range. Cassandra then distributes each row of data across the cluster by the token value automatically. If you need to scale up, just add a new node, and your data gets redistributed according to the new token range assignments. On the flip side, you can also scale down hassle-free. Data architects need to know how to create a partition that returns queries accurately and quickly before they create a data model. Once you\u2019ve set a primary key for your table, it cannot be changed. Instead, you\u2019ll need to create a new table and migrate all the new data. Opinions expressed by DZone contributors are their own.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this hands-on primer on the powerful open-source NoSQL database Apache Cassandra, our discussion includes the CAP theorem and how to structure data. Join the DZone community and get the full member experience. Apache Cassandra\u00ae is a distributed NoSQL database that is used by the vast majority of Fortune 100 companies. By helping companies like [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2104781,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[93],"tags":[],"_links":{"self":[{"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/posts\/2104782"}],"collection":[{"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/comments?post=2104782"}],"version-history":[{"count":0,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/posts\/2104782\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/media\/2104781"}],"wp:attachment":[{"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/media?parent=2104782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/categories?post=2104782"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nhub.news\/ru\/wp-json\/wp\/v2\/tags?post=2104782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}