CAP, BASE and the NoSQL landscape

After this lesson you will say what a replica answers when the network breaks, define BASE in the slides' words and know where those words slip, tell the four NoSQL families apart by one line each, and fill the exam's one-point "which DB technology" table with motivations that earn the point.

A concert hall sells its tickets through a database kept in two copies, one on a server in Milan and one in Dublin, so that every fan gets a fast answer. One evening the cable between the two cities is cut. A second later a fan in Milan buys the last ticket: the Milan copy now says 0 tickets left. A second after that, a fan in Dublin opens the concert page — and the Dublin copy cannot reach Milan.

Dublin can think of three answers: "0 tickets left", "1 ticket left", or "sorry, try again later". One of them is out of its reach. Which one? And of the other two, which would you want when the Dublin fan presses Buy, and which when the same page only shows how many fans are going?

The slide that states the theorem behind this puzzle (p. 195) says a distributed system can have any two of three guarantees. The next slide takes it back. By the end of the lesson you will know why, and you will answer both questions in the slides' own words.

Three guarantees and a cut cable

The exam guideline lists "The CAP theorem" and "ACID vs. BASE" among the theory topics of NoSQL and data models, and this part of the deck is where both live. Page 195, "CAP Theorem (Brewer's Theorem)", states it: "It is impossible for a distributed computer system to simultaneously provide all three of the following guarantees":

Consistency — "all nodes see the same data at the same time".

Availability — "Node failures do not prevent other survivors from continuing to operate (a guarantee that every request receives a response about whether it succeeded or failed)".

Partition tolerance — "the system continues to operate despite arbitrary partitioning due to network failures (e.g., message loss)".

Read them on the hook (Fig. 1). A partition is the cut cable: the network splits the nodes into groups that cannot exchange messages. Consistency would mean Dublin answering "0 left", the same data Milan has. Availability means Dublin gives a real answer, a number of tickets, and not an error. Partition tolerance means the system keeps operating although every message across the cut is lost.

Milan Dublin cable cut tickets 0 tickets 1 buys the last ticket how many left? fan fan 0 left 1 left try again later which one?
Fig. 1. The hook as a picture. The sale reached Milan's copy only: no message crosses the cut, so Dublin's own copy still says 1. Which of the three answers can Dublin give?

Dublin's copy says 1, and nothing has reached it since the cut. The slides state the theorem without proof; the classic argument — Seth Gilbert and Nancy Lynch proved Brewer's conjecture in 2002 — fits on the same two copies (background, not slide text).

  1. Take the smallest distributed system: two copies, Milan and Dublin, both holding \(v_0\), "1 ticket left". With more nodes the argument is the same: split them into two groups that cannot talk to each other.

  2. Cut the cable: every message between the two is now lost — the "arbitrary partitioning due to network failures (e.g., message loss)" of the definition. Partition tolerance asks the system to keep operating anyway.

  3. A client asks Milan to write \(v_1\), "0 left". Refusing with an error would already give up availability, so Milan accepts — and the write exists in Milan only: no message can carry it to Dublin.

  4. A client then asks Dublin for the value. To stay available, Dublin must answer, without asking Milan.

  5. Dublin has heard nothing since the cut, so it can only return \(v_0\), while consistency demanded \(v_1\). While a partition lasts, C or A must give way; choosing which is the only freedom left.

So the answer out of Dublin's reach is "0 left": it is the truth, but no message can bring it there. What remains is a choice between the other two — and that is where the last line of p. 195 goes too far.

"The C of CAP is the C of ACID." No. ACID's consistency (lesson 3) means that a transaction keeps the integrity constraints: a property of one database. CAP's consistency means that every copy shows the same data: a property of replicas. A single-site database has the first and never faces the second.

Consistency or availability, decided per operation

Page 196, "So, what can be done?", corrects the slide before it. A distributed system needs a network, and "Failures can, and will, occur to a networked system", so partition tolerance must be accommodated. Then "the only option left is choosing between Consistency and Availability": "CA doesn't make any sense", except for a database on a single site — one machine has no cable to cut. (The slide adds 2-phase commit and cache validation protocols: they keep copies in step only while every node can be reached.) The choice is "Not necessarily in a mutually exclusive manner, but possibly by partial accommodation of both → trade-off analysis important". Then the two lines to learn word for word:

CP — "A partitioned node returns a correct value, if in a consistent state; a timeout error or an error, otherwise".

AP — "A partitioned node returns the most recent version of the data, which could be stale."

CP keeps the data right and gives up the answer; AP keeps answering and gives up being sure. Neither produces the current value on the far side of the cut. Try both in the widget — and the mixed setting the next slides recommend.

The partition simulator: one ticket, two copies

