Vibe Engines
YouTube
SYSTEMS & BACKEND

Databases & Storage

Storing data at scale — transactions, isolation, indexing, ledgers and sync — from the concurrency handbook to systems like Dropbox, a payment ledger and a key-value store.

32 pieces · 6 formats Follow this topic (RSS)

A database is a set of promises about your data: what you write stays written, concurrent users do not corrupt each other’s changes, and queries come back fast enough to use. Databases and storage is the study of how those promises are kept, what each one costs, and which ones you can relax when the data outgrows a single machine.

Core ideas and trade-offs

  • Transactions and isolation define “correct.” An ACID transaction applies a group of writes all together or not at all. Isolation levels decide which anomalies concurrent transactions can observe, from dirty reads to lost updates and write skew; stronger levels prevent more of them and cost more throughput.
  • Indexes decide speed. A B-tree index turns a full table scan into a few page reads, but every index slows writes and takes space, and the query planner uses one only when it estimates that doing so is cheaper.
  • Storage engines suit different workloads. B-trees update data in place and favor reads; LSM-trees append writes and compact them in the background, which favors heavy write loads at some cost to reads.
  • Rows or columns. Row-oriented OLTP databases fetch and update individual records cheaply; column-oriented OLAP stores scan and aggregate one column across millions of rows cheaply. Running heavy analytics on the production database tends to slow both jobs.
  • Scaling out changes the guarantees. Replication adds read capacity and survives failures but introduces lag; partitioning spreads data across machines but makes cross-partition queries and transactions harder.

How the formats fit together

The handbooks build the mental model: SQL and what happens beneath a query, PostgreSQL internals, concurrency and isolation, partitioning and replication, and focused comparisons such as SQL versus NoSQL and OLTP versus OLAP. The labs make two invisible things visible, the query planner’s choice and the B-tree versus LSM-tree trade, and an algorithm game builds an LSM-tree step by step. The system designs show where storage decisions are the hardest part of a product: payments, wallets, ticketing, file sync, object storage, time-series data and search. The tools estimate index size and storage growth before you commit.

Common mistakes

  • Assuming the default isolation level prevents every race. PostgreSQL defaults to Read Committed, where a read-then-write in application code can lose an update unless you use an atomic update, a row lock or a stricter level.
  • Indexing every column, then wondering why writes slowed down.
  • Choosing a NoSQL store for scale the product does not have yet and giving up joins and transactions it does need.
  • Storing money as a mutable balance instead of an append-only ledger with idempotent writes.

Start here, in this order

  1. The SQL Handbook — Start beneath your SELECT: keys, joins, indexes, the planner, transactions and isolation levels.
  2. The Query Planner — Watch a cost-based planner flip between a sequential scan and an index scan as you change how selective a filter is.
  3. Concurrency, Locks & Isolation Levels — Learn which anomalies each isolation level allows, how MVCC works and when to lock optimistically or pessimistically.
  4. B-Tree vs LSM-Tree — Stream the same writes into both storage engines and see which one wins for writes and which for reads.
  5. Partitioning, Sharding & Replication — See how one dataset becomes many through hash and range partitioning, and what replication lag and quorums mean for reads.
  6. Design a Payment System — Put it all under real stakes with idempotency keys, a double-entry ledger and reconciliation.

Questions

Should I use SQL or NoSQL?

Start with a relational database unless you have a specific reason not to. SQL databases give you schemas, joins, transactions and decades of tooling, and systems such as PostgreSQL scale further on one machine than most products ever need. Choose a NoSQL store when its data model matches your access pattern exactly: a key-value store for simple lookups at very high volume, a document store for self-contained records, or a wide-column store for huge write-heavy datasets. The deciding question is what your queries look like, not which store is fashionable.

What does a database index actually do?

An index is a separate, sorted structure, usually a B-tree, that maps column values to the rows that contain them. Instead of scanning every row to find matches, the database walks the tree in a few page reads and jumps straight to the right rows. The cost is that every insert, update and delete must also update each index, and indexes take disk space and memory. The query planner uses an index only when it estimates that doing so is cheaper than a scan, which is why an index on a value most rows share often goes unused.

What are isolation levels?

Isolation levels define how much concurrent transactions can see of each other’s changes. The SQL standard names four: Read Uncommitted, Read Committed, Repeatable Read and Serializable. Each step up prevents more anomalies, such as dirty reads, non-repeatable reads and phantoms, and Serializable makes concurrent transactions behave as if they had run one at a time. Real databases implement the levels differently, often with multiversion concurrency control, so check your database’s documentation for what each level actually guarantees and which errors your code must retry.

When do I need to shard a database?

