Kokil Thapa - Professional Web Developer in Nepal
Freelancer Web Developer in Nepal with 15+ Years of Experience

Kokil Thapa is an experienced full-stack web developer focused on building fast, secure, and scalable web applications. He helps businesses and individuals create SEO-friendly, user-focused digital platforms designed for long-term growth.

Cassandra: Distributed Database Basics

By Kokil Thapa | Last reviewed: September 2026

You reach for Cassandra: Distributed Database Basics when a single MySQL or PostgreSQL server stops keeping up. Write traffic spikes, global users, or always-on mobile apps push relational replicas into conflict. Apache Cassandra spreads data across a cluster with no single master. That design trades joins and ACID guarantees for horizontal scale and fault tolerance. This guide maps the architecture, data model, and production trade-offs so you can decide whether Cassandra belongs in your stack—or whether read replicas on MySQL 8.4 LTS still solve the problem.

What is Cassandra and how does a distributed database work?

Apache Cassandra is an open-source, wide-column store built for always-on workloads. Facebook engineers created it to handle massive inbox traffic. It now powers time-series feeds, IoT pipelines, messaging backends, and analytics ingestion at companies that cannot afford a central database bottleneck.

Unlike a primary-replica SQL setup, every Cassandra node is equal. Any node can accept reads and writes. There is no elected master that serialises the whole cluster. When a node fails, others continue serving data from replicated copies. That peer model is the core of Cassandra distributed database basics.

Cassandra belongs to the NoSQL family, but it is not a document store like MongoDB. It stores rows grouped by partition key inside tables that resemble SQL. You query with CQL (Cassandra Query Language), which looks familiar to anyone who writes SQL for Laravel transactions on MySQL 9.7 or PostgreSQL 18.

Cassandra Token RingNode ATokens 0-25Node BTokens 26-50Node CTokens 51-75Node DTokens 76-99Partition key hashmaps to token range
Cassandra distributed database basics: each node owns token ranges on a logical ring with no single master.

The cluster arranges nodes on a logical ring. Each row’s partition key is hashed to a token. The node responsible for that token stores the primary copy. Replication copies the partition to the next nodes clockwise on the ring. Adding hardware means adding nodes and rebalancing tokens—not buying a bigger single server.

Cassandra favours availability and partition tolerance in the CAP trade-off. Network splits happen. Cassandra keeps serving writes rather than blocking the whole cluster. You tune how many replicas must agree before a read or write succeeds. That is fundamentally different from strict serialisable SQL on one primary.

Core components you should know

  • Node: One Cassandra process on a server; holds a slice of cluster data.
  • Cluster: All nodes sharing the same cluster name and schema.
  • Keyspace: Top-level namespace, similar to a SQL database.
  • Table: Rows grouped by partition key; columns can vary per row.
  • Partition key: Determines which node owns the row.
  • Replication factor (RF): How many copies of each partition exist.
  • Consistency level: How many replicas must respond for a query.

Official reference material lives in the Apache Cassandra documentation. Read the architecture chapter before you provision hardware.

How does Cassandra partition and replicate data across nodes?

Partitioning and replication are the two mechanisms that make Cassandra distributed. Get them wrong and you get hot spots, slow queries, or data loss during failures.

Partitioning with Murmur3 and tokens

Modern Cassandra uses the Murmur3 partitioner. It hashes your partition key into a 64-bit token. Each node owns a range of tokens. When you insert a row, the coordinator node—the one your client contacted—computes the token and forwards the write to the replica nodes responsible for that range.

A hot partition kills performance. If every event shares one partition key, one node handles all traffic. Design keys that spread load: append a time bucket, user ID, or shard suffix. The same principle applies when you plan database sharding on relational engines.

Replication strategies

Two strategies control replica placement:

  1. SimpleStrategy: Places replicas on the next N nodes clockwise. Fine for single-datacenter dev clusters only.
  2. NetworkTopologyStrategy: Places replicas across racks and datacenters. Use this in production.

With RF=3 in one datacenter, Cassandra stores three copies on three distinct racks when rack names are configured. A single rack failure still leaves QUORUM reads and writes intact.

Cassandra Write PathClientdriver sendCoordinatorany nodeReplica 1commit logReplica 2memtableReplica 3SSTablehinted handoff if node downasync repair fixes drift
Write path in Cassandra distributed database basics: coordinator forwards to replicas, then memtables flush to SSTables on disk.

Write path and storage engine

When a write arrives, the replica appends to a commit log on disk first. That log protects against process crashes. The row then lands in an in-memory memtable sorted by key. When the memtable fills, Cassandra flushes it to an immutable SSTable file on disk.