Milan holds the primary copy: every sale ends up there. Dublin holds a replica. Cut the cable with the switch, choose how the system answers during a partition, and send requests from both cities. Untick the switch to repair the cable. The readouts give Dublin's answers; the note says which slide sentence you just saw.

  1. Keep "CP for every operation". Cut the cable, press Milan: a fan buys the last ticket, and before pressing Dublin: a fan opens the concert page, predict Dublin's answer.
    What you should see

    "error: timeout". Dublin cannot check its copy against Milan, so CP gives "a timeout error or an error, otherwise" (p. 196). This is the insight the widget exists for: during a partition the current value (0 left) is out of Dublin's reach, so its only honest choices are an error or its own, possibly stale, version.

  2. Switch to "AP for every operation" and open the page again. Then press Dublin: a fan presses Buy. Predict the readout "fans holding the last ticket" after you repair the cable.
    What you should see

    The page now shows "1 left, 4,999 going, as of 21:00": stale, but stamped with its time. Dublin also sells from its own copy. When the cable is repaired the copies converge to 0 tickets — and the readout says 2: two fans hold the one last seat. AP is fine for showing; for selling it lets the copies disagree about something that cannot be undone.

  3. Start over, choose "per operation: Buy CP, page AP", cut the cable, let Milan sell, then try both Dublin buttons. Predict the two answers.
    What you should see

    The page answers from Dublin's copy, stale and timestamped; Buy is refused with a timeout. One database, two operations, two choices — "It's not at DBMS level, It's at operation level!" (p. 198). No seat is sold twice, and the page never goes blank.

  4. Repair the cable and open the page in Dublin under "CP for every operation", then under "AP for every operation". The value is the same. What differs?
    What you should see

    The readout says how Dublin answered: under CP "after asking Milan: one round trip", under AP "answered locally, at once". Even with no partition, consistency costs waiting — the second seesaw of p. 198, consistency against performance.

Two seesaws (pp. 197–198, Fig. 2) say what the widget showed. The first balances consistency against availability: the choice during a partition. The second swaps availability for performance. Read it as the trade-off of an ordinary day, with no partition at all: to answer consistently a replica must first hear from the others — the round trip of task 4 — so consistency is paid in waiting time. Beside it the slide writes three sentences to know by heart: "It's a trade-off!", "It's a continuous space!", "It's not at DBMS level, It's at operation level!".

Consistency Availability a balance, not a switch

p. 197: consistency against availability

Consistency Performance the price is waiting

p. 198: consistency against performance

Fig. 2. The two seesaws of "CAP: what's really about?" (pp. 197–198), redrawn. On p. 197, the choice p. 196 forces while the network is split. On p. 198 Performance takes the place of Availability; read it as the same balance with no failure at all — keeping replicas in agreement means waiting for them, so consistency is paid in performance.

"Continuous": between "wait for every copy" and "answer from the nearest one" lie settings such as "wait for two copies out of three", which lesson 22 meets as Cassandra's consistency levels. "Operation level" is task 3: one database serves the sale CP and the page AP. (Background: in 2012 Daniel Abadi gave this pair of trade-offs a name, PACELC — if Partition, then Availability or Consistency; Else, Latency or Consistency.)

Why can't Dublin simply wait until the cable is repaired?

Because waiting forever is not an answer. Availability asks for a response to every request; a node that waits a bounded time and then gives up is the CP behaviour of p. 196 — "a timeout error". A partition can last seconds or hours, and nobody inside the system knows which.

Page 199 is the picture everybody remembers, the "Visual Guide to CAP Theorem" (Fig. 3): a triangle with "Pick Two" in the middle and databases lined up along its sides.

A C P Pick Two a 2010 map CA RDBMSs (MySQL, Postgres, etc) Aster Data Greenplum Vertica AP Dynamo Voldemort Tokyo Cabinet KAI Cassandra SimpleDB CouchDB Riak CP BigTable Hypertable Hbase MongoDB Terrastore Scalaris Berkeley DB MemcacheDB Redis
Fig. 3. "Visual Guide to CAP Theorem" (p. 199), with the product lists as printed. Its corner notes: "Availability: Each client can always read and write." "Consistency: All clients always have the same view of the data." "Partition Tolerance: The system works well despite physical network partitions." The original also colours each name by data model (relational, key-value, column-oriented, document).

Read it as a map from 2010 (it comes from a blog post by Nathan Hurst — background), with two caveats the course itself supplies. It classifies whole products, while p. 198 has just said the choice is made per operation: MongoDB and Cassandra let each request say how many copies must agree (lessons 16 and 22). And its CA side is no third option for a distributed system: p. 196 grants CA only to a single site, where there is nothing to partition. Yet that side also lists Aster Data, Greenplum and Vertica, databases that run on clusters — when their network splits, they too must give up C or A.

If you revise from the course notes: their page 10 swaps the two lines. It prints the CP behaviour (a correct value, or a timeout or an error) under "AP", with "typical use case: banking applications", and the AP behaviour (the most recent, possibly stale version) under "CP". The slides are right (p. 196), and banking belongs with CP.