Shard when one machine can no longer handle the data size or write load even after indexing, query tuning, caching, read replicas and a bigger server. Sharding splits data across machines by a key, which multiplies capacity but makes cross-shard queries, joins, transactions and rebalancing much harder. Choose the shard key from your most common access pattern so that most requests touch one shard, and watch for hot keys that concentrate traffic. Many teams postpone sharding for years by scaling up and moving analytics or archived data elsewhere.

Handbooks 8

Handbook

Concurrency, Locks & Isolation Levels

How overlapping operations stay correct — race conditions, optimistic vs pessimistic locking, the four isolation levels and their anomalies, MVCC, and distributed locks with fencing tokens. Part of System Design Fundamentals.

Engineering
Handbook

Partitioning, Sharding & Replication

How one dataset becomes many — range vs hash partitioning, consistent hashing and virtual nodes, hot partitions, replication topologies, replication lag, and quorums. Part of System Design Fundamentals.

Engineering
Handbook

The SQL Handbook

What the database does underneath your SELECT — the relational model and keys, joins (inner/left/right/full), indexes and B-trees, the query planner and reading EXPLAIN, transactions and ACID, isolation levels and the anomalies they prevent, normalization vs denormalization, and the pitfalls (N+1, missing indexes, SELECT *).

Engineering
Handbook

The PostgreSQL Internals Handbook

UPDATE never updates, and a janitor keeps it working. Heap pages and tuples, MVCC's row versions (xmin/xmax visibility arithmetic), VACUUM, bloat and the wraparound scare, B-trees, HOT updates and index-only scans, the WAL's three superpowers (recovery, replication, PITR), reading the planner honestly, and why PgBouncer is infrastructure.

EngineeringDatabases
Handbook

SQL vs NoSQL

Framed as a war, it’s really a menu. Relational databases give you schema, joins and ACID; NoSQL is an umbrella of document/key-value/wide-column/graph stores that drop some of that for flexibility and horizontal scale. The relationships-vs-scale core difference, the CAP trade-off, and why to start relational.

EngineeringComparison
Handbook

PostgreSQL vs MySQL

Both are excellent free relational databases you can build a company on, so the choice is about character, not capability: Postgres prizes correctness, rich types and advanced features; MySQL prizes simplicity and read-heavy speed. The real differences, when each wins, and why Postgres became the modern default.

EngineeringComparison
Handbook

OLTP vs OLAP

One storage-layout decision explains the whole comparison: row-oriented OLTP makes fetching one record cheap, column-oriented OLAP makes aggregating one column across millions of rows cheap. Why you can’t run heavy analytics well on your production database.

EngineeringComparison
Handbook

SQL vs Vector Database

SQL vs vector databases, decided by the kind of question you ask: a relational database answers exact, structured queries over rows (WHERE price < 50); a vector database answers similarity queries over embeddings (find the items most like this). Exact filters vs approximate nearest neighbors, B-tree vs HNSW, pgvector, and why most real systems need both.

EngineeringAI

Roadmaps 1

System Designs 18

System Design

Design YouTube

Build a planet-scale video platform. See how raw uploads become an adaptive-bitrate ladder through an async transcoding pipeline, how a CDN serves immutable segments from the edge, how tiered blob storage holds exabytes affordably, and how view counts stay async.

StorageCDNScalability
System Design

Design Dropbox

Build a file sync engine. See how splitting metadata from bytes, content-addressed block storage with deduplication, delta sync, a push-then-pull notification service, and conflict-safe versioning fit together to keep files consistent across every device.

StorageSyncScalability
System Design

Design Ticketmaster

Build an event-booking system. Tackle the double-booking problem head-on: seat inventory, short-lived holds with TTLs, exactly-once purchases via ACID transactions, payment sagas with idempotency, and a virtual waiting room that tames the on-sale stampede.

ConcurrencyConsistencyTransactions
System Design

Design a Key-Value Store

Build a distributed key-value store like DynamoDB. See how consistent hashing places keys, how replication and tunable quorums (R + W > N) trade consistency for availability, how vector clocks resolve conflicts, and how gossip membership, hinted handoff and read repair keep it alive through failure.

Distributed SystemsConsistencyReplication
System Design

Design a Web Crawler

Build a distributed web crawler. See how a URL frontier drives the fetch–parse–enqueue loop, how a bloom-filter seen-set stops infinite re-crawling, how politeness and robots.txt keep you a good citizen, how DNS caching and content dedup remove bottlenecks, and how to shard the frontier by host and dodge traps.

Distributed SystemsScalabilityStorage
System Design

Design Instagram

Build a photo-sharing app. See how splitting media from metadata, a CDN for immutable images, async image processing, a precomputed feed cache, asynchronous like/view counters, TTL-based ephemeral stories, and sharding fit together to serve billions of photos.

StorageCDNFan-out
System Design

Design Pastebin

Build a text-paste service. See how base62 key generation, separating metadata from blob storage, a cache and CDN for the read-heavy immutable path, TTL expiration, privacy flags and size limits, and async analytics fit together.