SSTables are append-only. Updates and deletes write new tombstone markers rather than overwriting old bytes in place. Compaction merges SSTables later and removes expired tombstones. Heavy delete workloads without proper compaction settings bloat disk usage—a common production surprise.

Reads check memtables plus all relevant SSTables. Bloom filters and partition key indexes skip irrelevant files. Still, wide partitions with thousands of columns slow reads. Keep partitions under roughly 100 MB as a practical rule cited in Cassandra tuning guides.

What is the Cassandra data model and how do you query it?

CQL looks like SQL but behaves differently. You must design tables around query patterns, not normalise first and join later.

Keyspace and table creation

CREATE KEYSPACE analytics
  WITH replication = {
    'class': 'NetworkTopologyStrategy',
    'datacenter1': 3
  };

USE analytics;

CREATE TABLE events_by_user (
  user_id uuid,
  event_date date,
  event_id timeuuid,
  event_type text,
  payload text,
  PRIMARY KEY ((user_id, event_date), event_id)
) WITH CLUSTERING ORDER BY (event_id DESC);

The double parentheses define a composite partition key. All rows for one user on one date live on the same node. The clustering column event_id sorts rows inside that partition. This table supports “latest events for user X on date Y” efficiently. It does not support “all events across every user today” without a second table keyed by date.

That query-driven modelling mirrors lessons from denormalization when it actually helps. You duplicate data into multiple tables so each access pattern hits one partition.

Query rules that bite newcomers

  • Every query must include the full partition key, or Cassandra scans the cluster.
  • Secondary indexes exist but perform poorly at scale; prefer materialized views or duplicate tables.
  • ALLOW FILTERING is a debug escape hatch, not a production feature.
  • Batch statements only help when all rows share one partition key.
  • Lightweight transactions (LWT) use Paxos and are slow; avoid them on hot paths.

CQL reference syntax is documented in the official CQL developing guide. Treat it like a contract: if your query shape does not match the primary key, redesign the table.

Consistency levels in practice

Consistency is tunable per operation. Common levels:

LevelBehaviourTypical use
ONEOne replica respondsMetrics, logs, best-effort feeds
QUORUMMajority of RF replicasDefault for many production apps
LOCAL_QUORUMMajority within local DCMulti-DC with local reads
ALLEvery replica must respondRare; fragile during failures

For RF=3, QUORUM means two replicas. Writes at QUORUM plus reads at QUORUM give you strong consistency for that query path. Writes at ONE plus reads at ONE give eventual consistency with lower latency.

Consistency Levels RF=3ONE — fastR1R2R31 replica answersQUORUM — safeR1R2R32 of 3 must agreeMatch W + R levels for strong reads
Tunable consistency in Cassandra distributed database basics: ONE minimises latency; QUORUM balances durability and speed.

When should you choose Cassandra over MySQL, PostgreSQL, or MongoDB?

Pick Cassandra when write throughput and uptime matter more than ad-hoc joins. Stay on MySQL 9.7, PostgreSQL 18, or Redis 8.10 when your workload fits a single primary with replicas and predictable schemas.

In my experience working on production Laravel applications, relational databases handle most business CRUD well. I reach for MongoDB when documents vary wildly and relational joins are rare. Cassandra enters the picture when event volume, geographic distribution, or zero-downtime requirements exceed what connection pooling and read replicas can fix.

CriteriaCassandraMySQL / PostgreSQLMongoDB
Write scale-outExcellent — add nodesHard — shard manuallyGood with sharded cluster
Ad-hoc queries / joinsPoor — design per queryExcellentModerate
Multi-DC active-activeBuilt-inComplexPossible with effort
TransactionsLimited LWT onlyFull ACIDMulti-doc since 4.0
Ops complexityHighLow to moderateModerate
Best fitTime-series, IoT, messagingOLTP, eCommerce, ERPFlexible documents

A florist eCommerce site on WooCommerce 11.1 rarely needs Cassandra. High-volume clickstream ingestion for a marketplace directory might. On projects involving large listing platforms, separating hot write paths into a dedicated store while keeping checkout on MySQL is a pattern worth evaluating—similar to how directory platforms at scale split concerns across services.

Good fits for Cassandra

  • Sensor and telemetry ingestion with time-bucketed partition keys
  • Activity feeds where each user reads their own timeline
  • Message storage with high append rates
  • Audit logs retained for compliance with TTL expiry
  • Global apps needing local-quorum reads in each region