BASE: stale is fine, if you say when

Look again at the AP answer of the widget: "1 left, 4,999 going, as of 21:00". It is out of date, and it is not a lie. Page 202, "ACID vs. BASE", makes this a design principle: "It's ok to use stale data (Accounting systems do this all the time. It's called "closing out the books.") ; it's ok to give approximate answers". The condition: "Use resource versioning -> say what the data really is about – no more, no less." Not "x is 5", but "The value of x is 5, at time T and date D". A balance sheet closed on 31 December is still true in March — about 31 December.

The name is a chemistry pun: p. 200 shows three beakers, acid, base and salt, under "Recall the CAP theorem!", and p. 202 shifts "the PH from 0-6 (acidic) to 8-14 (basic)". Page 201 answers the obvious fear, "ACID properties may not hold -> no properties at all then???": these systems focus on "availability of data even in the presence of multiple failures" and "spread data across many storage systems with a high degree of replication" — the many copies that make immediate consistency expensive. Hence the question of p. 202, "Can some compromise be made between C and A?", instead of giving up either one completely.

BASE — "Basically Available, Soft-State, Eventually Consistent" (p. 203):

  • Basic Availability: "fulfill request, even in partial consistency."
  • Soft State: "abandon the consistency requirements of the ACID model pretty much completely" (but see the red pen below).
  • Eventual Consistency: "at some point in the future, data will converge to a consistent state; delayed consistency, as opposed to immediate consistency of the ACID properties."

The last letter carries the deepest remark of the section. Eventual consistency is "purely a liveness guarantee (reads eventually return the requested value); but does not make safety guarantees, i.e., an eventually consistent system can return any value before it converges". A liveness property promises that something good eventually happens; a safety property, that nothing bad ever happens. Fig. 4 shows the difference on three replicas.

replica 1 replica 2 replica 3 write x = 5 time → read → 3 read → 5 inconsistency window converged
Fig. 4. Eventual consistency on three replicas (x was 3 everywhere). The write reaches replica 1 at once and the others later; inside the yellow window a read on replica 3 still returns 3. Once the last copy has arrived, every read returns 5. The promise is convergence — "purely a liveness guarantee"; what a read returns inside the window is not promised — no "safety guarantees" (p. 203).

Eventual consistency promises convergence, not correctness on the way: if the writes stop, every copy ends up equal; before that, any value may come back.

Page 204 sends the bill. There is "No general answer to whether your application needs an ACID versus BASE consistency model", but "Given BASE's loose consistency, developers need to be more knowledgeable and rigorous about consistent data if they choose a BASE store", and "Planning around BASE limitations can sometimes be a major disadvantage when compared to the simplicity of ACID transactions." In an ACID database the DBMS keeps the data correct (lesson 3); in a BASE store the application must — the oversold ticket becomes your code's problem. Hence: "A fully ACID database is the perfect fit for use cases where data reliability and consistency are essential."

ACID and BASE side by side (pp. 188–193 for ACID, pp. 201–204 for BASE).
ACIDBASE
The lettersAtomicity, Consistency, Isolation, DurabilityBasically Available, Soft state, Eventually consistent
When the data is consistentimmediately, at the end of every transaction"at some point in the future": delayed consistency
What a read may returnthe committed valuea stale value — better if versioned; "any value before it converges"
Who keeps the data correctthe DBMS: integrity checking, concurrency control, recoverythe developer, "more knowledgeable and rigorous about consistent data"
Best fit"use cases where data reliability and consistency are essential"data spread over many replicas, where stale or approximate answers are acceptable

Which is why relational did not give way. Page 205, "Why didn't we change Relational?", answers "Consolidated", "Integration platform", "Granting ACID properties!" (lesson 3); the second item returns in section 5.

NoSQL: a name older than the movement

Page 207 compresses the argument so far into one "Good Quote!", signed Cedric Beust: "Google, Amazon, Facebook, and DARPA all recognized that when you scale systems large enough, you can never put enough iron in one place to get the job done (and you wouldn't want to, to prevent a single point of failure). Once you accept that you have a distributed system, you need to give up consistency or availability, which the fundamental transactionality of traditional RDBMSs cannot abide." Scale forces distribution (lesson 3), distribution forces the CAP choice, and the choice calls for new databases.

They are older than their name (Fig. 5). Pages 208–209 run from "MultiValue databases at TRW in 1965" to "The term NoSQL was reintroduced in early 2009"; p. 210, "The #NOSQL story", adds "A meetup — Johan Oskarsson in SF, CA, June 2009" and "A hashtag: #nosql". The slide prints in bold the date that surprises: "Carlo Strozzi used the term NoSQL in 1998 to name his lightweight, open-source relational database that did not expose the standard SQL interface."

