Buildfest Learn System DesignRead and experiment freely · Chapter activities stay in this tab
Practice librarySystem DesignDatabases and distributed data

LESSON 15 • ESSENTIAL

Databases and distributed dataOrganize the records.
Keep distributed data correct.

Databases and distributed data. Learn the concepts, explore a model and defend your design.

DEFINITION

Data design combines record organization, authoritative update rules and the placement of copies or shards. An efficient read is useful only if the system also preserves ownership and concurrency rules.

An index is a maintained shortcut
  1. STEP 1Lookup keystudent_id = 42
  2. STEP 2Index entriesLocate matching row references
  3. STEP 3Table rowsRead the requested records

An index reduces some read work but uses space and must be maintained during writes.

CONCEPT 1

Store records and change them safely

Data models and indexes

Relational tables connect structured records and can enforce constraints. Document, key-value and graph models suit other access patterns. Choose the actual product behavior rather than assuming NoSQL means more scalable. Large photo bytes can live in object storage with ownership metadata in a database. An index is a maintained shortcut for selected queries; it speeds some reads while adding write and space cost.

The final-seat problem

Two buyers can both read stock=1 before either changes it. An unprotected read-then-write can accept both. Use an atomic conditional update or an appropriate transaction/locking strategy, check which request won and record related changes consistently. Atomic means the chosen change cannot be split into conflicting intermediate decisions. The database must enforce the rule, not only the browser.

Copies are not the same as splits

Replication copies data and can produce stale reads when propagation lags. Sharding divides data ownership across instances. A popular key can overload one shard even if record counts are balanced. Consistency states what users may observe across updates. During a partition, an uncertain seat sale may need rejection while an approximate counter can tolerate temporary differences. A replica is not a recoverable historical backup.

Replication copies; sharding divides
  1. CONCEPTReplicationA B C -> A B C
  2. CONCEPTShardingA B on one; C D on another
  3. CONCEPTCombined designEach shard can have replicas

These solve different problems and can be used together.

Key learning points

  • Match indexes to real query patterns.
  • Use atomic authoritative decisions for scarce stock.
  • Distinguish copied data from split ownership.

Compare the important ideas

Databases and distributed data: concepts and trade-offs
TermMeansCheck
IndexMaintained read shortcutQuery plan and write cost
TransactionCoordinated selected changesBoundary and concurrent anomalies
ReplicaAnother copyLag, failover and recovery
ShardA divided ownership groupKey skew and movement

WORKED EXAMPLE

Separate browsing and purchase correctness

A cached seat map can briefly show an old available seat. The purchase path must still atomically decide whether a buyer can reserve it. A replica that has not seen the latest reservation is not an independent authority allowed to sell the same seat.

Further reading

Original teaching explanations by Buildfest Learn. Check these primary references for the underlying concepts and implementation details.