StorageCachingScalability
System Design

Design a Search Engine

Build a web search engine. See how an inverted index turns search into list lookups, how query parsing mirrors indexing, how an offline indexer builds postings, how BM25 and PageRank rank results, and how document-sharded scatter-gather, result caching and a fresh index scale it to billions of pages.

IndexingRankingScalability
System Design

Design Airbnb

Build a lodging marketplace. See how listings and geo search with filters, per-listing availability calendars, atomic booking that never double-books, payment hold-and-capture with idempotency, event-driven reviews and reindexing, and read replicas fit together.

SearchConcurrencyTransactions
System Design

Design a Payment System

Build a payment system like Stripe. See how a payment is modeled as a state machine of authorize and capture, how idempotency keys prevent double-charges, how a double-entry ledger keeps every cent auditable, how tokenization shrinks PCI scope, and how async webhooks, reconciliation and a durable retryable worker handle slow banks and failure.

ConsistencyLedgerReliability
System Design

Design Object Storage

Build an object store like Amazon S3. See why one disk caps capacity, durability and availability, how a flat bucket/key namespace scales to trillions of immutable objects, how a metadata service maps keys to chunk locations, how replication and erasure coding deliver eleven-nines durability, how read-after-write consistency is anchored in metadata, and how multipart uploads, tiering and background repair work.

StorageDurabilityScalability
System Design

Design a Distributed File System

Build a distributed file system like GFS or HDFS. See why one file server caps capacity and throughput, how huge files split into large chunks across chunkservers, how a single master serves only metadata while clients stream bytes directly, how rack-aware replication survives correlated failures, how a leased primary orders pipelined writes, and how the master is made recoverable.

StorageDistributed SystemsThroughput
System Design

Design a Time-Series Database

Build a time-series database like InfluxDB or Prometheus TSDB. See why a row-per-point SQL table melts, how series = metric + tags models the data, how columnar storage with delta-of-delta timestamps and XOR values shrinks points to ~1–2 bytes, how an LSM write path with a WAL swallows the firehose, how sharding by series and downsampling work, and why cardinality is the real scaling limit.

StorageIndexingScalability
System Design

Design a Log Search System

Build a log aggregation and search system like the ELK stack or Loki. See why grep-over-SSH can't scale, how structured logs and shipper agents get data off ephemeral hosts, how a Kafka buffer absorbs bursts, how a parse/enrich pipeline feeds an inverted index, how time-based sharding and scatter-gather search billions of lines in milliseconds, and how hot-warm-cold retention bounds cost.

ObservabilityIndexingScalability
System Design

Design a Digital Wallet

Build a digital wallet like PayPal or Venmo. See why a mutable balance column is dangerous, how an append-only double-entry ledger makes balance derived and money conserved, how atomic debit+credit transfers survive a mid-transfer crash, how idempotency keys stop double-charges, how per-account locking prevents double-spend, how cross-shard transfers use sagas, and how pending/settled states and reconciliation handle slow bank rails.

ConsistencyLedgerReliability
System Design

Design a Proximity Service

Build a proximity / nearby-search service like Yelp or "find drivers near me". See why SQL distance queries degrade to full scans, the 2D indexing problem, how geohash encodes 2D into a locality-preserving 1D key, how quadtrees and S2 cells adapt to density, the cell-boundary problem, caching hot cells, and how moving objects and geo-sharding are handled.

GeospatialIndexingScalability
System Design

Design a Logging Pipeline

Build the ingestion pipeline that collects, buffers and delivers logs from thousands of services — the write path, not the query/search side. See why synchronous writes to a central log server are dangerous, local agent buffering, bounded backpressure and overflow policy, batching for throughput, where structured parsing should happen, at-least-once delivery with dedup, sampling at high volume, and why a logging storm can take down the very system it was meant to observe.

Distributed SystemsStorageScalability
System Design

Design an Email System

Build an email system like Gmail or Outlook. See why raw inbound mail can't land straight in a mailbox, retry-with-backoff for unreliable delivery across the open internet, layered spam/authentication filtering, per-user mailbox sharding, thread reconstruction via message headers instead of subject lines, delivery dedup and bounce-loop prevention, and IMAP-style incremental multi-device sync.

Distributed SystemsStorageConsistency

Algorithm Games 1

Labs 2

Interactive Tools 2

About databases & storage

Storing data at scale is where correctness and performance collide. Transactions and isolation levels decide what "correct" means under concurrency; indexing decides whether a query is instant or hopeless; replication and sharding decide how you grow past one machine without losing data or your mind.

This topic spans the concurrency handbook and the systems that live or die on storage decisions — a payment ledger that must never double-charge, a key-value store, a sync engine like Dropbox. The through-line: the database is usually the hardest part of a system to change later, so its guarantees are worth understanding up front.

More in Systems & Backend

← Browse all topics