Chapter 26: Column-Family and Graph Databases
Column-Family: Cassandra
Designed for massive write throughput across many nodes. Used by Netflix, Apple, Discord.
-- Cassandra CQL (looks like SQL but isn't)
CREATE TABLE sensor_data (
sensor_id UUID,
timestamp TIMESTAMP,
value DOUBLE,
PRIMARY KEY (sensor_id, timestamp)
) WITH CLUSTERING ORDER BY (timestamp DESC);
-- Writes are FAST (append-only, no read-before-write)
INSERT INTO sensor_data (sensor_id, timestamp, value)
VALUES (uuid(), toTimestamp(now()), 23.5);
Key Properties
- Masterless (no single point of failure)
- Linear horizontal scaling
- Tunable consistency (ONE, QUORUM, ALL)
- Designed for time-series and write-heavy workloads
- NO joins, NO subqueries, limited WHERE clauses
Graph Databases: Neo4j
Optimized for traversing relationships. Queries like "friends of friends" that would require recursive JOINs in SQL are trivial.
// Cypher query language (Neo4j)
// Create nodes and relationships
CREATE (alice:Person {name: 'Alice'})-[:WORKS_AT]->(ericsson:Company {name: 'Ericsson'})
CREATE (bob:Person {name: 'Bob'})-[:WORKS_AT]->(ericsson)
CREATE (alice)-[:FRIENDS_WITH]->(bob)
// Find friends of friends
MATCH (me:Person {name: 'Alice'})-[:FRIENDS_WITH*2]->(fof)
RETURN fof.name
// Shortest path between two people
MATCH path = shortestPath(
(a:Person {name:'Alice'})-[*]-(b:Person {name:'Dave'})
)
RETURN path
Graph DB Use Cases
- Social networks (friends, followers, recommendations)
- Fraud detection (find suspicious transaction patterns)
- Network topology (telecom network maps)
- Knowledge graphs
- Dependency analysis
Key Takeaways
- Cassandra: write-heavy, distributed, time-series. No JOINs.
- Neo4j: relationship-heavy data, graph traversals. Not for tabular data.
- Each NoSQL type solves a specific problem — don't use them as general-purpose
- In telecom: Cassandra for CDRs/telemetry, Graph for network topology