热门面试题与答案和在线测试
面向面试准备、在线测试、教程与实战练习的学习平台

通过聚焦学习路径、模拟测试和面试实战内容持续提升技能。

WithoutBook 将分主题面试题、在线练习测试、教程和对比指南整合到一个响应式学习空间中。

Chapter 3

Keyspaces, Tables, Columns, Primary Keys, and Data Modeling Basics

Learn how Cassandra organizes data and why primary key design is the center of good modeling.

Inside this chapter

  1. Keyspaces and Tables
  2. Creating a Keyspace
  3. Primary Key Structure Matters Most
  4. Modeling Starts with Queries

Series navigation

Study the chapters in order for the clearest path from beginner Cassandra concepts to advanced distributed operations. Use the navigation at the bottom of each page to move through the full series.

Tutorial Home

Chapter 3

Keyspaces and Tables

A keyspace in Cassandra is similar to a top-level namespace or database container, but it also includes replication settings. Tables hold data, but unlike relational systems, their structure is usually designed around how the application will query data, not around normalized relationships first.

Chapter 3

Creating a Keyspace

CREATE KEYSPACE ecommerce
WITH replication = {
  'class': 'SimpleStrategy',
  'replication_factor': 1
};

This basic example is fine for local learning. Production systems often use data-center-aware replication strategies instead.

Chapter 3

Primary Key Structure Matters Most

CREATE TABLE user_activity (
    user_id UUID,
    activity_time TIMESTAMP,
    activity_type TEXT,
    details TEXT,
    PRIMARY KEY ((user_id), activity_time)
) WITH CLUSTERING ORDER BY (activity_time DESC);

In Cassandra, the primary key has two major parts: the partition key and the clustering columns. The partition key controls data distribution across the cluster. Clustering columns control ordering within a partition. This is one of the most important beginner-to-intermediate concepts in Cassandra.

Chapter 3

Modeling Starts with Queries

Instead of starting with entities and normalizing everything, Cassandra modeling often starts by asking: what exact queries must the application support? If a service needs to fetch recent activity by user, the table should be shaped directly for that access pattern.

版权所有 © 2026,WithoutBook。