Poor fits—keep relational or document stores

  • Checkout, inventory, and ledger systems needing ACID across rows
  • Reporting dashboards with arbitrary filters and aggregates
  • Small teams without dedicated DBA or SRE capacity
  • Apps that rely on foreign keys and cascading deletes

If you are migrating from MySQL, read migration planning guides first. Moving to Cassandra is not a lift-and-shift. It is a schema rewrite and application redesign.

Database Choice Decision TreeNeed strict ACID?YesMySQL / PGNoHuge writes?NoMongoDBYesCassandraCache layer?Use Redis
Decision guide for Cassandra distributed database basics versus relational and document alternatives.

How do you install, operate, and tune Cassandra in production?

Running Cassandra is closer to operating a small distributed system than managing one MySQL instance. Plan hardware, monitoring, backups, and upgrades before you load production traffic.

Minimum cluster and hardware

Never run a single production node. Use at least three nodes so RF=3 and QUORUM survive one failure. Production nodes want fast SSDs, 32 GB RAM or more, and a dedicated commit-log disk when possible. JVM heap typically sits between 8 GB and 16 GB; never push heap past half of system RAM because off-heap memtable and cache need space.

# Ubuntu 24.04 — install from Apache repo (example)
curl -O https://downloads.apache.org/cassandra/KEYS
sudo apt-key add KEYS
echo "deb https://downloads.apache.org/cassandra/debian 50x main" \
  | sudo tee /etc/apt/sources.list.d/cassandra.list
sudo apt update && sudo apt install cassandra -y

# cassandra.yaml essentials
cluster_name: 'prod-analytics'
num_tokens: 256
endpoint_snitch: GossipingPropertyFileSnitch
seed_provider:
  - class_name: org.apache.cassandra.locator.SimpleSeedProvider
    parameters:
      - seeds: "10.0.1.10,10.0.1.11"

Seed nodes help new nodes discover the cluster. They are not masters. List two or three stable IPs. Set rack and datacenter names in cassandra-rackdc.properties when using NetworkTopologyStrategy.

Operations checklist

  1. Run nodetool status after every deploy to confirm all nodes are UN (Up/Normal).
  2. Schedule nodetool repair weekly; it fixes replica drift missed by hinted handoff.
  3. Monitor pending compactions, heap pressure, and read latency p99.
  4. Set TTL on time-series tables so old SSTables expire cleanly.
  5. Test restores from snapshots; a cluster you cannot rebuild is not backed up.
  6. Plan upgrades one node at a time with nodetool drain before restarts.

Backup thinking overlaps with restore testing you should actually do and backup strategies for small servers. Cassandra snapshots plus off-site object storage beat assuming replicas are backups.

For teams without in-house ops capacity, managed Cassandra on cloud vendors or staying on PostgreSQL 18 with read replicas is often cheaper than hiring a Cassandra specialist full-time. That trade-off comes up often on enterprise application projects with limited budgets in Nepal and abroad.

Production Ops CycleDeployrolling restartMonitorlatency p99Repairweekly jobBackupsnapshotsCommon GotchasHot partitions — skewed keysTombstone buildup — missing compactionSkipped repairs — stale readsALLOW FILTERING in prod — full scans
Production operations for Cassandra distributed database basics: rolling deploys, monitoring, repairs, and snapshot backups.

Integrating Cassandra with application stacks

PHP and Laravel apps usually talk to Cassandra through the DataStax PHP driver or a gRPC sidecar microservice. Most teams I work with keep Laravel 13 on MySQL for transactional data and push high-volume events to Cassandra through a queue worker. That hybrid respects database-per-service patterns without rewriting the entire monolith.

Use JSON formatters to inspect event payloads during development. Validate schemas before they land in production tables. For API-facing ingestion, pair Cassandra with solid API design practices—rate limits, idempotency keys, and dead-letter queues prevent poison writes from saturating a partition.

Security matters even on internal clusters. Enable TLS between nodes and clients. Restrict JMX ports with firewall rules—the same mindset as database encryption at rest and in transit. Role-based access in Cassandra grants minimum privileges per application user.

Performance tuning also overlaps with general indexing discipline and query caching strategies. Cassandra has no magical index for every filter. Design beats tuning every time.

If your team runs the cluster on Ubuntu servers you manage yourself, baseline Linux system administration skills matter as much as CQL knowledge. Disk latency spikes show up as p99 read timeouts long before CPU maxes out.

For schema design reviews before you commit to hardware, compare notes with common schema design mistakes on relational systems. Many failures—wide rows, wrong key choice, missing access paths—look the same across engines.

Distributed tracing helps when writes cross services. Tools like OpenTelemetry pair well with Cassandra clusters described in guides on distributed tracing with OpenTelemetry. You see which coordinator node adds latency.

