AI Hints
Home›System Design Tutorial›Database Families
System Design · Lesson 38 of 120

Kinds of NoSQL

Key-value, document, wide-column, graph.

⏱ 2 min read▶ Video at 44:20🎓 Free
Watch this lesson in the System Design courseWatch on YouTube ↗Full System Design course

No SQL isn't one thing. It's a family of four quite different database types. Each is built for a particular shape of data.

Kinds of NoSQL
From the video: Kinds of NoSQL
  • Not one thing
  • Four types
  • Each for a shape of data

Four types

A key value store is a giant dictionary. Give it a key, get a value, extremely fast. A document store keeps J SON like documents, with flexible fields. A wide column store spreads huge tables across many machines, great for heavy writes. And a graph database stores things and the links between them, like friends of friends.

TypeExampleGreat for
Key-valueRedis, DynamoDBsessions, caches
DocumentMongoDBflexible records
Wide-columnCassandrahuge write volume
GraphNeo4jrelationships

A key-value store

A key value store is as simple as a Python dictionary. Put a value under a key. Get it back by its key. Run it. Lookups by key are instant. But notice what's missing. There's no way to ask, which sessions belong to Sam, without scanning everything. You must design your keys around the questions you'll ask.

kvstore.pypython
store = {}

store["session:abc123"] = {"user": "sam", "cart": 2}
store["session:def456"] = {"user": "priya", "cart": 0}

print(store["session:abc123"])

# "Which sessions are Sam's?" means checking every key:
print([k for k, v in store.items() if v["user"] == "sam"])
Output
{'user': 'sam', 'cart': 2}
['session:abc123']

Summary

Key value stores are fast dictionaries, document stores hold flexible records, wide column stores handle huge writes, and graph databases handle relationships. Next, how databases find rows quickly. Indexes.

Key takeaways
  • Key-value
  • Document
  • Wide-column, graph
Next up: Indexes — finding rows fast