VOOZH about

URL: https://dzone.com/articles/cassandra-vs-dynamodb-database-comparison

⇱ Cassandra vs DynamoDB: NoSQL Database Comparison Guide


Related

  1. DZone
  2. Data Engineering
  3. Databases
  4. Comparing Cassandra and DynamoDB: A Side-By-Side Guide

Comparing Cassandra and DynamoDB: A Side-By-Side Guide

Compare Apache Cassandra and Amazon DynamoDB across features, scalability, cost, and use cases to choose the right NoSQL database for your next project.

Likes
Comment
Save
2.2K Views

Join the DZone community and get the full member experience.

Join For Free

Database technologies have gone through revolutions in the last decade. With just a handful of databases before, there are now multiple options — selecting the right one for a new project is often a challenge. The last decade saw the rise in popularity of NoSQL databases, which remove some of the complexities of relational databases for use cases that don’t require structured queries. This article attempts to compare two popular NoSQL databases: DynamoDB and Cassandra. It highlights their features and compares database operations.

Evolution

Cassandra is an open-source database released under the Apache License. It was originally built by Facebook for internal use and open-sourced in 2008. Ongoing development and stewardship of Cassandra is handled by the Apache Software Foundation. The latest version available at the time of writing is 5.0.

DynamoDB is owned by AWS. It was developed by Amazon to handle the large volume of data for their cart operations. Initially used internally, it was launched as a service in AWS in 2012.

Feature Comparison

Feature Apache Cassandra Amazon DynamoDB
Data Model Pros:
- Flexible schema design accommodating semi-structured and unstructured data.
- Designed as a column-based database, it works well for time-series use cases and datasets with wide rows.
-Atomic transaction management using light weight transactions
-Allows multiple values as partition key and sort key
Cons:
- Data modeling can be challenging for beginners.
- Limited support for ad-hoc queries.
Pros:
- Key-value and document-oriented model with flexible schemas.
- Supports secondary indexes for efficient querying.
-Supports atomic transactions using TransactionWrite API
Cons:
- Offers fewer querying options than conventional SQL-based databases.
- Schema design requires careful planning to optimize performance.
-Allows only one partition key and one sort key
Scalability Pros:
- Linear scalability; easily add/remove nodes to adjust capacity.
- Designed for high write and read throughput.
Cons:
- Manual intervention required for scaling operations.
- Potential complexity in managing large clusters.
Pros:
- Automatic scaling with no manual intervention.
- Seamless handling of varying workloads.
Cons:
- Costs can escalate with high throughput requirements.
- Limited control over underlying infrastructure.
Availability Pros:
- Decentralized architecture ensures no single point of failure.
- Replicating data to multiple nodes ensures the system remains available and reliable, even during hardware or network failures.
Cons:
- Requires careful configuration to achieve desired fault tolerance.
Pros:
- Fully managed service with data replicated across multiple availability zones.
- Built-in high availability and durability.
Cons:
- Less control over replication strategies.

Management Pros:
- Full control over configuration and optimization.
- Open-source with a large community for support.
-Connection using JDBC Driver Similar to Relational DB
Cons:
- Requires significant operational expertise to manage and maintain.
- Higher administrative overhead for tasks like backups and monitoring.
Pros:
- Fully managed by AWS, reducing administrative burden.
- Point in time recovery,Automated backups, updates, and maintenance.
-Connection to DB using AWS CLI or AWS SDK
Cons:
- Limited customization options.
- Dependency on AWS for management and support.
Cost Pros:
- Open-source; no licensing fees.
- Cost-effective for large-scale deployments.
Cons:
- Infrastructure and operational costs can accumulate.
- Requires investment in skilled personnel for management.
Pros:
- Pay-as-you-go pricing model.
- No upfront infrastructure costs.
Cons:
- Costs can become significant with high usage patterns.
- Additional charges for features like backups and data transfer and data replication across indexes.

Comparison of Database Operations

Database Operation Apache Cassandra Amazon DynamoDB
Insert
Java
StringBuilder sb = new StringBuilder("INSERT INTO ")
 .append(TABLE_NAME).append("(key, value) ")
 .append("VALUES (").append(keyVal)
 .append(", '").append(valueVal).append("');");
	String query = sb.toString();
 session.execute(query);


