What is the difference between Cassandra and a relational database?
Compare Cassandra and relational databases: data model, consistency, scaling and availability, and learn when to choose each for your application.
Expected Interview Answer
A relational database stores normalized data in tables with fixed schemas, joins, and strong ACID consistency on a single primary node, while Cassandra is a distributed NoSQL store that denormalizes data around queries, spreads it across a masterless ring, and offers tunable consistency for scale and availability.
Relational databases like PostgreSQL model entities once and join them at query time, guaranteeing strong consistency but scaling mainly vertically. Cassandra flips this: you design tables per query, duplicate data freely, and partition it across many nodes so writes and reads stay fast at massive scale. It gives up cross-table joins, foreign keys, and default strong consistency in exchange for horizontal scalability, no single point of failure, and multi-data-center replication.
- Scales horizontally instead of vertically
- No single point of failure
- Handles huge write throughput
- Query-driven, denormalized data model
- Tunable consistency per request
- Native multi-data-center support
AI Mentor Explanation
A relational database is like one meticulous head scorer who keeps a single normalized ledger and cross-references batters, bowlers, and overs on demand — accurate, but one person is the bottleneck. Cassandra is like handing every stadium a purpose-built scoresheet already laid out for the exact stat they report, duplicated across venues. You trade tidy cross-referencing for the ability to keep scoring at a hundred grounds at once with nobody as the single choke point.
Step-by-Step Explanation
Step 1
Compare data models
Relational databases normalize and join; Cassandra denormalizes and designs one table per query.
Step 2
Compare schemas
Relational schemas are rigid with foreign keys; Cassandra tables are query-driven with a partition and clustering key.
Step 3
Compare consistency
Relational gives strong ACID consistency by default; Cassandra offers tunable consistency per request.
Step 4
Compare scaling
Relational scales mostly vertically on one primary; Cassandra scales horizontally across a masterless ring.
Step 5
Compare availability
A relational primary is a single point of failure; Cassandra replicates so the cluster survives node loss.
What Interviewer Expects
- Normalization versus query-driven denormalization
- ACID versus tunable/eventual consistency
- Vertical versus horizontal scaling
- Absence of joins and foreign keys in Cassandra
- When to choose each database
Common Mistakes
- Claiming Cassandra supports joins like SQL
- Assuming Cassandra is always strongly consistent
- Modeling Cassandra tables like normalized relational tables
- Thinking relational databases cannot scale at all
Best Answer (HR Friendly)
“A relational database keeps data neatly organized in linked tables on one main server and is very strict about accuracy. Cassandra spreads copies of data shaped around specific questions across many servers, trading some of that strictness for the ability to grow huge and stay online.”
Code Example
-- Cassandra: design one table per query
CREATE TABLE orders_by_user (
user_id UUID,
order_id TIMEUUID,
total DECIMAL,
status TEXT,
PRIMARY KEY (user_id, order_id)
) WITH CLUSTERING ORDER BY (order_id DESC);
-- Fetch a user's orders directly, no JOIN needed
SELECT * FROM orders_by_user WHERE user_id = 123e4567-e89b-12d3-a456-426614174000;Follow-up Questions
- Why does Cassandra avoid joins?
- What is denormalization and why does Cassandra rely on it?
- How does tunable consistency differ from ACID?
- When would you still pick a relational database?
- What is a partition key in Cassandra?
MCQ Practice
1. How does Cassandra primarily scale compared to a relational database?
Cassandra scales horizontally by adding equal nodes to the ring, while relational databases typically scale vertically.
2. How is data modeled in Cassandra?
Cassandra tables are designed per query and denormalize data, unlike normalized relational schemas.
3. Which is true of Cassandra's consistency?
Cassandra lets you set a consistency level per query, trading latency for stronger agreement among replicas.
Flash Cards
Relational data model? — Normalized tables joined at query time with fixed schemas and foreign keys.
Cassandra data model? — Denormalized, query-driven tables with a partition key and clustering columns.
Consistency difference? — Relational is strong ACID by default; Cassandra is tunable per request.
Scaling difference? — Relational scales vertically; Cassandra scales horizontally across a masterless ring.