Developer Newsletter: Flexible Cassandra Data Models with User-Defined Types | Cassandra 4.0 Beta
This issue edited by Sushant Kumar (sushantkr16), Technical Architect @ JCPenney
Cassandra being a NoSQL database, denormalization and duplication of data is allowed and considered normal. Cassandra supports many data types and one of them is user-defined types (UDTs).
UDTs are a kind of custom data type which can be completely user-requirement based and can contain one or more data fields. These data fields have their own individual data types, including collections (Sets, Lists, and Maps). The benefit of a UDT is that it allows you to group multiple fields and store nested objects in the same table rather than in another separate table.
For example, let’s say we’re planning a marathon. We want to make sure we have all the information related to a marathon such as name, venue, distance, and date stored, and also the basic information of the person who has won the particular marathon. To store this data in Cassandra, either we need to have two different tables, which might not be feasible, or all the columns individually stored, which makes columns cluttered in the whole row.
A better design is to create a table with all the marathon details and use a UDT to store the winner details. Now this UDT can be stored as a single column in the table. This also makes the data very easy to read, as in this JSON response.
{
"marathonDate" : "2020-07-26",
"marathonName" : "LA marathon",
"distance" : "50m",
"venue" : "LA",
"winner" : {
"firstName" : "Jhon",
"lastName" : "Doe",
"marathonParticipantNumber" : "2345"
}
}
UDTs offer flexibility in storing required details in easily readable formats without greatly impacting performance. DataStax drivers for various languages can serialize and deserialize the data to POJO's/Domain objects. To see UDTs in action in a Java Spring Boot application, check out this example on GitHub.
Notable Software Releases
- Cassandra 4.0 Beta 1 - the long-awaited 4.0 is getting closer and closer to full release! This is shaping up to be the most stable Cassandra release ever. Congratulations to everyone involved in making this happen. Here are a few articles we noticed in various tech outlets: The Register, Tech Republic, Datanami, and SD Times.
- DataStax Desktop 2.2.0 - this tool provides a quick way to try out the Cassandra 4.0 Beta on your desktop (release notes).
Upcoming Events
- Cassandra Workshop series - We have just reached the halfway mark of this 8 week series! So far we have covered the basics of Cassandra, how to data model with Cassandra and how to build apps with Cassandra. It is not too late to get involved! Catch up and join us for the second half where we delve into monitoring and maintaining your deployments.
Community Highlights from Cassandra.Link
- Cassandra Chaos Engineering with Litmus - Great article showcasing how to test a resilient deployment of Cassandra on Kubernetes. (more about Litmus)
- Blitzz.io - Cloud Native Data Replication - Interesting self-contained data replication software that runs on K8s that can sync between Cassandra, MySQL, PostgreSQL
- Redash.io - Open Source Query Visualization Notebook - Very useful multi-database tool that works with Cassandra. It’s not Tableau but it’s pretty nice for being free.
- Exploring Presto and Zeppelin for Fast Data Analytics & Visualization - Like Cassandra, Presto was born out of Facebook. It’s a multi-db data virtualizer that makes it possible to do SQL joins and aggregations against Cassandra and other data-sources.
Example of the Week
- Microservices with Spring, Kubernetes, and Cassandra
Contributed by @clun, @csplinter, @fpmoles - This example contains sample inventory microservices to demonstrate how to use Spring, Kubernetes, and Cassandra together in a single stack.
- Read the VMWare blog post: Save Your Stack: Build Cloud Native Apps with Spring, Kubernetes and Cassandra
- Walkthrough this example with Chris Splinter: YouTube Video
- Become a contributor! Try this example, add your own flair, and submit a PR. Or submit your own example through the DataStax Examples Submission Form or example@datastax.com
What topics would you like to hear more about? Working on something interesting? We’d love your feedback: developer@datastax.com | @DataStaxDevs.