Multi-tenant SaaS products should read multi-tenant database design before sharing one Cassandra cluster across customers. Tenant ID in the partition key prevents cross-tenant leaks and spreads load.

When Cassandra is overkill, caching hot keys in Redis 8.10 or Memcached 1.6.x often buys enough headroom. Not every spike needs a new database engine.

Key Takeaways

  • Cassandra scales writes horizontally via a token ring; every node is a peer with no single master.
  • Design tables around query patterns and partition keys first—joins and ad-hoc filters are anti-patterns.
  • Use NetworkTopologyStrategy with RF=3 and QUORUM for most production read/write paths.
  • Schedule repairs, monitor compactions, and test snapshot restores—replicas are not backups.
  • Keep OLTP checkout and ledgers on MySQL or PostgreSQL; use Cassandra for high-volume append-heavy workloads.
  • Start with a three-node staging cluster and realistic load tests before committing production traffic.

People Also Ask

Is Cassandra a SQL or NoSQL database?

Cassandra is a NoSQL wide-column store. You write CQL that resembles SQL, but there are no flexible joins, foreign keys, or arbitrary WHERE clauses without a partition key. Data model design follows access patterns, not third-normal-form rules.

How many nodes do you need for a Cassandra cluster?

Development can run one node, but production needs at least three nodes in each datacenter where RF=3. That layout lets QUORUM operations survive a single node failure. Multi-datacenter deployments add three or more nodes per region.

Can Cassandra replace MySQL for a Laravel eCommerce site?

Not for core transactional tables. Orders, payments, and inventory need ACID guarantees that MySQL or PostgreSQL provide natively. Cassandra fits adjacent high-write workloads like click tracking, activity logs, or analytics events fed through queue workers.

What causes hot partitions in Cassandra?

A hot partition appears when too many rows share one partition key value. One node then serves disproportionate traffic. Fix it by salting keys, adding time buckets, or splitting data across multiple tables keyed for each query pattern.

Build the right data layer for your scale

Cassandra: Distributed Database Basics come down to one decision: does your workload need peer-to-peer write scale more than relational flexibility? If yes, invest in partition-key design, replication strategy, and operational discipline before you write application code. If no, PostgreSQL 18, MySQL 9.7, or MongoDB with careful sharding will ship faster and cost less to run.

Need help choosing between Cassandra, relational stores, and hybrid architectures for a Nepal or global project? Review the portfolio of shipped systems, browse related posts on the blog, or contact us to talk through your data layer before you provision a cluster you will fight in production.

Frequently Asked Questions

Apache Cassandra is an open-source wide-column store built for always-on workloads. Every node is equal; there is no single master serializing the cluster.

Modern Cassandra uses the Murmur3 partitioner to hash your partition key into a 64-bit token on a logical ring. Each node owns a token range and stores the primary copy for rows in that range. Replication copies each partition to additional nodes clockwise on the ring. In production, NetworkTopologyStrategy places replicas across distinct racks and datacenters rather than SimpleStrategy, which is only suitable for single-datacenter dev clusters. With replication factor 3, three copies exist so QUORUM operations still succeed after one rack or node failure.

Pick Cassandra when write throughput, geographic distribution, or zero-downtime requirements exceed what a single MySQL 9.7 or PostgreSQL 18 primary with read replicas can handle. It excels at time-series ingestion, IoT telemetry, activity feeds, high-volume messaging, and audit logs with TTL expiry. Stay on relational databases for checkout, inventory, and ledger systems needing full ACID transactions. MongoDB fits better when documents vary wildly and joins are rare. In my experience on production Laravel applications, most business CRUD stays on MySQL while hot write paths move to Cassandra only when volume truly demands it.

CQL is Cassandra Query Language. It resembles SQL syntactically but every query must include the full partition key or Cassandra scans the cluster.

Consistency is tunable per operation. ONE means one replica responds—fine for metrics and best-effort logs with lowest latency. QUORUM requires a majority of replication factor replicas and is the default for many production apps; with RF=3, that means two replicas must agree. LOCAL_QUORUM limits quorum to the local datacenter for multi-DC deployments needing local reads. ALL requires every replica and is fragile during failures. Writes at QUORUM plus reads at QUORUM give strong consistency for that query path; ONE on both sides yields eventual consistency with lower latency.

Never run a single production node. Use at least three nodes with replication factor 3 so QUORUM reads and writes survive one failure.

A hot partition occurs when many rows share one partition key, forcing a single node to handle all traffic. This kills performance regardless of cluster size. Spread load by appending a time bucket, user ID, or shard suffix to partition keys so writes distribute across nodes. The same principle applies when planning sharding on relational engines. Keep individual partitions under roughly 100 MB as a practical tuning guideline. Wide partitions with thousands of columns also slow reads because Cassandra checks memtables plus all relevant SSTables even with Bloom filters skipping irrelevant files.

When a write arrives, the replica appends to a commit log on disk first to protect against process crashes. The row then lands in an in-memory memtable sorted by key. When the memtable fills, Cassandra flushes it to an immutable SSTable file on disk. SSTables are append-only; updates and deletes write new tombstone markers rather than overwriting old bytes. Compaction merges SSTables later and removes expired tombstones. Heavy delete workloads without proper compaction settings bloat disk usage—a common production surprise teams discover only after disk alarms fire.

Cassandra requires query-driven table design, not normalize-first modeling. Every query must include the full partition key; otherwise Cassandra scans the cluster. Secondary indexes exist but perform poorly at scale—prefer materialized views or duplicate tables keyed for each access pattern. ALLOW FILTERING is a debug escape hatch, not a production feature. Batch statements only help when all rows share one partition key. Lightweight transactions use Paxos and are slow on hot paths. A table supporting latest events for one user on one date cannot efficiently answer all events across every user without a second table keyed differently.

Install from the Apache repository on Ubuntu 24.04 using apt after adding the official Cassandra deb source and GPG key. In cassandra.yaml, set cluster_name, num_tokens to 256, endpoint_snitch to GossipingPropertyFileSnitch, and seed_provider with two or three stable seed node IPs—seeds help discovery but are not masters. Set rack and datacenter names in cassandra-rackdc.properties when using NetworkTopologyStrategy. Production nodes want fast SSDs, 32 GB RAM or more, a dedicated commit-log disk when possible, and JVM heap between 8 GB and 16 GB—never exceeding half of system RAM because off-heap memtable and cache need space.

No. Checkout, inventory, and ledger systems needing ACID transactions across rows are poor fits for Cassandra, which offers only limited lightweight transactions and no foreign keys or cascading deletes. A florist eCommerce site on WooCommerce 11.1 rarely needs Cassandra. Relational databases handle predictable schemas, ad-hoc reporting, and transactional order flows far better. On large marketplace projects, a practical pattern is keeping checkout on MySQL while separating high-volume clickstream or listing ingestion into a dedicated Cassandra store—but the transactional core stays relational.

PHP and Laravel apps typically connect through the DataStax PHP driver or a gRPC sidecar microservice. Most teams keep Laravel 13 on MySQL for transactional data and push high-volume events to Cassandra through a queue worker—a hybrid that respects database-per-service patterns without rewriting the entire monolith. For API-facing ingestion, pair Cassandra with rate limits, idempotency keys, and dead-letter queues so poison writes do not saturate a partition. Use JSON formatters to inspect event payloads during development and validate schemas before they land in production tables.

Enable TLS between nodes and clients so data is encrypted in transit—the same mindset as database encryption at rest and in transit on relational systems. Restrict JMX ports with firewall rules because exposed management interfaces are an attack surface. Apply role-based access granting minimum privileges per application user rather than sharing a superuser account. Security matters even on internal clusters because a compromised application credential with broad CQL access can exfiltrate or corrupt replicated data across every node simultaneously.

Run nodetool status after every deploy to confirm all nodes show UN (Up/Normal). Schedule nodetool repair weekly to fix replica drift missed by hinted handoff. Monitor pending compactions, heap pressure, and read latency p99—disk latency spikes appear as p99 read timeouts before CPU maxes out. Set TTL on time-series tables so old SSTables expire cleanly. Test restores from snapshots regularly; replicas are not backups. Plan upgrades one node at a time with nodetool drain before restarts. For teams without dedicated DBA or SRE capacity, managed Cassandra or staying on PostgreSQL 18 with read replicas is often cheaper than hiring a Cassandra specialist full-time.

Designing tables around normalization instead of query patterns is the biggest error—if your query shape does not match the primary key, redesign the table rather than forcing ALLOW FILTERING. Relying on secondary indexes at scale, using lightweight transactions on hot paths, and batching rows across different partition keys all cause performance collapse. Creating wide partitions with thousands of columns slows reads. Omitting TTL on time-series data leads to unbounded disk growth. Many failures mirror relational schema mistakes—wrong key choice and missing access paths—except in Cassandra there is no query optimizer to paper over bad design. Read the official CQL developing guide before committing to hardware.

Share this article

0 Comments

Leave a comment

Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

Quick Contact Options
Choose how you want to connect me: