Module 25 of 52 · Engineering and platforms

Databases and storage systems

30 min 3 outcomes Interactive + terminal 6 references

By the end of this module you will be able to:

  • Explain Codd's relational model and the guarantees ACID properties provide
  • Apply the CAP theorem to choose a database for a given consistency-availability trade-off
  • Identify the correct NoSQL model (document, key-value, column-family, graph) for a data pattern

Database choice triaged by workload across four shapes

Database choice is a workload triage, not a vendor argument, and a row store for OLTP, columnar for aggregation, an inverted index for free text and triples for traversal differ only at scale, so a choice made on familiarity holds right up to the boundary that forces a migration.

Database choice is a workload triage, not a vendor argument: OLTP for transactions, analytics columnar for aggregation, search index for free-text, graph for relationship queries. Choosing by team familiarity instead of workload hits the boundary as soon as scale arrives.

Database choice triaged by workload across four shapes A field divided by a dashed red boundary line. Left of the line, a grey panel headed One row store for everything, chosen for familiarity, where stuffing analytics into Postgres works at a million rows and, in red, breaks at a billion. Right of the line, the four workload shapes sit two by two as peers with no arrows between them: OLTP with a row store and ACID, Analytics with columnar aggregation emphasised in red soft, Search with an inverted index for free text, Graph with triples, traversals and SPARQL. A scale axis below runs from a million rows to a billion, and the boundary line drops onto a plate reading The boundary forces a migration. A filled red band closes the figure. Workload decides the shape, not the vendor Chosen for familiarityOne row store for everythingStuffing analytics into Postgres works at amillion rowsand breaks at a billion. OLTPRow store, ACIDISO 9075 AnalyticsColumnar, aggregationKimball SearchInverted index, free-textApache Lucene GraphTriples, traversals, SPARQLW3C RDF A million rowsA billion rowsThe boundary forces a migration Familiarity-driven choice hits the boundary at scaleMatch shape to workload before the boundary forces a migration.

Where distribution starts paying for itself

One machine now covers a large share of real analytical work, which is why a cluster can only be justified on the query shape and the concurrency in front of you, and never as the default starting point.

One machine now covers a large share of real analytical work, so a cluster should be a decision you can defend on the query shape and the concurrency, not a default. Each side of the boundary pays a different bill: the single node pays a ceiling, the cluster pays coordination.

Where distribution starts paying for itself A boundary drawn on a scale. Two panels sit either side of a dashed red line that runs down onto a workload axis below. The left panel, emphasised in red soft, is headed One machine: whole dataset in memory, one process and one failure mode, no shuffle. In red, it pays a ceiling on memory and concurrency. The right panel is headed A distributed cluster: parallel scan, storage beyond one machine, concurrency beyond one process. In red, it pays coordination, retries and operations. The axis runs from smaller to larger workload, and a plate on the boundary reads Cross here for a reason you can name. A filled red band closes with the four tells that the line has been crossed. Distribution is a means, not a status symbol Left of the lineOne machineWhole dataset in memoryOne process, one failure modeNo shuffle, no network hopPays a ceiling: memory and concurrency both stop atthe box Right of the lineA distributed clusterParallel scan across machinesStorage beyond one machineConcurrency beyond one processPays coordination: shuffle, retries, operations and asecond skill set Smaller workloadLarger workloadCross here for a reason you can name Four tells that the line has been crossedData outgrows one machine · Many concurrent users · Joins that must shuffle · Uptime beyond one box

CAP theorem: during a partition, choose consistency or availability

CAP theorem: while a network partition lasts, a distributed system must choose, for the affected operations, between consistency and availability: refuse what it cannot prove consistent (CP), as a ledger does, or answer with something possibly stale (AP), as a feed does.

CAP theorem: while a network partition lasts, a distributed system has to choose, for the affected operations, between consistency and availability. Partitions cannot be ruled out, so the design choice is CP (refuse what cannot be proved consistent) or AP (answer with possibly stale data). Gilbert and Lynch 2002 proved this formally.

CAP theorem: during a partition, choose consistency or availability Three columns name the guarantees: Consistency, every read sees the latest write; Partition tolerance in the middle, works under network split, emphasised in red; Availability, every request gets a response. Below them each pair is a span across exactly the two columns it keeps. The span marked C plus P covers consistency and partition tolerance: banks pick CP, refusing the transaction rather than showing a stale balance. The span marked P plus A covers partition tolerance and availability: social feeds pick AP. The third pair, C plus A, is a dashed rule broken over the middle column, labelled that it needs a network that never splits. A red band closes the figure. CConsistencyEvery read sees the latest writeCAP PPartition toleranceWorks under network splitGilbert+Lynch AAvailabilityEvery request gets a responseCAP C + PBanks pick CP: refuse the transaction rather than show stale balance P + ASocial feeds pick AP: show possibly stale content rather than fail. C + Aneeds a network that never splits Network partition is unavoidable; the real choice is CP vs AP

Twitter FlockDB: storing wide social graph adjacency lists at scale

In 2010, Twitter's engineering team described FlockDB, a distributed database for storing social graph edges such as who follows whom. The problem was not deep graph theory. It was operational scale: very large adjacency lists, high read and write rates, paging through millions of edges, and set operations that had to stay fast under social network traffic.

A relational model can represent the same relationship with a followers table, but the access pattern matters. If the product frequently asks for all followees of one account, all followers of one account, or set differences between two adjacency lists, the storage design should make those reads local and predictable rather than forcing wide joins through a general-purpose schema.

FlockDB's lesson is more precise than "use a graph database for graphs". It shows that the correct database abstraction starts with the query pattern. Deep multi-hop traversal, fraud ring discovery, and knowledge graph reasoning need graph traversal engines. Wide social adjacency lists need fast edge storage, set arithmetic, and horizontal scaling.

Twitter had 500 million users, each with hundreds of followers and followees. The follower graph did not fit the relational model efficiently. What makes graph databases the right abstraction for social network relationships?

Database choice starts with the shape of truth: what must be stored, what must be queried, and what must never be half-written.

22.1 The relational model and ACID

Edgar Codd published "A Relational Model of Data for Large Shared Data Banks" in 1970. His insight was that data should be represented as relations with tuples and attributes, and that users should specify what data they wanted rather than navigating machine storage paths. SQL emerged from IBM research in the 1970s, became an ANSI standard in 1986, and became an ISO standard in 1987. The current ISO/IEC 9075 family is SQL:2023.

ACID properties define the guarantees a relational database provides for transactions. Atomicity means a transaction either completes fully or not at all: there is no partial update state. Consistency means the database moves from one valid state to another valid state, enforcing all defined constraints. Isolation means concurrent transactions do not see each other's in-progress changes (at the configured isolation level). Durability means committed transactions survive system crashes: the data is written to persistent storage before the commit is acknowledged.

These guarantees matter because real business operations involve multiple related changes. A bank transfer must debit one account and credit another atomically. If the system crashes after the debit but before the credit, the atomicity guarantee means the debit is rolled back. Without ACID, financial systems, inventory management, and booking systems would produce incorrect results during failures or concurrent access.

“It provides a means of describing data with its natural structure only.”

E.F. Codd, 'A Relational Model of Data for Large Shared Data Banks', Communications of the ACM (1970) - Section 1

Codd separated the logical representation of data from the physical storage path. That separation is why SQL can ask for a result without telling the database which index, join order, or disk page to use.

ACID settles whether a transaction is correct. It does not settle whether the answer arrives quickly, and that is decided by the plan the engine picks.

22.2 Execution plans and index design

SQL query optimisation uses an execution plan: a tree of operations (scans, joins, sorts, aggregations) that the query planner selects to minimise cost. Indexes on frequently queried columns allow range scans instead of full table scans. EXPLAIN ANALYSE in PostgreSQL reveals the actual execution plan and row counts, which is the first tool to reach for when a query is slow.

Loading interactive component...

ACID explains correctness inside a transaction; distributed systems force the same correctness question across machines that can lose contact with each other.

22.3 The CAP theorem and distributed databases

Eric Brewer's CAP conjecture (2000), formally proved by Seth Gilbert and Nancy Lynch in 2002, is often reduced too far. The useful form is this: when a network partition occurs, a distributed data system must choose between consistency and availability for the affected operation. Consistency means a read receives the most recent write or an error. Availability means every request receives a non-error response, without guaranteeing it is the newest value. Partition tolerance means the system continues to have defined behaviour when messages between nodes are delayed or dropped.

In practice, network partitions are not optional in a distributed system. The real trade-off is between consistency and availability during the partition. A CP design refuses reads or writes it cannot prove are consistent. An AP design serves potentially stale reads or accepts writes that will be reconciled later. Outside a partition, many systems can provide both useful availability and strong consistency for normal operations.

The right choice depends on the application. A banking ledger requires CP: serving a stale balance could allow overdrafts. A product catalogue or social media feed tolerates AP: a slightly stale product count or a delayed post count is acceptable. Most modern distributed databases (Cassandra, DynamoDB, CockroachDB, MongoDB) implement tunable consistency, allowing the application to choose the consistency level per query.

The next decision is not SQL versus NoSQL as a slogan; it is whether the access pattern is relational, document-shaped, key-based, append-heavy, or relationship-heavy.

Common misconception

