Cassandra Explained: The Database That Never Goes Down

Cassandra explained in plain terms means understanding the database that keeps answering queries even when servers fail, data centres go dark, and traffic spikes without warning. The central question is how a database can be both enormous and always available, and the answer is to copy every piece of data to several machines, spread the work evenly, and let any machine answer for any other.

Apache Cassandra is a distributed NoSQL database designed for very large amounts of data spread across many ordinary servers, first released in 2008 after being built at Facebook and inspired by Amazon’s Dynamo and Google’s Bigtable. It is used by companies that cannot afford downtime, including banks, retailers, and streaming services.

The idea is simple: there is no master. Every node in a Cassandra cluster is equal, every node can answer any query, and data is copied to several nodes, so the loss of any one machine, or even a whole data centre, does not stop the database. This article explains what Cassandra is, how it works, and where it is used.

Key takeaways

  • Cassandra is a distributed database with no single master node.
  • Data is copied to several nodes, so failures do not stop the service.
  • It scales by adding machines, with no downtime for the change.
  • Writes are fast, because they go to memory and a log first.
  • It suits huge datasets that must always be available.

What Cassandra is

Cassandra is a wide-column NoSQL database, which means it stores data in tables of rows and columns, but with a flexible schema: each row can have different columns, and a single row can hold a very large number of them. That flexibility suits data that does not fit neatly into the fixed tables of a traditional database, such as time series, sensor readings, and user activity.

A Cassandra cluster is a ring of nodes, and each piece of data is assigned to a position on that ring by hashing its partition key. The data is then stored on the nodes responsible for that position, plus copies on the next few nodes, which is called the replication factor, usually three. Any node can coordinate a query, asking the right nodes for the data and returning the answer.

Consistency is tunable, which is one of Cassandra’s defining features. A write or a read can ask for one copy, a majority of copies, or all copies to agree, and the choice trades speed against certainty. A system that needs instant answers can accept one copy, while a system that needs certainty can wait for a majority. Our guide to MongoDB explains the document database that is often compared with Cassandra, and our guide to Redis explains the in-memory store used for the fastest lookups.

How Cassandra works

Writing data starts with the coordinator node, which is whichever node received the request. It writes the change to a commit log on disk, so that nothing is lost if the machine crashes, and then to a memory table, which is fast. The write is acknowledged as soon as enough replicas have accepted it, according to the consistency level chosen.

When a memory table fills up, it is flushed to disk as an SSTable, an immutable sorted file. Cassandra never overwrites data in place; it writes new files and later merges them in a process called compaction, which removes old versions and deleted data, and keeps reads fast.

Reading data means asking the replicas that hold it. The coordinator sends the request to enough replicas to satisfy the consistency level, compares the answers, and returns the newest version, repairing any replica that is out of date in the background, a process called read repair.

Adding a node is a normal operation. The new node joins the ring, takes over part of the data range, and streams the data it needs from its neighbours, all while the cluster keeps serving traffic. Removing a node works the same way in reverse, which is how Cassandra scales without downtime.

Failure is handled by gossip and hinted handoff. Nodes constantly exchange small messages about which other nodes are alive, and if a node is down when a write arrives, another node stores the write as a hint and delivers it when the failed node returns, so that no write is lost.

A laptop on a dark desk with its screen showing a glowing green ring of database nodes sharing copies of data
A laptop showing a glowing green ring of database nodes sharing copies of data shows how Cassandra works: no master, every node equal, every copy safe.

Comparing Cassandra with other databases

Cassandra is one of several NoSQL databases, and each suits a different need. MongoDB stores flexible documents, Redis keeps data in memory for speed, and a traditional relational database enforces strict rules and joins, but each has its own trade-offs.

The table below sets out the main contrasts between the leading approaches.

Aspect Cassandra MongoDB Relational database
Data model Wide-column tables Documents, JSON-like Fixed tables, rows
Scaling Add nodes, no downtime Sharding, more setup Scale up, bigger server
Availability Always on, no master Replica set, one primary Primary and standby
Consistency Tunable per query Strong by default Strong, ACID
Best for Huge, always-on data Flexible app data Transactions, joins

