Replication configuration, monitoring, upgrade path, and failure modes. Before introducing a new Database technology, ensure your team has the expertise to operate it in production. The cost of Operating 5 different databases often exceeds the cost of operating one database that handles 80% of Your use cases adequately.
The CAP theorem is like a three-legged stool: consistency, availability, and partition tolerance. You can have at most two legs at any time. Since network partitions are a fact of life in distributed systems, the real choice is between consistency and availability. This is not a failure of design but a physical reality of building systems across multiple machines.
NoSQL databases are like different types of transportation. A document store is a cargo van: it carries large, self-contained packages of data. A key-value store is a filing cabinet: you put something in, you take it out by its label. A column-family store is a warehouse with narrow aisles optimized for reading many rows of the same item. A graph database is a road map optimized for navigating relationships. The right vehicle depends on what you are hauling and where you need to go.
Choosing MongoDB or Cassandra because “SQL is hard” leads to data integrity problems that are far Harder to debug than SQL queries. If your data has relationships, normalisation requirements, and Transactional needs, a relational database is the right tool regardless of how you feel about SQL.
Many NoSQL databases default to eventual consistency. If your application assumes strong consistency (e.g., reading a value immediately after writing it), you will see stale data. Always configure Consistency levels explicitly based on your application’s requirements.
Designing a Cassandra table with many small partitions, or a MongoDB collection with frequent Inter-document references that require application-level joins, defeats the purpose of using NoSQL. Model around your access patterns, not your entity relationships.
Running a Redis cluster, a Cassandra ring, or a MongoDB replica set in production requires expertise In the specific database’s failure modes, backup procedures, monitoring, and upgrade paths. Budget For this expertise before adopting a new technology.
In Redis and Memcached, data without a TTL accumulates until memory is full, at which point eviction Policies kick in and may evict data you wanted to keep. Always set TTL on cached data:
SET session:abc123 " user_data " EX 3600 # expire in 1 hour
HSET cache:product:P1 name " Widget " price 29.99
EXPIRE cache:product:P1 86400 # expire in 24 hours
Cassandra’s strengths (linear scalability, multi-DC replication, high write throughput) only Materialise at scale. For datasets that fit on a single PostgreSQL instance, the operational Overhead of Cassandra is not justified. The same applies to most other NoSQL databases: they solve Problems that relational databases cannot solve at scale, but they introduce complexity that is not Warranted for small-scale systems.
Distributed databases that require strong consistency use consensus algorithms to agree on the Current state across replicas.
Raft (Ongaro and Ousterhout, 2014):
Used by: etcd, CockroachDB, TiKV, Consul Roles: Leader, Follower, Candidate Leader election: heartbeat timeout triggers election Log replication: leader appends entries, followers replicate Safety: committed entries are never lost Follower --> Candidate : election timeout
Candidate --> Leader : receive majority votes
Leader --> Follower : discover higher term
Candidate --> Candidate : election timeout (split vote)
Follower --> Follower : receive heartbeat from leader
Candidate --> Follower : receive heartbeat from higher term
Paxos (Lamport, 1989):
Used by: Google Chubby, Spanner (as part of Multi-Paxos) More complex than Raft but equally correct Forms the theoretical foundation for most modern consensus protocols CRDTs are data structures designed to be replicated across multiple nodes with automatic conflict Resolution. They guarantee eventual consistency without requiring coordination.
CRDT Type Example Operations Conflict Resolution G-Counter Increment Take maximum PN-Counter Increment, Decrement Separate positive/negative counters G-Set Add Union (set merge) OR-Set Add, Remove Observed-remove (tombstone-based) LWW-Register Assign value with timestamp Last-writer-wins
CRDTs are used in Riak, Redis CRDT module, and some edge computing frameworks. The trade-off: they Only support a limited set of operations (no arbitrary transactions), and some types accumulate Garbage (tombstones in OR-Set).
Most NoSQL databases that are write-optimised (Cassandra, RocksDB, LevelDB, HBase) use LSM trees Instead of B-trees. LSM trees batch writes in memory and flush to disk in sorted runs, which Dramatically reduces write amplification.
Write path:
1. Write appended to in-memory MemTable (sorted data structure, in standard practice a skip list or red-black tree)
2. When MemTable is full, it becomes an immutable SSTable (Sorted String Table) on disk
3. Background compaction merges SSTables to maintain read performance
SSTable Level 0 (disk) ← newest, unsorted relative to each other
SSTable Level 1 (disk) ← sorted, non-overlapping
SSTable Level N (disk) ← oldest, largest
Read path:
2. Check Bloom filter for each SSTable level
3. If Bloom filter indicates possible match, search SSTable
4. Return the most recent value found
LSM Tree vs B-Tree:
Aspect LSM Tree B-Tree Write throughput Very high (sequential writes only) Moderate (random writes for updates) Read throughput Moderate (may check multiple levels) High (single tree traversal) Write amplification Low (sequential) High (in-place update, page rewrite) Read amplification High (multiple levels) Low (single traversal) Space amplification Moderate (compaction overhead) Low to moderate (page fragmentation) Compaction Required (background merge) Not required (in-place updates)