Java
Region region = Region.US_EAST_1;
DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();
HashMap<String, AttributeValue> itemValues = new HashMap<>();
itemValues.put(key, AttributeValue.builder().s(keyVal).build());
itemValues.put(value, AttributeValue.builder().s(valueVal).build());
PutItemRequest request = PutItemRequest.builder().tableName(tableName).item(itemValues).build();
PutItemResponse response = ddb.putItem(request);


Update
Java
UPDATE keyspace.tablename 
SET column1 = 'col1Val',column1 = 'col2Val' 
 WHERE id = 'id123';
Java
HashMap<String, AttributeValue> itemKey = new HashMap<>();
itemKey.put(key, AttributeValue.builder().s(keyVal).build());
HashMap<String, AttributeValueUpdate> updatedValues = new HashMap<>();
updatedValues.put(name, AttributeValueUpdate.builder().value(AttributeValue.builder().s(updateVal).build())
 .action(AttributeAction.PUT)
 .build());
UpdateItemRequest request = UpdateItemRequest.builder().tableName(tableName).key(itemKey)
 .attributeUpdates(updatedValues)
 .build();
ddb.updateItem(request);
Delete
Java
//Delete data from specific columns in a row
DELETE col1, col2 FROM keyspace.table WHERE id = 'id123';
//Delete a row
DELETE FROM keyspace.table WHERE id = 'id123';

Java
HashMap<String, AttributeValue> keyToDelete = new HashMap<>();
keyToDelete.put(key, AttributeValue.builder().s(keyVal).build());
DeleteItemRequest deleteReq = DeleteItemRequest.builder().tableName(tableName).key(keyToDelete).build();
ddb.deleteItem(deleteReq);
Select
Java
//Select specific columns in a row
SELECT col1, col2 FROM keyspace.table WHERE id = 'id123';
//Select all columns in a row
SELECT *  FROM keyspace.table WHERE id = 'id123';



Java
// Set up an alias for the partition key name 
HashMap<String, String> attrNameAlias = new HashMap<String, String>();
attrNameAlias.put(partitionAlias, partitionKeyName);
 // Set up mapping of the partition name with the value.
HashMap<String, AttributeValue> attrValues = new HashMap<>();
attrValues.put(":" + partitionKeyName, AttributeValue.builder().s(partitionKeyVal).build());
QueryRequest queryReq = QueryRequest.builder()
 .tableName(tableName)
 .keyConditionExpression(partitionAlias + " = :" + partitionKeyName)
 .expressionAttributeNames(attrNameAlias)
 .expressionAttributeValues(attrValues)
 .build();
QueryResponse response = ddb.query(queryReq);



Conclusion

Apache Cassandra offers flexibility and control, making it suitable for applications requiring high availability and scalability, provided there is expertise to manage its complexity. There are enterprise edition versions of Cassandra like ScalaDB, AstraDB from DataStax, AWS Keyspaces, etc., available from different vendors. They also provide serverless versions, taking away the overhead of maintaining the DB.

Amazon DynamoDB, as a fully managed service, simplifies operations and provides scalability. It’s ideal for teams that want to focus on application development without getting into the nitty-gritty of infrastructure or capacity planning. DynamoDB’s seamless integration with other AWS services, built-in security, and automatic backups make it a strong choice for cloud-native applications and microservices. On the other hand, Cassandra provides more tuning knobs and control for on-prem or hybrid environments. 

Ultimately, the right choice depends on your team's operational maturity, latency tolerance, and budget flexibility. Both databases are powerful in their own ways — it’s just a matter of matching them to your specific use case and long-term strategy.

Amazon DynamoDB Apache Cassandra Data structure

Opinions expressed by DZone contributors are their own.

Related

  • Build a Philosophy Quote Generator With Vector Search and Astra DB
  • Wayland Compositor Debugging in C++: Hunting Null Pointer Crashes in the Display Stack
  • Building High‑Precision Vector Search for Document Retrieval on Databricks
  • Reducing RAG Hallucinations With Relationship-Aware Retrieval

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

Let's be friends: