Gizmo is a stored key; Gadgets is inside the values
Wide-Column StoreCore idea
Looks like a table, but every row may have its own set of columns
Sparse Cells Under a Row KeyIn a Bigtable-style model, rows can hold different column qualifiers
user:1
Family: activity
Value
page:home
09:01
page:product
09:03
purchase:1
Laptop
user:2
Family: activity
Value
page:home
09:02
purchase:2
TV
Same column family, different populated cells
Caveat: A Busy Partition Key
Incoming readings
device
time
D1
09:00
D1
09:01
D1
09:02
D2
09:00
Partition A: key D1
time
device
09:00
D1
09:01
D1
09:02
D1
Partition B: key D2
time
device
09:00
D2
The D1 key keeps three readings together and concentrates their requests in one partition
Graph StoreCore idea
Nodes and edges are the data; following an edge replaces a join
Edges and Foreign KeysEdges instead of foreign keys
The same five entities: edges on the left, foreign keys and joins on the right
Property GraphsProperty graphs
A property graph: both nodes and edges carry attributes
Paths and Relational JoinsWhen a graph fits
Graph databases represent relationships as edges and offer traversal queries. Relational databases can use an edge table with a relationship-type column. The better fit depends on the traversal pattern and workload.
Friendship as a table: two-hop paths use two copies of the edge table
Paths of Unknown Depth
Stored edges
from
to
John
Mary
Mary
Sue
Sue
Dirk
Starting at John
Hops
Reached node
1
Mary
2
Sue
3
Dirk
Each extra hop reads another edge; the destination changes with the requested path depth
Caveat: A Path Can Revisit a Node
John → Mary → Sue → Dirk → Mary → Sue → …
One added edge creates a cycle; traversal needs an explicit stopping rule
Document StoreCore idea
A key-value store whose values have structure the store can read
Structure Inside a ValueValues with structure
In key-value stores, the value is often a very complex object
Key = 'GizmoWorks', Value = [all products of that company]
John and his two orders become one document that the application can read together
02 · JSON and Semi-Structured Data
01
Four Families of NoSQL
choose a model by its access pattern
02
JSON and Semi-Structured Data
read named fields and ordered arrays
03
Between Trees and Tables
convert nesting and repeated values
04
Why NoSQL
check flexibility, scale and guarantees
JSON Overview
JavaScript Object Notation = lightweight text-based open standard designed for human-readable data interchange. Interfaces in C, C++, Java, Python, Perl, etc.
These are difficult to represent in the relational model
Recap: The People Table
The four people of the last three slides, as rows of one SQLite table. The whole document sits in a text column; SQLite reads it with its JSON functions.
One row per person; the document is a column value
Demo: JSON Inside a SQL TableStoring JSON in RDBMS, made runnable (SQLite JSON functions)
Each person’s name: person ->> '$.name'. What comes back for row 4?
One row per phone number: FROM people p, json_each(p.person, '$.phone') j. Who disappears, who doubles?
People with no phone at all: json_type(person, '$.phone') IS NULL.
Ctrl/⌘ + Enter
Query result
Write a query on the left, then Run.
Answer: JSON Inside a SQL Table
SELECT p.id, p.person ->> '$.name'AS name, j.value AS phone
FROM people p, json_each(p.person, '$.phone') j;
id
name
phone
1
John
1234
2
Mary
1234
2
Mary
5678
4
{"first":"John","last":"Smith"}
2345
json_each turns the phone array into rows: Mary twice, Joe not at all. The relational answer to a repeated attribute is a second table, built here on the fly.
A repeated attribute becomes one row per value: the join is back
Discussion: Why Semi-Structured Data?
Semi-structured data works well as data exchange formats
i.e., exchanging data between different apps
Examples: XML, JSON, Protobuf (protocol buffers)
Increasingly, systems use them as a data model for DBs:
SQL Server supports XML-valued relations
CouchBase, MongoDB, Snowflake: JSON
Dremel (BigQuery): Protobuf
Nesting and UnnestingNesting groups related values; unnesting makes repeated values separate rows
Nested document
{ name: "Mary",
phones: [1234, 5678] }
One row per phone
name
phone
Mary
1234
Mary
5678
The representation changes how a query reaches each phone
04 · Why NoSQL
01
Four Families of NoSQL
choose a model by its access pattern
02
JSON and Semi-Structured Data
read named fields and ordered arrays
03
Between Trees and Tables
convert nesting and repeated values
04
Why NoSQL
check flexibility, scale and guarantees
Why NoSQL? – Data Model
Choose a model for the records and access patterns
Declaring a Relational Schema
Shared rule
User
user_id: unique identifier
age: numeric value
Incoming record
{user_id: 2, age: "unknown"}
The age value fails the numeric rule; reject it or resolve its meaning
A schema makes the expected type explicit before readers try to use the value
Evolving Document ShapesDocuments: mixed shapes
Document databases can allow mixed record shapes. Adding a field need not rewrite every document, but readers, validation rules, and old records may still need migration.
Example: User and Orders in a Document Database (e.g., MongoDB) In a document-based NoSQL database, you store user and order data in a single document.