NoSQL Databases

5.Why BlueTicket Runs Two Databases

A

In this chapter

We'll learn what NoSQL databases are and why they exist — document databases (complete folders), key-value stores (a coat check, again) and others — and how to choose between relational and NoSQL, using the two databases BlueTicket actually runs.

12–14 min

The Problem in Real Life

John opens the infrastructure diagram. Next to PostgreSQL there's a second database Anna has never noticed: Redis.

"Remember the sessions from Act 12 — the guest list behind the wristband?" he asks. "They don't live in PostgreSQL. They live in Redis. It's a completely different kind of database, built for a completely different job."

A

Why would one company need two different kinds of database?

Anna

One Kind of Database for Everything vs. the Right Kind for Each Job

Not all data is a neat table

Some data is a whole document, some is just a key and a value, some is a web of connections.

Some jobs need extreme speed

Looking up a session happens on every single request; it has to be almost instant.

Trade-offs again

Every kind of database is great at some jobs and worse at others — just like data structures in Act 09.

NoSQL Databases

NoSQL (often read as "not only SQL") is the name for databases that don't store data in relational tables. They appeared when big websites needed to store huge amounts of data, with flexible shapes, across many servers. They're not "better" or "worse" than relational databases — they make different trade-offs. The main families:

  • Document database — a folder with a complete document inside: instead of splitting an event across tables, a document database stores each event as one self-contained document (usually JSON-like, Act 12) with everything about it inside: name, date, venue, artists, even a list of ticket types. Different documents can have different fields. Like keeping one complete folder per event, instead of spreading its pages across several filing cabinets. Example: MongoDB. Good for data that's read and written as a whole and whose shape varies.
  • Key-value store — the coat check (again): a key-value store is a giant, very fast hash table (Act 09): you store a value under a key and get it back by the key, instantly. Nothing more. Example: Redis, which keeps data in memory (RAM), so lookups take well under a millisecond. Perfect for sessions (session:8f2c → Zoë's session), caches, counters and rate limits.
  • Others you'll hear about: wide-column databases (like Cassandra) for enormous amounts of data spread across many servers; graph databases (like Neo4j) for data that's all about connections — the graphs from Act 09, like "fans who went to this show also went to..."; search engines (like Elasticsearch) for full-text search; and time-series databases for measurements over time, like the memory graph from Act 10.
Table — Main database families
FamilyEveryday pictureExampleGreat for
RelationalStrict filing cabinets with linked formsPostgreSQL, MySQLMoney, bookings, accounts
DocumentOne complete folder per thingMongoDBFlexible, self-contained records
Key-valueA coat checkRedisSessions, caches, counters
Wide-columnHuge ledgers spread over many buildingsCassandraMassive write-heavy data
GraphA map of who knows whomNeo4jConnections and recommendations
SearchA book's index for everythingElasticsearchFull-text search
Table — Relational vs. NoSQL
FeatureRelationalNoSQL (in general)
Data shapeFixed tables and columnsFlexible (documents, key-values, graphs)
RelationshipsBuilt in: foreign keys, joinsOften handled by the application
Transactions and constraintsStrong (ACID)Varies; often simpler or weaker
ScalingUsually one main server, scaled upOften designed to spread across many servers
Query languageSQLVaries by database
Table — BlueTicket's two databases
DataStored inWhy
Events, seats, fans, bookings, paymentsPostgreSQL (relational)Must be strictly correct; many relationships
Login sessionsRedis (key-value)Read on every request; must be instant
Short-lived cachesRedis (key-value)Fast; fine to lose and rebuild

In a document database, an event can be one self-contained document. In a key-value store, a session is just a key and a value.

The same event, two ways
// A document (MongoDB-style)
{
"_id": "evt_42",
"name": "Friday Stand-Up Night",
"date": "2026-11-13T20:00:00Z",
"venue": { "name": "Grand Hall", "address": "14 River Road" },
"ticketTypes": [
{ "name": "Standard", "priceCents": 4999 },
{ "name": "Student", "priceCents": 3999 }
]
}
// A key-value pair (Redis-style)
// key: session:8f2c
// value: { "fanId": 77, "loggedInAt": "2026-11-14T10:00:00Z" }

Lines starting with // are comments for you; real JSON doesn't allow comments.

Relational vs. NoSQL — how to choose: relational databases shine when data has a clear structure, many relationships, and must be strictly correct: money, bookings, stock, accounts. Their transactions and constraints (last chapter) are hard to beat. NoSQL databases shine when you need flexible shapes, extreme speed for simple lookups, or enormous scale across many machines — often accepting weaker guarantees in return.

Most real companies use both: each kind of database for what it's best at. That's called polyglot persistence. BlueTicket keeps bookings, payments, seats and fans in PostgreSQL, because they must be exactly right. It keeps sessions and short-lived caches in Redis, because they're simple key-value lookups that happen on every request and must be lightning fast — and losing a cached copy is fine, because it can be rebuilt.

Anna adds both to her notes, with one line underneath: "Bookings must be correct → relational. Sessions must be fast → key-value." BizTechLab's Non-Relational Databases course covers every NoSQL family in depth, with the same kind of story.

Key Takeaway

NoSQL databases store data without relational tables: document databases keep each item as a complete JSON-like document (MongoDB), key-value stores are giant, fast hash tables (Redis), and others handle wide-column, graph, search and time-series data. Relational databases win when structure and strict correctness matter; NoSQL wins for flexible shapes, speed and huge scale. Most companies use both.

Why This Matters

Choosing the right database for each job is one of the most important early decisions in any system, and it's hard to change later. Knowing the families — and that "use both" is normal — lets you understand any company's architecture diagram, including the Sale Day design BlueTicket builds in Act 14.

Anna knows what databases are, how they're shaped and which kind fits which job. One practical question remains: how does BlueTicket's code actually reach the database at all — and when is a plain file still the right choice?

Next