“NoSQL databases do not support ACID transactions.”

This was true of early NoSQL systems but is no longer accurate. MongoDB has supported multi-document ACID transactions since version 4.0 (2018). Amazon DynamoDB supports transactions across multiple items. CockroachDB and Google Spanner are distributed SQL databases offering full ACID guarantees at global scale. The modern choice is not between SQL (ACID) and NoSQL (no ACID) but between different data models and consistency trade-offs, many of which can now be implemented with transactional guarantees.

22.4 NoSQL data models and when to use them

Four primary NoSQL data models address different access patterns that the relational model handles poorly or inefficiently.

  • Document stores (MongoDB, Firestore) store JSON or BSON documents. Ideal for data with variable schema (product catalogues with different attributes per category), hierarchical data that would require many joins (a blog post with embedded comments), or rapid development where schema evolves frequently.
  • Key-value stores (Redis, DynamoDB) retrieve values by a primary key: Redis, held in memory, answers in under a millisecond, and DynamoDB in single-digit milliseconds (microseconds with its DAX cache). Ideal for caching, session storage, leaderboards, and rate limiting where the access pattern is always get/set by a known key.
  • Column-family stores (Apache Cassandra, HBase) store data in columns grouped into column families, optimised for wide-row writes and time-series data. Ideal for IoT sensor ingestion, event logs, and metrics where data is appended chronologically and queried by time range.
  • Graph databases (Neo4j, Amazon Neptune) store nodes and edges with arbitrary properties, optimised for multi-hop traversal. Ideal for social networks, recommendation engines, fraud detection (unusual transaction graph patterns), and knowledge graphs where relationship traversal is the primary operation.

Naming one of those four families is the last move in a modelling sequence, not the first.

22.5 From conceptual model to physical design

The prerequisite skill is abstraction discipline. A conceptual model names the business things and relationships. A logical model turns those into entities, attributes, constraints, and identifiers. A physical model commits to indexes, partitions, denormalisation, clustering keys, and storage engines. Senior leaders need this chain because platform choices create lock-in and operational risk. Engineers need it because a database can only be excellent for the queries it was designed to answer.

22.6 Check your understanding

A payment processing system must ensure that when a customer pays for an order, the payment record and the order status update either both succeed or neither does. The system handles 10,000 transactions per second across three database nodes. Which ACID property is most critical here, and why?

An IoT platform ingests 50,000 temperature sensor readings per second, each with a sensor ID, timestamp, and temperature value. Readings are always appended (never updated) and queried by sensor ID and time range. Which database model is best suited to this workload?

A distributed database cluster experiences a network partition: nodes A and B can communicate with each other but not with node C. Under the CAP theorem, the system must choose between consistency and availability. A financial ledger application is using this database. Which choice is correct and why?

Loading interactive component...

Core checks before moving on

  • Codd's relational model separates logical data structure from physical storage path; SQL grew from that idea and is now maintained as ISO/IEC 9075.
  • ACID protects transaction correctness. Atomicity prevents half-finished business events, isolation controls concurrent visibility, and durability survives crashes after commit.
  • CAP is a partition-time trade-off: during a network partition, a distributed system must choose whether to preserve consistency or serve availability for the affected operation.
  • NoSQL is not one design. Document, key-value, column-family, and graph databases optimise for different access patterns.
  • Model choice should move from conceptual to logical to physical design before technology preference enters the conversation.

Standards and sources cited in this module

  1. E.F. Codd, 'A Relational Model of Data for Large Shared Data Banks', ACM (1970)

    The founding paper of relational database theory. Introduced the concepts of relations, tuples, and the precursor to SQL.

  2. Seth Gilbert and Nancy Lynch, 'Brewer's Conjecture and the Feasibility of Consistent Available Partition-Tolerant Web Services', ACM SIGACT News (2002)

    Formal proof of the CAP theorem. The authoritative reference for the consistency/availability trade-off in distributed systems.

  3. Amazon DynamoDB team, 'Dynamo: Amazon's Highly Available Key-value Store', SOSP (2007)

    Describes the eventual consistency model, consistent hashing, and vector clocks used by DynamoDB. Foundational to understanding AP-oriented distributed databases.

  4. ISO/IEC 9075:2023 SQL

    Current international SQL standard family for relational database language conformance.

  5. Apache Cassandra documentation: data modelling

    Stable Apache Cassandra documentation for query-driven modelling, partition design, and column-family storage.

  6. Twitter Engineering: Introducing FlockDB

    Primary engineering context for FlockDB as a social graph edge store optimised for wide adjacency lists and set operations.

Build it in the workspace

The artefact this module describes, as something you can fill in.

Module 25 of 52 · Engineering and platforms