contentintech

Databases at Scale Cheatsheet

Quick reference for replication, sharding, isolation levels, quorums, 2PC vs Saga, and NewSQL.

ShardingReplicationCAPNewSQL
NotesCheatsheet

ACID vs BASE

ACIDBASE
Atomicity, ConsistencyBasically Available
Isolation, DurabilitySoft state, Eventual consistency

NoSQL families

TypeExamples
Key-valueRedis, DynamoDB
DocumentMongoDB, Couchbase
Wide-columnCassandra, ScyllaDB
GraphNeo4j, Neptune

Indexes

IndexBest at
B-treeRange + equality; read-optimized
HashExact match O(1), no ranges
LSM-treeWrite-heavy; compaction cost
InvertedFull-text search

Replication

TopologyTrade-off
Single-leaderSimple; leader bottleneck/SPOF
Multi-leaderRegional writes; conflicts
LeaderlessHA; read-repair needed
Sync  = no loss, higher latency
Async = fast, lag + possible loss
Quorum: W + R > N  => read sees latest write

Sharding

StrategyDownside
RangeHot spots on sequential keys
HashNo range queries
DirectoryLookup is SPOF
Avoid hash % N  (add node -> reshuffle all)
Consistent hashing / fixed partitions -> move ~1/N keys
Virtual nodes -> even load

Isolation Levels

LevelDirtyNon-repPhantom
Read UncommittedYYY
Read CommittedNYY
Repeatable ReadNNY*
SerializableNNN

*InnoDB blocks phantoms with next-key locks.

2PC vs Saga & NewSQL

2PCSaga
AtomicityStrongCompensations
BlockingYesNo

CAP lean

CPSpanner, HBase, etcd, Mongo (majority)
APCassandra, DynamoDB, Riak

NewSQL: Spanner (TrueTime), CockroachDB/Yugabyte (Raft KV + SQL), Vitess (sharded MySQL). OLTP row-store vs OLAP column-store. Sync caches/indexes via CDC (Debezium → Kafka). Pool connections (PgBouncer).

Section navigation