1965 1979 1989 1998 2000 2004 2005 2007 2007 2008 2008 2009 2009 MultiValue databases at TRW DBM released by AT&T Lotus Domino released Strozzi's "NoSQL": relational, no SQL Neo4j started (graph) Google BigTable started (paper 2006) CouchDB started Amazon Dynamo paper MongoDB started (release 2009) Facebook open-sources Cassandra Project Voldemort started the term NoSQL reintroduced June: meetup in San Francisco, #nosql
Fig. 5. "NoSQL History" as pp. 208–210 list it. The two marked rows are the word itself: 1998, when Carlo Strozzi called a relational database without SQL "NoSQL", and early 2009, when the term came back for the opposite idea. The highlighted years 1965 and 2009 bound the list: the kind of database is 44 years older than the movement's name.

Strozzi's NoSQL keeps relational tables as plain text files and queries them with Unix pipes: it refused the SQL language, not relations. When Johan Oskarsson, then at Last.fm, reused the word for his 2009 meetup on open-source, distributed, non-relational databases, it named the opposite choice — Strozzi's own page remarks that the movement should rather have been called "NoREL". (Background: Strozzi's site and the NoSQL entry of Wikipedia.)

Who built them? Page 214, "NoSQL originators": Google (BigTable, LevelDB), LinkedIn (Voldemort), Facebook (Cassandra), Twitter (Hadoop/Hbase, FlockDB, Cassandra), Netflix (SimpleDB, Hadoop/HBase, Cassandra), CERN (CouchDB). Not database vendors: web companies and a laboratory whose own data outgrew "iron in one place". Some built the stores (BigTable, Cassandra, Voldemort, FlockDB); others were their early, visible users. Page 215, "Transactional properties?!", draws the line between the two worlds:

  • structured query language for traditional relational databases: "unique keys, single valued, no update/insertion/deletion anomalies" — the normal forms of lesson 9
  • "Well structured data"
  • "ACID properties should hold"
  • "triggered by the storage needs of Web 2.0 companies such as Facebook, Google and Amazon.com"
  • "Not necessarily well structured – e.g., pictures, documents, web page description, video clips, etc."
  • "Lately of increasing importance due to big data"
  • "BASE properties may be enough"

Not only SQL is the reading to keep: SQL stays where its guarantees are needed, and the new stores are added beside it.

Four families, one line each

The deck sorts the newcomers twice. Page 211, "Kinds of NoSQL", first makes a two-way cut: "Key/Value or 'the big hash table' (remember caching?)" — Amazon S3 (Dynamo), Voldemort, Scalaris, MemcacheDB, Azure Table Storage, Redis, Riak — against "Schema-less": "Cassandra (column-based)", "CouchDB (document-based)", "Neo4J (graph-based)", "HBase (column-based)" — an odd cut, since key-value stores are schema-less too. Pages 212–213, "Different Types of NoSQL", then give the four families the exam works with, each with the line that tells it apart. Learn the lines: they are the motivations of the one-point table.

The four families as pp. 212–213 print them, and where each one is taught in this notebook.
Family (slide title)The slide's lineProducts on the slideLessons
Key-Value Store"A key that refers to a payload (actual content / data)"MemcacheDB, Azure Table Storage, Redis17–19
Column Store"Column data is saved together, as opposed to row data"; "Super useful for data analytics" (see the red pens)Hadoop, Cassandra, Hypertable20–22
Document / XML / Object Store"Key (and possibly other indexes) point at a serialized object"; "DB can operate against values in document"MongoDB, CouchDB, RavenDB13–16
Graph Store"Nodes are stored independently, and the relationship between nodes (edges) are stored with data"Neo4j10–12

The four lines differ in what the database can see (Fig. 6). A key-value store sees keys only: the payload is opaque, so the one question it answers fast is "what is under this key?" — which is why p. 211 says "remember caching?". A document store sees inside the payload: it can index and filter on fields, it "can operate against values in document". A graph store sees the relationships themselves, stored next to the nodes, so a query walks from node to node instead of joining tables. And the column store keeps rows found by a key, each row with its own set of columns — which is not quite what p. 212 says.

Key-value store a key that refers to a payload Redis, MemcacheDB cart:7 …bytes… user:9 …bytes… opaque Document store DB can operate against values in document MongoDB, CouchDB { name: "Fenice" maestro: {…} members: […] } query Column store rows found by a key, columns vary by row Cassandra, HBase s1 s2 s3 Graph store edges are stored with the data Neo4j WENT_TO AT :Fan :Concert :Hall
Fig. 6. What each family can see. Key-value: only the key, the payload is opaque. Document: the fields inside, so a query can reach a field. Column store: rows found by a partition key (yellow), each row with its own number of columns — the wide-column picture the course's Cassandra lecture uses, not the one p. 212 describes (red pens below). Graph: the relationships are data, so a query walks them.

The exam adds a fifth family that these slides do not list. The guideline deck names, among the features to know, "Search-based (ElasticSearch)", and the 2026/27 rules list Elasticsearch among the practical topics. Its line: an inverted index from words to documents, with relevance scoring — find by words and rank the hits (lessons 24–26).

One more slide explains how a company ends up using several families at once. Page 216, "Integration: from data to services" (Fig. 7), shows two applications, Billing and Inventory. In the "SQL world" they meet in one Integration Database — p. 205's "Integration platform" — so its schema is a contract nobody may break, and one model must serve them all. In the "NO-SQL world" each owns an Application Database and they talk through a web service: each database now belongs to one application and can be schema-less, a graph or a key-value store, whichever fits that application's data.

Billing Inventory Integration Database shared

SQL world: the database is the meeting point

Billing Inventory web service Application Database

NoSQL world: services are the meeting point

Fig. 7. "Integration: from data to services" (p. 216), redrawn. Before: Billing and Inventory share one Integration Database, so its schema is everyone's contract. After: each application owns an Application Database and the two talk through a web service, so each may change its schema, or choose another family of store, without asking the other.

The one-point table: which database for which part

Five of the nine past papers open with the same exercise: "Exercise 1 - Unstructured data models (1 PT)", "Which DB technology would be the best to store the entities/rel. of the ER diagram? [you may not need all the rows of the table]", with a three-column table, ENTITIES / REL. | DB TYPE | MOTIVATION, and three empty rows. The exam guideline describes the skill in its own words: "which data model families should be used for each part of the data". The family lines of section 5 are the toolkit; here is a recipe:

  1. Read the shape of the data. A web of many-to-many relationships points to a graph. An entity read together with its 1:N children, or an ISA whose children carry different attributes, points to a document. Free text searched by words points to a search engine. A value reached only through its key — a cache, a set, a counter with a TTL — points to key-value. A large, continuously growing volume of records, written fast and read by key, points to a column store.
  2. Read the shape of the questions: counting along paths, filtering inside an aggregate, ranking by words, fetching by key.
  3. Group the entities and relationships into two or three parts, one family each.
  4. Motivate each row with data shape, question shape and the family's line from pp. 212–213.

The paper gives itself away. Its later exercises name the entities each technology gets: in the exam of 13 June 2025, Neo4j works on Audience, Concert, Artistic Director and Location, MongoDB on Orchestra, Maestro, Musician and Instrument, Redis on Instrument, Elasticsearch on Track. Read the whole paper before filling the table. An entity may appear in two exercises — that is two access paths to the same data, not a contradiction.

The column store fills no row of the solved table below, but two 2025 papers say when the examiners reach for one: "Suppose you expect to record large-scale, continuously increasing number of sales of products in the market, and therefore you decide to store it in a columnar database" (exam of 12 Sept 2025, exercise 1; the exam of 30 May 2025 says the same of "a large number of purchases of puzzles"). A volume that keeps growing, read by key: that is the column store's motivation.

Now rehearse on a real paper: the exam of 13 June 2025, "tracking concert attendances and performances", exercise 1. Its ER diagram has Person, with the total and exclusive sub-entities Audience, Artistic Director, Maestro and Musician, and Concert, Location, Track, Orchestra and Instrument, joined by Attend, Organize, Located, At, Perform, Direct, Compose and Play. The widget takes it one fragment at a time, drawn in the paper's notation.

Which DB for which part: the exam of 13 June 2025

Four fragments of the paper's ER diagram, each with the question the same paper later asks about it. For each fragment choose a DB type and one of the four motivations (tap it, or pick its letter), then press Check this row. A row that is right on both counts enters the exam table under the widget.

  1. Fragment 1. Before choosing, look at the cardinalities of Attend and at the question the paper asks. What shape is the data, what shape is the question? Choose, then check.
    What you should see

    Graph, motivation B: Attend is many-to-many and both questions count along chains of relationships. This is the insight the drill is built on: the family follows the shape of the data and of the question, not the name of the entity.

  2. Fragment 2. A graph is tempting, since Play is many-to-many. Predict what makes the document store the better answer, then check — and read the feedback of motivation A.
    What you should see

    Document, motivation D. The questions never go deeper than orchestra → member → instrument and always start from an orchestra or a musician: an aggregate with two fixed levels, which nesting covers, and the database can filter on the nested values. A graph would work, but it is not the best fit.

  3. Instrument appears in fragments 2 and 4. Predict: can the same entity deserve two families? Do fragment 4 and compare.
    What you should see

    Yes. In fragment 2 the instruments are nested in the orchestra document, because they are read with the musicians; in fragment 4 the paper only asks whether a name is in a set, with a time to live — key-value. Same entity, two ways of reaching it, two stores. The table asks how the data is used, not what it is called.

  4. When all four rows are right, read the assembled table. The paper's table has three rows. Which one would you leave out?
    What you should see

    The key-value row. The three large parts — graph, document, search — cover every entity of the diagram; the set of instrument names is a small extra. The paper's own bracket, "you may not need all the rows of the table", works the other way too: a fourth idea can go in a sentence under the table.

Check yourself: the model table for the exam of 13 June 2025
ENTITIES / REL.DB TYPEMOTIVATION
Audience, Concert, Artistic Director, Location; Attend, Organize, LocatedGraph DB (Neo4j)Attend is many-to-many (a member attends 1..N concerts, a concert has 0..N attendees) and the queries count along paths: concerts per director with more than 1000 attendances, locations per member. The relationships are stored with the data, so each hop is followed without a join.
Orchestra, Maestro, Musician, Instrument; Direct, Compose, PlayDocument DB (MongoDB)An orchestra is an aggregate read as one unit: its maestro (Direct is 1:1) and its members — at least 10, each in at most 2 orchestras — nested in it with the instruments they play (Since as a field). The DB can operate against values in the document: members named "Lorenzo" who play the piano.
TrackSearch-based DB (Elasticsearch)Tracks are found by words in their fields — composer "Bach", music type classical — and ranked ("prioritizing" the longer ones): an inverted index with relevance scoring.

Under the table, one sentence for what is left: the Person attributes are copied into each sub-entity where it is stored; At and Perform can be edges from the concerts and orchestras to track nodes that carry only the title; and the set of instrument names checked by exercise 4 is a key-value extra.

Back to the concert hall of the hook. "0 tickets left" was out of Dublin's reach: the truth was on the other side of the cut. The other two answers are the two corners: "1 left, as of 21:00" is AP, "try again later" is CP. For Buy you want CP — an error is better than a seat sold twice, as the widget's oversold counter showed. For the count of fans going, AP is fine, and honest when it carries its time. One system, two choices, made per operation: "It's not at DBMS level, It's at operation level!". And "pick two of three" was never the menu — the cut cable had already chosen P.

Exam-style questions

Theory questions in the forms the theory part uses — true/false, multiple choice and short open answers, where a wrong tick may cost points — and one practical exercise in the wording of the past papers.

True or false: according to the CAP theorem, a distributed database can choose to be CA — consistent and available — by not tolerating network partitions.

  • True In a distributed system the network is inevitable and "Failures can, and will, occur": partition tolerance cannot be declined.
  • False Partition tolerance must be accommodated, so during a partition the choice is between consistency and availability; "CA doesn't make any sense" except for a single-site database (p. 196).
Show model answer

False. In a distributed system a network is inevitable and failures will occur, so partition tolerance must be accommodated; when a partition happens the only choice left is between consistency and availability. CA makes sense only for a single-site database, which is not distributed.

The trap is p. 195's "any two of these guarantees". The examiner checks that you know p. 196 takes it back. Wrong answers may carry a penalty (the rule is announced just before the exam): tick only what you can justify.

During a network partition, a node of a CP system:

  • returns the most recent version of the data it holds, which could be stale That is the AP behaviour (p. 196).
  • returns a correct value if it is in a consistent state, and a timeout or an error otherwise The CP line of p. 196, nearly word for word.
  • accepts every write locally and reconciles the copies after the partition Availability first, convergence later: that is AP and BASE, not CP.
  • keeps answering normally, because partitions do not affect CP systems A partition affects every distributed system; CP pays for it with availability.
Show model answer

The second option. A CP system keeps consistency and gives up availability: a partitioned node returns a correct value if it is in a consistent state, a timeout error or an error otherwise.

Learn the two lines of p. 196 exactly; the course notes (printed p. 10) swap them, which is the most likely way to get this question wrong.

State the CAP theorem and its three guarantees. Explain why, in practice, a distributed system chooses between consistency and availability, and why that choice can be made per operation. Give an example.

Show model answer

The CAP theorem (Brewer) states that a distributed system cannot provide at the same time Consistency (all nodes see the same data at the same time), Availability (node failures do not stop the survivors; every request receives a response about whether it succeeded or failed) and Partition tolerance (the system keeps operating despite arbitrary partitioning due to network failures, such as message loss). In a distributed system the network is inevitable and failures will occur, so partition tolerance must be accommodated: during a partition a node that cannot reach the others either refuses — CP: a correct value if it is in a consistent state, a timeout or an error otherwise — or answers with the most recent version it has, which could be stale — AP. CA is meaningful only for a single-site database. The trade-off is a continuous space and is decided at operation level, not for the whole DBMS; even without partitions, consistency costs latency. Example: a ticketing system serves the purchase of a seat CP (better an error than a seat sold twice) and the page showing how many fans are going AP (a slightly stale, timestamped count is acceptable).

Three things to earn: the three definitions, the argument that P cannot be declined (hence C or A), and the operation-level trade-off with an example. "Pick any two" alone, without p. 196, is the answer the slides themselves correct.

What does BASE stand for? Explain each property, why eventual consistency is "purely a liveness guarantee", and when an ACID database is the better choice.

Show model answer

BASE stands for Basically Available, Soft state, Eventually consistent. Basically available: the system fulfils requests even in partial consistency, answering when some replicas are not up to date. Soft state: the state may change over time without new input while the replicas converge (the slide words it as abandoning the consistency requirements of the ACID model "pretty much completely"). Eventually consistent: at some point in the future the data will converge to a consistent state — delayed rather than immediate consistency. This is purely a liveness guarantee, because it only promises that something good eventually happens (reads return the converged value), and no safety guarantee, because before converging the system can return any value. The rationale is that stale data is acceptable when it is versioned ("the value of x is 5, at time T and date D"), as accounting does when it closes out the books. The price is that developers must be more knowledgeable and rigorous about consistent data, so a fully ACID database is the better fit where data reliability and consistency are essential, such as payments.

Give both readings of soft state — the slide's sentence and the precise meaning. The liveness/safety pair is the part most answers miss, and "who pays" (the developer, p. 204) is the comparison with ACID the examiner looks for.

Which statements about NoSQL agree with the lecture? Select all that apply.

  • In a key-value store, a key refers to a payload, the actual content. p. 212.
  • In a document store, the database can operate against the values inside the document. p. 213.
  • In a graph store, the relationships between nodes (edges) are stored with the data. p. 213.
  • The term NoSQL was coined in 2009 for the first non-relational databases. Carlo Strozzi used it in 1998 for a relational database without the SQL interface; it was reintroduced in early 2009 (pp. 208–209), and non-relational databases go back to MultiValue, 1965.
  • NoSQL means that SQL is not used at all. p. 215 reads it "NoSQL (Not only SQL)": SQL stays, it is no longer the only option.
Show model answer

The first three. The term NoSQL was first used by Carlo Strozzi in 1998 for a relational database without SQL and reintroduced in 2009; it is read "Not only SQL".

A select-all question where wrong ticks may cost points: the two false options are the classic traps, the 1998 origin of the word and the "not only".

Exam of 6 Sept 2024, exercise 1. Consider the following ER diagram of a restaurant. Person (Personal_ID, Name, Surname, Birth Date, Phone Number) has the sub-entities Owner (Owner Since, E-mail), Customer (E-mail), Waiter (Hiring Date) and Chef (Hiring Date); Head Chef (Head Chef Since) is a Chef. Restaurant (Restaurant_ID, Name, Maximum Number of Guests, Address, Phone Number); Table (Table_ID, Table Number, Max Seats); Dish (Dish_ID, Name, Price, Recipe, Description); Ingredient (Ingredient_ID, Name, Allergies (Yes/No)). Many-to-many relationships (1:N on both sides): Book between Customer and Table, with Number of People and Booking Date; Serve between Waiter and Table; Order between Table and Dish; Cook between Chef and Dish; Use between Dish and Ingredient. One-to-many: Has, Table (1:1) – Restaurant (1:N); Owns, Restaurant (1:1) – Owner (1:N); Manage, Chef (1:1) – Head Chef (1:N). N.B. There is only one Head Chef per Restaurant. Tables are served by more Waiters overall, but only one at a time. Dishes are cooked by more Chefs overall, but only one at a time.

Which DB technology would be the best to store the entities/rel. of the ER diagram? [you may not need all the rows of the table] (1 PT) — ENTITIES / REL. | DB TYPE | MOTIVATION

Show model answer
ENTITIES / REL.DB TYPEMOTIVATION
Customer, Table, Waiter, Dish; Book, Serve, OrderGraph DB (Neo4j)Many-to-many links (bookings, service, orders) traversed and counted, e.g. different dishes served at each table, customers served by each waiter; edges are stored with the data, and Book's attributes become edge properties.
Chef, Head Chef, Dish, Ingredient; Cook, Use, ManageDocument DB (MongoDB)A chef is an aggregate read as one unit: the dishes they cook, each with its ingredients, nested inside (a dish cooked by several chefs is copied into each, acceptable because every query starts from the chef); Head Chef is a Chef with one more field (schema-less); the DB operates on nested values, e.g. chefs who cooked a dish named "Octopus with Potatoes".
Dish (Name, Description, Recipe)Search-based DB (Elasticsearch)Full-text conditions with ranking (description and name containing "salmon", recipes with "stir" or "boil" first): an inverted index with relevance scoring.

Restaurant, Owner, Has and Owns are small and can be nodes and edges of the graph.

The grouping follows the paper's own later exercises: Neo4j on Customer, Table, Waiter and Dish; MongoDB on Head Chef, Chef, Dish and Ingredient; Elasticsearch on Dish (exercise 5 also puts Chef in a Cassandra table, a fourth access path the three rows need not list). Dish in two rows is expected — a node in the graph, a text document in the index. The paper writes cardinalities as 1:N, the 2025 papers as (1,N): the same pair. The examiner looks for a family per part and a motivation that names the shape of the data and of the queries.

Check yourself

The cable is cut and the ticket counter is served CP. A fan in Dublin presses Buy. What happens, and why?

  • The sale goes through from Dublin's own copy, which still says 1 left, and the copies are reconciled later That is the AP behaviour, and it is how the last seat gets sold twice.
  • The request fails with a timeout or an error, because Dublin cannot confirm with the primary that the seat is still free CP: "a correct value, if in a consistent state; a timeout error or an error, otherwise" (p. 196). Availability is given up so that consistency holds.
  • The request holds the seat and waits until the cable is repaired, then Milan confirms the sale Waiting forever is not an answer; CP gives up after a while with a timeout.
  • Dublin forwards the sale to Milan over the cut cable No message crosses a partition: that is what a partition is.

During a partition, which of these operations could you serve AP — from the local copy, possibly stale? Select all that apply.

  • The "fans going" count on a concert page A slightly old number misleads nobody, especially if it says "as of 21:00" (p. 202).
  • A "people who went to this concert also liked…" list Recommendations tolerate staleness; an approximate answer is fine (p. 202).
  • Selling the last ticket Two replicas could each sell it: the oversold state of the widget.
  • A transfer between two bank accounts "A fully ACID database is the perfect fit for use cases where data reliability and consistency are essential" (p. 204).

The test for AP: is a stale but timestamped answer still a true statement that nobody acts on irreversibly?

Page 196 accepts "CA" only for a single-site database. Why does CA make sense there?

  • Because a single site answers faster than a cluster, so no request ever reaches a timeout Speed has nothing to do with it; the theorem is about what happens when messages are lost.
  • Because with one site there is no network between copies, hence no partition to tolerate Consistency and availability can then hold together — until the site itself fails, which is a different problem.
  • Because single-site databases follow BASE They are the classic ACID systems.
  • Because there the C means "integrity constraints", which one machine can always check That is ACID's C; CAP's C is about copies agreeing, and a single site has one copy.

An eventually consistent store: you write x = 5 and at once read x on another replica. What is guaranteed?

  • The read returns 5 That would be immediate consistency, which BASE gives up.
  • The read returns 5 or the previous value, never anything else The slide is blunter: "an eventually consistent system can return any value before it converges" (p. 203).
  • If no new writes arrive, reads will eventually return 5 on every replica; before that, nothing is promised about the value A liveness guarantee without safety: convergence, not correctness on the way.
  • The read blocks until every replica has 5 Blocking until all copies agree is the consistent, ACID-style behaviour.

A key-value store and a document store both keep the JSON of user 7 under the key user:7. By the definitions of pp. 212–213, what can only the document store do?

  • Find all the users whose city is Milan, by looking inside the stored values "DB can operate against values in document" (p. 213); to a key-value store the payload is opaque.
  • Return the value stored under user:7 quickly Both do that: it is the key-value store's one job.
  • Store a value of any shape and size, from a short string to a whole JSON tree A key-value store accepts any payload; it just cannot look into it.
  • Keep several copies of each user on different nodes, so that a crash loses nothing Replication is independent of the data model.

For a sensor log written at a very high rate and always read by sensor and time, you choose a column store. Which motivation should you write in the exam table?

  • Wide-column store (Cassandra): very large and growing volumes written fast, rows found by the sensor key, scaling out by adding nodes What Cassandra is built for; lesson 21 adds ordering by time inside each sensor's row.
  • Hadoop: column data is saved together, super useful for data analytics Hadoop is a file system plus a processing engine, not a database, and the sentence describes column-oriented storage, not Cassandra (the red pens of section 5).
  • Document store (MongoDB): every reading is a small JSON document, and documents need no fixed schema Possible as storage, but nothing is nested or read as an aggregate; volume and access by key decide.
  • Graph store (Neo4j): each reading is linked to the next one in time, so the log is a path to traverse A sequence is not a web of relationships to traverse.

Why did the move "from data to services" (p. 216) make it acceptable for a database to drop the shared schema?

  • Once each application owns its database and the others reach it only through a web service, a change of schema stays inside one application The database stops being the integration platform (p. 205), so it may follow the needs of one application.
  • Because a web service answers faster than a shared database, so the schema no longer slows anyone down Speed is not the argument; ownership of the schema is.
  • Because the web service validates every request against the schema, on behalf of the database The service hides the database; it does not enforce its schema.
  • Because NoSQL databases cannot be shared between applications They can be; the point is that they no longer have to be.

Key take-aways

What to watch and read