Last Updated: November 21, 2025
Apache Cassandra
Distributed NoSQL database
Core Concepts
| Item | Description |
|---|---|
Keyspace
|
Top-level namespace (like database) |
Table
|
Collection of rows |
Partition Key
|
Determines data distribution |
Clustering Key
|
Defines sort order within partition |
Node
|
Single server in cluster |
Replication Factor
|
Number of data copies |
CQL Examples
-- Create keyspace
CREATE KEYSPACE my_keyspace
WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 3
};
-- Create table
CREATE TABLE users (
user_id UUID PRIMARY KEY,
username text,
email text,
created_at timestamp
);
-- Insert data
INSERT INTO users (user_id, username, email, created_at)
VALUES (uuid(), 'john_doe', 'john@example.com', toTimestamp(now()));
-- Query data
SELECT * FROM users WHERE user_id = ?;
Data Types
| Item | Description |
|---|---|
text
|
UTF-8 encoded string |
int
|
32-bit signed integer |
uuid
|
Universally unique identifier |
timestamp
|
Date and time |
set
|
Collection of unique elements |
map
|
Key-value pairs |
Best Practices
- Design tables based on query patterns
- Use appropriate partition keys to avoid hotspots
- Denormalize data for read performance
- Set appropriate TTL for time-series data
💡 Pro Tips
Quick Reference
Design schema around query patterns, not normalization