The practical result is that Cassandra is the right choice when data is huge and the service must never stop, MongoDB suits flexible application data, and a relational database remains the choice for transactions and complex queries.

Where Cassandra is used

Streaming services use Cassandra to store viewing history, recommendations, and user activity. Millions of viewers generate billions of events, and Cassandra absorbs the writes and serves the reads without slowing down, even at peak viewing times.

Retailers use Cassandra for shopping carts, product catalogues, and order history. A cart must be available whenever a customer opens it, from any device, and Cassandra’s replication means the data is there even if a data centre is down.

Banks and payment systems use Cassandra for fraud detection and transaction history. A payment must be checked against patterns in a huge history, and the answer must come back in milliseconds, which is why the database is spread across many machines close to the work.

Messaging and social platforms use Cassandra for feeds and messages. A timeline is a time-ordered list of events, which fits Cassandra’s wide-column model well, and the volume of posts means the database must grow by adding nodes rather than by buying bigger servers.

Internet of Things platforms use Cassandra for sensor data. Millions of devices send readings every few seconds, and Cassandra stores the time series, answers queries about recent values, and keeps working as devices are added.

Strengths and limits

The greatest strength of Cassandra is availability. With no master node and data copied to several machines, the cluster keeps working through failures that would stop a traditional database, and it scales in a straight line as nodes are added, which is why it is trusted for services that must never go down.

It is also a strength that Cassandra is fast for writes. Appending to a log and a memory table is cheap, so the database can absorb enormous write loads, which is exactly what sensor data, activity logs, and event streams need.

The limits are real, though. Cassandra has no joins and no ad hoc queries, so data must be modelled around the questions that will be asked, and changing the model later is painful. It also needs careful tuning of compaction and consistency, and running a large cluster takes skilled staff.

Cassandra checklist

  • Model data around your queries, since there are no joins.
  • Use a replication factor of three, across racks or data centres.
  • Choose a consistency level that fits each query’s needs.
  • Keep partitions small, so no single node becomes a bottleneck.
  • Monitor compaction, since it affects read speed.
  • Test node failure, and check the cluster stays available.
  • Use a load balancer or driver that knows the ring.
  • Back up snapshots regularly, even though data is replicated.
  • Plan capacity, since adding nodes takes time and data movement.

Frequently asked questions

What is Cassandra in simple terms?

Cassandra is a database spread across many machines, with no master, where every piece of data is copied to several nodes. It keeps working when machines fail, and it grows by adding more machines.

What is the difference between Cassandra and MongoDB?

Cassandra is a wide-column store built for huge, always-on datasets with tunable consistency, while MongoDB is a document store built for flexible application data with strong consistency by default. Cassandra scales more easily; MongoDB is easier to query.

Is Cassandra a SQL database?

Not exactly. It has its own query language, CQL, which looks like SQL but supports only a subset: no joins, no subqueries, and only queries that the data model was designed for.

How does Cassandra stay available when a node fails?

Because every piece of data is copied to several nodes, and every node can answer any query. When a node fails, the others serve its data, and hinted handoff delivers missed writes when it returns.

What is tunable consistency?

It is the ability to choose, for each read or write, how many copies must agree. One copy is fastest, a majority is safer, and all copies is the strongest, so each query can balance speed against certainty.

When should I use Cassandra?

When your data is very large, must always be available, and is written far more than it is queried in complex ways. Time series, activity logs, and large catalogues are the classic cases.

The bottom line

Cassandra explained in one line is this: a database with no master, where every node is equal and every piece of data is copied, so that the service never stops and the data never disappears.

It is the choice for systems that cannot afford downtime and cannot fit on one machine, and it has proved itself at the largest scale, from streaming video to banking to the sensors of the internet of things.

This article is general information about how Cassandra works, not advice about choosing a database for a particular application.

Latest articles

Scroll to Top