Types of Databases
On the way to the inventory, QUERY slows down beside a dark section of the vault. Behind the glass is a registry of old Earth archives that didn't survive the Great Severance: the cache nodes went dark first, the document stores arrived in torn fragments, and entire sectors of the analytical clusters have fallen silent. The relational of Kotomarket, however, survived intact — with all its relationships preserved.

Beyond relational databases
Relational databases work especially well for Kotomarket: customers, orders, and products fit naturally into tables connected by relationships. That's the type of database this course focuses on. Other approaches were also common in the industry in 2024 and remain common today:
- key-value (Redis) — a very fast “key → value” format for retrieving a simple record almost instantly;
- document (MongoDB) — stores flexible documents whose structure can vary from one record to another;
- columnar (ClickHouse) — well suited to analytics when you need to calculate metrics quickly across huge amounts of data.
Most popular DBMSs used for product development are still relational: PostgreSQL, MySQL, Oracle, MS SQL. Once you learn SQL here, you'll be able to work with data at many different companies.
QUERY: Every archive has its own job. Some prioritize speed, while others are built for flexible data or analytics. We got lucky — ours is the kind where everything is connected.
The database family registry: a closer look
The registry behind the glass is a good place to examine database families in detail. “What types of databases are there, and when would you choose each one?” is one of the most common interview questions. We'll cover five families using the same structure each time: how data is stored, strengths and weaknesses, products, and when to use them.
Relational databases: strict schemas and relationships
How data is stored: rows in tables with a predefined schema — every column has a type, tables are linked through keys, and the database itself enforces data integrity, so you can't record an order for a customer who doesn't exist. Changes run inside with guarantees: “create the order + reduce the stock” either both happen or neither happens.
- Strengths: expressive SQL (filters, table joins, ), database-level integrity, .
- Weaknesses: the schema has to be designed in advance and migrated when it changes; horizontal scaling across many servers is harder than with families.
- Products: PostgreSQL, MySQL/MariaDB, Microsoft SQL Server, Oracle, SQLite.
- When to use it: users, orders, money, inventory — anywhere data is related and incorrect writes are unacceptable. For a new product, this is the default choice.
Key-value databases: a dictionary at maximum speed
How data is stored: one giant “key → value” dictionary, usually kept in memory. There are no tables or relationships: store something under a key, then retrieve it by that key in a fraction of a millisecond.
-- This isn't SQL; these are Redis commands
SET session:8f3a '{"user_id": 42}'
GET session:8f3a
- Strengths: speed, simplicity, easy scaling.
- Weaknesses: queries work only by exact key — you can't ask this format to “find all sessions belonging to customers from Miami”; the database treats the contents of each value as opaque.
- Products: Redis, Memcached, Amazon DynamoDB.
- When to use it: caches, sessions, counters, queues, leaderboards — hot data stored alongside the main database rather than replacing it.
Document databases: flexible JSON
How data is stored: records are documents grouped into collections. You don't declare the schema in advance: a smartwatch can have a “battery life” field, while a hoodie has a “size chart” field, and both documents can live in the same collection. Nested structures are stored directly inside each document without separate tables.
- Strengths: flexible structure, the whole document can be read in one request, useful for catalogs with very different attributes and for rapid prototypes.
- Weaknesses: relationships between documents are handled by the application, and full-featured operations are rare; without discipline, a collection can become a mix of incompatible formats.
- Products: MongoDB, Couchbase, Firestore.
- When to use it: content, catalogs with widely varying fields, profiles, and settings.
The boundaries between database families are blurry: PostgreSQL can store documents in a jsonb column and build indexes on them. That is often enough for a document-style use case without adding a second database:
-- Example outside our snapshot: attrs is a jsonb column
SELECT name, attrs->>'color' AS color
FROM catalog
WHERE attrs @> '{"brand": "Kotomarket"}';
Columnar databases: analytics across billions of rows
How data is stored: values are stored by column rather than by row: all prices together, all dates together. A query for “average order value by month” reads only two columns from disk instead of the entire table. Similar values also compress very well, which makes queries fast.
-- A classic columnar-database query (ClickHouse dialect: toYYYYMM is one of its functions)
SELECT toYYYYMM(created_at) AS month, avg(total_amount) AS avg_check
FROM orders
GROUP BY month;
- Strengths: fast and scans across billions of rows, with strong compression.
- Weaknesses: updating or deleting individual records is expensive; reading one complete row is slower than in a row-oriented database; these systems aren't designed for transactional workloads.
- Products: ClickHouse, BigQuery, Snowflake, Amazon Redshift.
- When to use it: analytics, reports, events, logs, metrics — usually alongside the relational database.
Two terms often come up in interviews: (online processing — lots of short reads and writes, the PostgreSQL world) and (online analytical processing — heavy analytical reads across the full history, the ClickHouse world). The product writes to an OLTP database; analytics reads from an OLAP copy.
The final family: graph databases
When relationships matter more than the records themselves — “friends of friends,” delivery routes, recommendation chains — graph databases such as Neo4j and Memgraph are a natural fit. Their data consists of nodes (records) and edges (relationships between records), and following relationships to any depth is a native operation. In a relational database, the same traversal becomes a chain of table joins that grows more expensive as the depth increases.
Mini-guide: choosing a database for a project
- Start with the questions, not the data. What kinds of queries will the product make: exact lookups “by key,” relational queries like “who bought what,” or analytical ones like “how much this month”?
- Default to relational. Related data where mistakes are costly — orders, payments, inventory — points to PostgreSQL. It's the safest starting point for almost any product.
- Add specialized databases for a specific job, not “just in case.” If hot reads become a bottleneck, add Redis as a cache. If analytics grows, replicate events into ClickHouse. If fields vary wildly, start with
jsonbin PostgreSQL and move to a document database only if it stops being enough. - Account for the cost of a second database. Every new database brings data synchronization, backups, monitoring, and another technology the team has to maintain.
Pitfall: choosing a database “because it's trendy.” “Let's use MongoDB — no schema means we'll move faster” often ends with the team designing a schema anyway, except its rules now live in application code instead of being enforced by the database. The opposite mistake also happens: adding ClickHouse for data volumes that PostgreSQL can in milliseconds. Choose the database based on the queries you'll run and the cost of mistakes, not hype.
ClickHouse is a columnar database for analytics, popular for fast calculations across large tables of events and orders. It has its own SQL , and the platform has a separate ClickHouse practice environment. Our is relational: next, QUERY opens the inventory and shows what it contains — tables, rows, and key-like threads connecting them.
Interview question
Interview question: what types of databases do you know, and how would you choose storage for a new service?
Strong answer: relational (PostgreSQL, MySQL) — strict schemas, relationships, ; key-value (Redis) — caches, sessions, counters; document (MongoDB) — flexible documents; columnar (ClickHouse, BigQuery) — analytics over large ; graph (Neo4j) — deep relationships. I choose based on the queries the service needs: I use a relational database as the source of truth and add specialized databases for specific jobs such as caching or analytics instead of replacing it.
Follow-up question: what's the difference between and ?
Strong answer: OLTP means lots of short read and write transactions, such as placing orders, typically in row-oriented databases like PostgreSQL; OLAP means heavy analytical reads and across historical data, typically in columnar databases like ClickHouse. They often work as a pair: the product writes to OLTP, while analytics reads from an OLAP .