Chapter 9 - NoSQL & Big Data Processing
Chapter 9 — NoSQL & Big Data Processing
CSS451 Cloud Computing · Cheat Sheet
🧭 Big Picture First
Think of traditional RDBMS as a single, well-organized filing cabinet. It works great for a small office, but when the entire city needs to file documents simultaneously, it becomes a bottleneck. NoSQL is the answer to that bottleneck — a distributed warehouse of flexible storage rooms, each designed for a different kind of data.
1. History: How We Got Here
- Relational Databases (RDBMS) were the mainstay of business apps — because of ACID properties
- Web-based apps (especially e-Commerce) caused sudden traffic spikes
- Developers started fronting RDBMS with memcache or Ehcache to cope
- Eventually the bottleneck wasn't cache — it was the database itself
The Core Scaling Problem
RDBMS were not designed to be distributed. When datasets grew too big, two main approaches emerged:
| Approach | How | Problem |
|---|---|---|
| Scale Up | Buy a bigger single machine | Expensive, has hardware limits |
| Scale Out (horizontal) | Add more cheap machines | Requires distributed design |
2. Scaling RDBMS
Master/Slave Replication
- All writes → Master
- All reads → Slave (replicated copies)
Problems:
- Critical reads may be stale — writes haven't propagated yet
- Large datasets: master must duplicate data to all slaves
Like a newspaper: the editor (master) writes the stories, printing machines (slaves) copy them. But if the presses haven't caught up, readers get yesterday's news.
Sharding (Partitioning)
- Splits data into smaller, independent pieces across multiple servers
- Scales well for both reads and writes
- BUT: application must be partition-aware, no JOINs across shards, loss of referential integrity
Like splitting a dictionary into volumes A–M and N–Z — each is independent, but together they cover everything.
Four Sharding Techniques
| Technique | How It Works | Key Note |
|---|---|---|
| Vertical Partitioning | Tables for each feature on its own server | May need resharding if tables grow too large |
| Range-Based | Split by a value range (e.g., price 49, 99, $100+) | Simple but can cause hot spots |
| Key/Hash-Based | Hash function on key → determines which server | Uniform distribution |
| Directory-Based | Lookup service knows the partitioning scheme | Most flexible; can change scheme without app changes |
Other Scaling Techniques
| Technique | Details |
|---|---|
| Multi-Master Replication | INSERT only (no UPDATE/DELETE) to preserve consistency. No JOINs. De-normalized data. |
| In-Memory Databases | Eliminate disk access entirely → minimal response times |
3. What Is NoSQL?
- Stands for "Not Only SQL"
- A class of non-relational data storage systems
- Usually: no fixed table schema, no joins
- All NoSQL offerings relax one or more ACID properties (→ see CAP Theorem)
NoSQL is like a flexible notebook instead of a rigid spreadsheet — add any kind of info without pre-defining the format.
Why NoSQL?
- RDBMS can't be the "be-all/end-all" for all data storage needs
- Just as we have different programming languages for different jobs, we need different storage tools
- Triggered by:
- Explosion of social media (Facebook, Twitter)
- Rise of cloud (Amazon S3)
- Shift to dynamically-typed data with frequent schema changes
- Growth of the open-source community
The NoSQL Perfect Storm
This is NOT a rebellion against RDBMS. SQL is a rich query language that NoSQL cannot rival — they serve different purposes.
4. Seeds of NoSQL: Dynamo & BigTable
Three major papers seeded the NoSQL movement:
- BigTable — Google
- Dynamo — Amazon
- Gossip Protocol — for discovery and error detection
Amazon Dynamo
- Platform for Amazon's e-commerce: shopping cart, product catalog, best seller list, etc.
- A highly available, distributed key-value storage system
- Exposes only
put()andget()interfaces - Aims for "always on" at the cost of some consistency
- Introduced the CAP Theorem
Dynamo Design Principles
| Principle | Meaning |
|---|---|
| Incremental scalability | Scale out one node at a time |
| Minimal management overhead | Self-managing |
| Symmetry | No master/slave — decentralized |
| Decentralized control | Centralized control → outages |
| Heterogeneity | Exploit different node capabilities |
5. Three Popular NoSQL Designs
5.1 Key/Value Store
- Values looked up by a key (like a hashmap)
- Keys can map to more than one value
- Stored in native data types
"user:123" → { name: "Google", age: 21 }
Like a dictionary — you look up a word (key) and get its definition (value).
Examples: Amazon S3/Dynamo, Redis, Memcached, Voldemort, Scalaris
5.2 Document Database
- Stores data as JSON or XML documents
- Documents create hierarchies — the structure implies relationships
- No fixed schema — different documents can have different fields
Relational vs. Document
| Aspect | Relational DB | Document DB |
|---|---|---|
| Storage | Rows in a table | JSON/XML documents |
| Structure | Fixed columns | Flexible properties |
| Constraint | Every row has same columns | Each document can differ |
Doc 1: { "id": "1", "name": "John Smith" }
Doc 2: { "id": "2", "fullName": "Sarah Jones" }
Doc 3: { "id": "3", "fullName": { "first": "Adam", "last": "Stark" } }Notice Doc 2 uses fullName instead of name, and Doc 3 nests the name — impossible in relational tables.
Examples: MongoDB, CouchDB
5.3 Graph Database
- Stores data in nodes (vertices) and edges (relationships)
- Graph traversal = how you query
- Relationship info stored on the edges themselves
MATCH p=((tx:Transaction {txId:'123abc'})-[*..10]-(c:Car {plate: "LOVE NE04"})) RETURN p;Two Key Advantages of Graph DBs
- Rich relationship modeling — relationships are first-class citizens
- Query performance — traversal is far faster than JOIN-heavy SQL for connected data
Why Graph DBs Are Powerful for Investigations
- Easy for non-developers to query with Cypher + visualization tools
- Fast at analyzing connected data (e.g., ongoing fraud/terrorist investigations)
- Help users discover the "unknowns"
Like a social network map — instead of asking "who knows John?", draw lines between people and follow connections directly.
Examples: Neo4j, OrientDB
6. Neo4j Deep Dive
- A graph is a collection of nodes (things) and edges (relationships)
- Both nodes and relationships hold properties (key-value pairs)
- Think of it as a key-value store with full relationship support
Four Core Concepts
| Concept | Description |
|---|---|
| Nodes | Represent entities (people, places, transactions) |
| Relationships | Connect two nodes; always have a direction and type |
| Properties | Key-value pairs on nodes or relationships |
| Indexes | Maps from properties → nodes/relationships for fast lookup (without full traversal) |
Node: (Person {name: "Alice", age: 30})
Relationship: (Alice)-[:KNOWS]->(Bob)
Index: Find node where username = "master-of-graphs"
Neo4j Features
| Feature | Detail |
|---|---|
| Performance | ~1000x faster than relational DBs for graph queries |
| Scalability | Billions of nodes/relationships on a single machine; can shard |
| ACID | Fully transactional |
| Traversal | Traverses 1000 levels deep at millisecond speed |
| License | Dual — open source + commercial |
| Use cases | Social networks, tagging, wikis, fraud detection, knowledge graphs |
Property Rules
- Keys are strings; values are primitives or arrays of one primitive type
nullis NOT a valid property value — model nulls by the absence of the key
7. OrientDB
- A combined graph + document database
- Stores JSON documents in both nodes and edges
- Uses HTTP REST API → easy to distribute
- Runs on JVM → portable
- APIs in C/C++, Ruby, PHP, Java
8. Distributed Databases
| Strategy | What It Does | Pros | Cons |
|---|---|---|---|
| Replication | Copies the entire DB to all nodes | Fast reads, high reliability | High network + memory overhead |
| Sharding | Splits data across nodes (horizontal = by rows, vertical = by columns) | Fast read/write, low overhead | Potential data loss |
- Nearly all NoSQL systems natively support distributed design — this is a key appeal
9. CAP Theorem ⭐
Three Properties of a Distributed System
| Property | Meaning |
|---|---|
| Consistency (C) | Read always returns the most recent write |
| Availability (A) | System always responds (may not be latest data) |
| Partition Tolerance (P) | System continues working even if nodes can't communicate |
| Pick 2 | Sacrifice | Examples |
|---|---|---|
| C + A | Partition Tolerance | Traditional RDBMS (not distributed) |
| C + P | Availability | HBase, BigTable |
| A + P | Consistency | Cassandra, DynamoDB |
To scale out, you must have Partition Tolerance (P) → you must choose between C and A. In most cases: choose Availability over Consistency (but not always!)
Like a group project: you can't have work that's consistent (everyone has the same version), available(everyone can always access it), and partition-tolerant (works even if members are unreachable) — never all three perfectly.
Real-World CAP Decisions
| Scenario | Choice | Reason |
|---|---|---|
| Shopping cart | Availability | Always honor "add to cart" — revenue-producing; fix errors later |
| Order submission | Consistency | Multiple services (credit card, shipping, reporting) access data simultaneously |
10. ACID vs. BASE
| ACID | BASE | |
|---|---|---|
| Full form | Atomicity, Consistency, Isolation, Durability | Basically Available, Soft-state, Eventual Consistency |
| Model | Strong Consistency | Weak Consistency |
| Used by | RDBMS | Most NoSQL |
ACID Properties
| Property | Meaning |
|---|---|
| Atomic | Transaction is all-or-nothing — either fully happens or not at all |
| Consistent | DB constraints are preserved before and after transaction |
| Isolated | Transactions appear to execute sequentially, even if concurrent |
| Durable | Once committed, changes survive crashes |
Key ACID Concepts
- Commit = transaction completes → all changes saved permanently
- Abort/Rollback = transaction fails → all changes undone completely
- Static Integrity Constraints = rules all DB states must satisfy (e.g., )
- Transaction Consistency: a correct transaction both maintains DB constraints AND keeps the DB in sync with reality:
Techniques for Isolation
- Two-Phase Locking (Lock phase → Shrinking phase)
- Timestamp Ordering
Why Not Just Use Serial Execution?
Serial execution (one transaction at a time) is 100% correct but too slow. Concurrent/interleaved execution = better performance but requires careful isolation management.
BASE Properties
| Property | Meaning |
|---|---|
| Basically Available | System seems to work all the time |
| Soft State | Doesn't have to be consistent at all times |
| Eventually Consistent | Becomes consistent at some later point |
Like a Wikipedia edit — your change may take time to appear across all server regions. Eventually, everyone sees the same version.
Durability Implementation
| Approach | Mechanism |
|---|---|
| Non-stop DBMS | Mirrored disks |
| Recovery-based DBMS | Log files, data backup, checkpoints |
11. Consistency Model
Determines rules for visibility and apparent order of updates.
- Strong Consistency → you always read the latest write (ACID)
- Eventual Consistency → you might read a stale value, but it will eventually be correct (BASE)
- Consistency is a continuum — usually traded against Availability
12. NoSQL Trade-offs Summary
What You Gain
- Cheap and easy to implement (open source)
- Data replicated to multiple nodes → fault-tolerant
- Data can be partitioned
- No single point of failure
- No schema required
- Can scale up and down
- Relaxed consistency (CAP tradeoff)
What You Give Up
JOINoperationsGROUP BY/ORDER BY- ACID transactions
- SQL's expressive query language
- Easy integration with SQL-supporting apps
13. NoSQL Categories & Examples
| Category | Examples |
|---|---|
| Key/Value | Amazon Dynamo, Redis, Memcached, Voldemort, Scalaris |
| Document | MongoDB, CouchDB |
| Column-based | Cassandra, HBase |
| Graph | Neo4j, OrientDB |
14. BigTable (Google) — C+P System
CAP category: Consistency + Partition Tolerance
Data Model
- A table is a sparse, distributed, persistent, multidimensional sorted map
- Supports: lookups, inserts, deletes
- Only single-row transactions (no multi-row ACID)
Key Concepts
| Term | Description |
|---|---|
| Row Key | Lexicographically sorted — enables efficient range scans |
| Column Family | Group of related columns; family:qualifier format |
| Timestamp | Every cell can have multiple versions, indexed by time |
| Tablet | A dynamically partitioned row range — unit of distribution |
Think of it as an enormous multi-layered spreadsheet where rows are web pages and columns store attributes — with timestamps so you can see historical versions.
Internal Storage Format
BigTable Building Blocks
| Component | Role |
|---|---|
| GFS | Google File System — distributed storage |
| Chubby | Distributed coordination — master election, schema storage, ACLs |
| SSTable | Sorted Strings Table — actual data storage format |
15. Chubby
- A distributed coordination service
- Goal: allow apps to synchronize and manage dynamic config state
Chubby's Role in BigTable
- Ensures only one active master at a time
- Stores bootstrap location of BigTable data
- Used to discover tablet servers
- Stores BigTable schema and access control lists
Chubby is like a traffic controller — ensures only one car (master) controls an intersection, and everyone knows where to look for directions.
16. SSTable (Sorted Strings Table)
- A file of key/value string pairs, sorted by keys
- Persistent, ordered, immutable map from keys to values
- Stored in GFS; structured as 64KB blocks + index at the end
[ 64K block | 64K block | 64K block | ... | Index ]
- Index loaded into memory when SSTable is opened
- Lookup = 1 seek: find block in memory index → seek to that block on disk
SSTable Pros & Cons
| ✅ Advantages | ❌ Disadvantages |
|---|---|
| Fast key-based lookups | Immutable (write-once) |
| Duplicate keys allowed | Keys must be sorted before creating |
| Sharding + compression automatic | Only lookup by key |
| Easy to use with MapReduce |
When to Use SSTable
- As input/output of a MapReduce job
- As a random-access lookup table for an application server
17. Tablet
- A dynamically partitioned range of rows built from multiple SSTables
- The unit of distribution and load balancing
- Key rule: A tablet is served by only one tablet server at a time, but SSTables can be shared between multiple tablets
A tablet is like one drawer in a filing cabinet. The entire cabinet is the table; each drawer holds a sorted range of files.
18. BigTable Architecture
Three Components
- Client Library
- Single Master Server
- Tablet Servers
Master Responsibilities
- Assigns tablets to tablet servers
- Detects addition/expiration of tablet servers
- Balances tablet server load
- Handles garbage collection and schema changes
Tablet Server Responsibilities
- Manages 10–1,000 tablets per server (each 100–200 MB)
- Handles read and write requests
- Splits tablets that grow too large
- Maintains exclusive lock on a Chubby file per tablet
Who Initiates What?
| Action | Initiated By |
|---|---|
| Table creation/deletion | Master |
| Tablet merging | Master |
| Tablet splitting | Tablet Server |
Tablet Location Hierarchy
Chubby
└── Root Tablet (METADATA table)
└── METADATA Tablets
└── User Tablets
Clients cache tablet locations after discovery.
19. Tablet Server Internals: Reads & Writes ⭐
Write Path
Write Request
→ WAL (Write Ahead Log / commit log) — stores REDO records
→ Memtable (in-memory cache of recent writes)
→ SSTable files in GFS (older writes)
Read Path
Read Request
→ Merged view of: Memtable + SSTables
(Both are lexicographically sorted → merge is efficient)
WAL (Write Ahead Log)
- We do NOT flush data pages to disk on every commit
- Data written to log files first, then flushed to disk later
- On crash:
- Uncommitted changes → UNDO (roll-backward)
- Committed but not flushed → REDO (roll-forward)
REDO is preferred for data recovery — it replays committed transactions that weren't flushed to disk yet.
20. Compactions
Compaction = cleaning up your desk over time
| Type | What Happens | Purpose |
|---|---|---|
| Minor Compaction | Converts memtable → SSTable | Reduces memory usage + log traffic |
| Merging Compaction | Merges a few SSTables + memtable → new SSTable | Reduces number of SSTables |
| Major Compaction | All SSTables → one SSTable | Only live data remains; no deletion records |
21. BigTable Performance Observations
| Access Pattern | Performance | Why |
|---|---|---|
| Scans | 🟢 Best | Batch multiple reads into one RPC → high throughput |
| Random reads (memory) | 🟡 Fast | Served from memtable |
| Random reads (disk) | 🔴 Worst | Each request = 64KB SSTable block read from GFS |
| Random writes ≈ Sequential writes | 🟡 Similar | Both result in appends to WAL log |
22. HBase — Open-Source BigTable
HBase = BigTable clone, open-source, built on HDFS (Hadoop)
Why HBase?
- RDBMS is great for transaction processing but not for very large-scale analytic processing
- BigTable/HBase handles:
- Big queries — range scans, table scans
- Big databases — 100s of TB
- Sharding is NOT a good solution for scaling open-source RDBMS — application-specific and labor-intensive
HBase vs. RDBMS
| Feature | HBase |
|---|---|
| Indexes | No real indexes (row key only) |
| Partitioning | Automatic |
| Scaling | Linear, automatic with new nodes |
| Hardware | Commodity servers |
| Reliability | Fault tolerant |
| Processing | Batch processing support |
HBase Data Model
- Tables sorted by Row
- Schema defines only column families — columns exist only when inserted (NULLs are free / sparse)
- Everything except table names is
byte[]
Row key → [Column Family : [Column : [Timestamp → Value]]]
HBase Consistency (Why It's C+P)
- Strongly consistent — each row hosted by one region server at a time
- Uses row locks + MVCC (multiversion concurrency control) within a row
- During failover: new region server doesn't accept writes until previous is blocked out
- Replication at the HDFS layer — not acknowledged to client until flushed to 3 HDFS replicas
HBase Architecture
| Component | Role |
|---|---|
| Master | Monitors region servers, load balancing, redirects clients |
| RegionServer (Slaves) | Handles Write/Read/Scan, sends heartbeat to Master |
HBase Client Access
| Method | Details |
|---|---|
| Java client | get(byte[] row, byte[] column, long timestamp, int versions) |
| Thrift server | Ruby, C++, Java via Thrift |
| REST server | HTTP REST API |
| MapReduce | TableInput/OutputFormat |
| HBase Shell | JRuby IRB with get, scan, admin commands |
23. RDBMS vs. Column Family Model
| Relational DB | Column Family (HBase/BigTable) | |
|---|---|---|
| Schema | Rigid, pre-defined, fixed | Flexible |
| Structure | Tables with fixed columns | Column families with dynamic columns |
| Scale | Vertical (scale up) | Horizontal (scale out) |
| Joins | Yes | No |
| ACID | Full | Partial (row-level only) |