Transactions, partitions and replicas: what one machine promises

After this lesson you will run the slide's bank transfer through a commit, a rollback and a crash and name the property that saved it, explain why "buy a better machine" stops working and when, and say what partitioning and replication each buy and cost.

Account 12202 holds 100 and account 42177 holds 25. A bank's server starts moving 10 from the second account to the first: it adds 10 to 12202 — and the power fails before it can take 10 from 42177. For that instant the two accounts hold 135 instead of 125, ten units of money that came from nowhere, and the new balance 110 may already sit on the disk.

When the server comes back, who has the extra 10? Keep the question open. The first half of this lesson answers it with four letters that a single relational machine promises. The second half asks why, if one machine keeps its promises so well, the slides still draw "buy a better machine" as a staircase that runs out — even when the machine has 576 cores and 24 TB of memory.

The relational contract: a schema and a unit of work

The slides' example works on one table, Account, with an account number AccNum and a Balance. Before any transaction runs, its schema already promises three things, which p. 144 ("The data schema") lists as three bare words: Typing, Coherence, Uniformity. Fig. 1 shows what each one refuses.

Account AccNum Balance integer integer 12202 100 42177 25 the schema the data refused at write time 55031 'ten' Typing: not an integer 12202 50 Coherence: duplicate key 61740 70 VIP Uniformity: extra column
Fig. 1. The three words of p. 144 as three refusals. The schema fixes the names, the types and the key of Account before any row arrives, and the DBMS rejects every insert that does not fit — at write time.

Typing: every column has a type, so a balance of 'ten' is refused. Coherence: integrity constraints — keys, references, conditions — keep the data consistent with itself, so a second account 12202 is refused. Uniformity: every row has the same columns. The slide gives only the three words; these glosses are their standard reading. Note when the checks happen: at write time, before the data is accepted. Lesson 4 is about systems that drop them on purpose.

A transaction is one unit of work

The next slide (p. 145) names three settings where transactions matter: "The relational world", "Multi-user", "Distributed systems". This lesson lives in the first two and ends at the door of the third.

Transaction — "An elementary unit of work performed by an application" (p. 146). It is encapsulated within two commands, begin transaction (bot) and end transaction (eot); within it exactly one of commit work (commit) or rollback work (abort) is executed.

The slides' example (p. 148) moves 10 from account 42177 to account 12202:

-- p. 148: transfer 10 from account 42177 to account 12202
begin transaction;
update Account
  set Balance = Balance + 10 where AccNum = 12202;
update Account
  set Balance = Balance - 10 where AccNum = 42177;
commit work;
end transaction;

Credit 12202, debit 42177, make both permanent. The order of the two updates does not matter; that they happen together or not at all does. The next slide (p. 149) adds a business rule — no overdraft — and lets the program choose how to end:

-- p. 149: commit only if 42177 does not go below zero
begin transaction;
update Account
  set Balance = Balance + 10 where AccNum = 12202;
update Account
  set Balance = Balance - 10 where AccNum = 42177;
select Balance into A from Account
  where AccNum = 42177;
if (A>=0) then commit work
          else rollback work;
end transaction;

After the debit, the program reads the new balance of 42177 into the variable A. If A is at least zero it commits; otherwise it executes rollback work — and the rollback cancels the credit to 12202 as well, although that update ran without error. The unit is the transaction, not the statement.

Well-formed transactions and the path of states

An application program is a sequence of such units (p. 147), and each must be well-formed (p. 150): begin transaction; code for data manipulation (reads and writes); commit work or rollback work; no data manipulation; end transaction. Fig. 2 draws the template twice, once for each outcome.

application program begin transaction commit work end transaction begin transaction rollback work end transaction transaction T₁ reads and writes no data here transaction T₂ reads and writes
Fig. 2. "Application and Transaction" (p. 147) with the template of p. 150 written inside: a program is a sequence of transactions; each opens, reads and writes, ends its work with exactly one of commit work or rollback work, touches no data after that, and closes.

"commit work ends the transaction." It decides the outcome; end transaction closes the unit afterwards, and between the two the template allows "no data manipulation". The outcome is decided once: commit or rollback is executed "exactly once" (p. 146), never both.

Under the template, p. 150 draws the transaction as a path of states: \(S_0\) before it, a new state after each write W1, W2, …, and \(S_r\), the result. Only the two ends are meant to be seen from outside. With the hook's balances (the slides give none): \(S_0\) = (100, 25), \(S_1\) = (110, 25) after the credit, \(S_r\) = (110, 15) after the debit.

ACID, one letter at a time

"A transaction is a unit of work enjoying the following properties: Atomicity, Consistency, Isolation, Durability" (p. 188). The slides give each letter its own page (pp. 189–192); here each one meets the transfer.

Atomicity: all or nothing

"A transaction is an atomic transformation from the initial state to the final state" (p. 189). Atomic means indivisible: seen from outside, the database either jumps from \(S_0\) to \(S_r\) or stays in \(S_0\), and \(S_1\) — the money from nowhere — is never where it ends. The slide lists three possible behaviours:

  1. "Commit work: SUCCESS" — the database reaches \(S_r\) and stays there.
  2. "Rollback work or error prior to commit: UNDO" — every write already made is undone, the newest first, back to \(S_0\).
  3. "Fault after commit: REDO" — committed writes that may not have reached the disk are applied again, up to \(S_r\).

Under the chain of states the slide draws UNDO arrows back to \(S_0\) and a REDO arrow forward to \(S_r\). Make them happen.

Transaction stepper: the transfer of p. 149, with a crash button

The program of p. 149 runs one line per press of Next step. Top left, the two balances; top right, the log the DBMS keeps on disk; below, the chain of states of p. 189 with each state's balances above it. Rollback work aborts on the application's behalf, Crash now pulls the plug. The slider sets the starting balance of 42177 (12202 always starts at 100); moving it starts over.

  1. Keep 42177 at 25. Before pressing anything, predict the total of the two accounts in \(S_1\). Then press Next step twice and read the readout.
    What you should see

    135 instead of 125: the credit has created ten units that the debit has not yet taken away. \(S_1\) is the state the transaction must never leave behind; the next two tasks show how the DBMS makes sure.

  2. Press Start over, then Next step twice (you are in \(S_1\)) and Crash now. Predict where the restart takes 12202, then press Next step until the outcome settles.
    What you should see

    The balance of 12202 turns into "?" — memory is gone and the disk may hold either value — and the log has no commit record, so the restart undoes W1: 12202 is back to 100, the state is \(S_0\). This is the insight the widget is built for: whatever ran, nothing uncommitted survives a crash.

  3. Set 42177 to 5 and run the whole program with Next step. Before the decision line, predict the final balance of 12202.
    What you should see

    100. A = −5, the check executes rollback work, and the UNDO removes the debit and then the credit, although the credit itself was fine. Try 10 as well: A = 0 passes A>=0 and the transfer commits.

  4. Back at 25, run until the outcome reads "committed", then press Crash now. Predict: UNDO or REDO?
    What you should see

    REDO. Both balances become "?", but the log holds a commit record, so the restart reapplies W1 and W2 with their new values and ends in \(S_r\): 110 and 15. Durability is this REDO; a crash after end transaction gives the same answer.

How does a restarted server know what to undo or redo? The slides only name the mechanisms: "Abort-rollback-restart" under atomicity, "Recovery management" under durability (p. 193). The widget shows the textbook answer, background rather than slide material: a log. Every write is first recorded in a log on stable storage, with the old and the new value, before the changed balance itself may reach the disk; commit work appends a commit record. At restart, a transaction without a commit record is undone with the old values; one with a commit record is redone with the new ones.

Consistency: constraints in, constraints out

"The transaction satisfies the integrity constraints"; consequence: "If the initial state is consistent, Then the final state is also consistent" (p. 190). Only the two ends count. Under a rule "the total of all balances never changes", \(S_1\) would be illegal — 135 instead of 125 — and that is allowed, because \(S_1\) is neither the start nor the end.

Which constraints? Those declared in the schema are checked by the DBMS itself; p. 193 calls it "integrity checking of the DBMS". A rule nobody declared, like "no overdraft" here, is the application's job — the if (A>=0) of p. 149. Had the bank declared "balance at least zero" on the column, the DBMS would have refused the debit with an error, and that error before commit would have triggered the UNDO.

Isolation: no half-finished state on show

"A transaction is not affected by the behavior of other, concurrent transactions"; consequence: "Its intermediate states are not exposed" and “The ‘domino effect’ is avoided” (p. 191, over a picture of falling dominoes). The slide does not spell the dominoes out; Fig. 3 shows their standard reading, a cascade of rollbacks.

time T₁ T₂ T₃ writes 110 rollback reads 110 rollback! reads T₂ rollback! dominoes

Before: no isolation

time T₁ T₂ T₃ writes 110 rollback reads 100 commit reads T₂ commit S1 never seen

After: isolation

Fig. 3. The "domino effect" of p. 191. Left: T₂ reads the uncommitted 110, so when T₁ rolls back T₂ must roll back too, and T₃ with it. Right: T₂ sees only the committed 100, T₁'s rollback touches nobody else, and the others commit.

Without isolation, an interest transaction T₂ could read 110 from 12202 while the transfer T₁ sits in \(S_1\). If T₁ then rolls back, T₂ has paid interest on money that never existed and must roll back too — and so must T₃, which read T₂'s result. With isolation T₂ reads the committed 100, or waits for T₁ to finish, and the first domino never falls. Isolation does not mean one transaction at a time: they still run concurrently, kept apart by "concurrency control" (p. 193).

Durability: committed means forever

“The effect of a transaction that has successfully committed will last ‘forever’”, "Independently of any system fault" (p. 192). Once commit work has run, no crash may bring back 25 for account 42177. Durability is the promise and REDO is how a restarted server keeps it, which is why p. 193 files it under "recovery management". That slide is the one to learn as a table:

"Transaction Properties and Mechanisms" (p. 193), with what each mechanism does in the transfer.
PropertyMechanism (p. 193)In the transfer
AtomicityAbort-rollback-restart; Commit protocolsthe rollback of p. 149 cancels the credit too
ConsistencyIntegrity checking of the DBMSa declared constraint, such as the key AccNum, holds at the end
IsolationConcurrency controlnobody reads 110 before the commit
DurabilityRecovery managementa crash after the commit is answered with REDO

"Commit protocols" sit under atomicity because of the third setting of p. 145: when the two accounts live on two machines, both must commit or both must abort, and a protocol — two-phase commit is the classic one, background here — makes them agree. Lesson 5 shows what keeping machines in agreement costs once the network between them can fail.

ACID started with three letters. Jim Gray's 1981 paper "The Transaction Concept: Virtues and Limitations" defines a transaction by atomicity, consistency and durability; isolation joined, and the four-letter acronym was coined, in a 1983 survey by Haerder and Reuter.

Where ACID lives: OLTP, and why relational stayed

The definition slide calls a system that runs transactions "on behalf of multiple, concurrent applications" a Transactional System (OLTP), "As opposed to OLAP" (p. 146). OLTP is the bank counter: many short transactions like the transfer, each touching a few rows of current data. OLAP is the analyst: long read-only queries that scan and aggregate history, such as the average balance per branch over ten years. ACID was built for the first; the data warehouses of lesson 23 serve the second.

This is also the slides' answer to "Why didn't we change Relational?" (p. 205): it is "Consolidated", it is an "Integration platform" — the one database many applications share — and it is "Granting ACID properties!". Nothing in this half of the lesson is broken. What breaks is the size.

How big is big? Scaling up or scaling out

A slide of three lines (p. 158) sets the agenda: "How big is big?", "Not only scaling up", "Elasticity". The answer begins on p. 177 with two bullets in deliberate parallel:

“Adding data to a ‘traditional’ SQL system may degrade its performances.” When the machine "no longer performs as required, the solution is to buy a better machine (with more RAM, more cores and more disk)".

"Adding data to a Big Data solution may degrade its performances." When the machines "no longer performs as required, the solution is to add another machine".

Both degrade as data grows; only the remedy differs. Vertical scaling — scaling up — replaces the machine with a better one. Horizontal scaling — scaling out — adds a machine next to the ones you have. Fig. 4 is the picture to keep.

buy a better one commodity appliance exceptional

Scale up: replace the machine

only more commodity hardware one two four

Scale out: add machines

Fig. 4. The two remedies of p. 177. Scaling up throws the old machine away and buys the next class, until the classes run out. Scaling out keeps every machine and adds identical cheap ones — “‘only more’ commodity hardware” (p. 181).

Vertical scaling has a cost curve (p. 178): cost against data size, rising through "commodity hardware", then "appliance", then "exceptional hardware", each segment steeper than the one before. The slides put numbers on the first two classes:

A commodity server against an appliance, as pp. 179–180 print them.
Commodity hardware (p. 179)Appliance (p. 180): Oracle Exadata Database Machine X6-8
CPU8–32 cores576 cores
RAM16–64 GB24 TB
Disk1–3 TB360 TB of flash storage per rack
Network10 GE40 Gb/second InfiniBand

One appliance rack has 18 to 72 times the cores and 375 to 1,500 times the memory of one commodity server. On the slide's curve each class costs more per terabyte than the one below it, and after "exceptional hardware" there is nothing left to buy: the curve leaves the top of the chart.

Horizontal scaling (p. 181) is one straight line labelled “‘only more’ commodity hardware”: every further slice of data costs about one more cheap machine. The line does not start at zero; the slide leaves the gap unexplained, and the natural reading is the price of having a cluster at all — several machines, a network, the software and the people to run them.

Overlay the two (p. 182) and the chart splits: "Use vertically scalable solutions" on the left, where one machine is cheaper than any cluster; "Use horizontally scalable solutions" on the right, where the staircase has shot past the line. Around the crossing lies “The ‘grey area’” (p. 183), where neither is clearly cheaper and other reasons decide. The last slide of the set is the one to remember: “The ‘grey area’ is time dependent” (p. 184).

Scale-cost explorer: when does a cluster beat one machine?

Idealised curves drawn after pp. 178–184: the teal staircase is vertical scaling, the magenta line horizontal scaling in the chosen year, the faint lines the other three years, the grey band the grey area. As on p. 184, the size axis has one tick per factor of ten, the cost axis has no numbers and the lines are drawn straight: read them for their order and their crossing, not for prices. Where the staircase bends is the widget's assumption — where the slides' own disks run out, 3 TB for a commodity server (p. 179) and 360 TB for an Exadata rack (p. 180) — and it agrees with p. 184, which draws the bends below 10 TB and between 100 TB and 1 PB.

  1. Year 2006, data size 100 TB. Predict which way of scaling is cheaper, then read the readout.
    What you should see

    Vertical: one appliance. In 2006 the grey area sat near 10 PB, so 100 TB was a hundred times too small for a cluster to pay off.

  2. Keep 100 TB and move the year to "today?". Predict before you move it.
    What you should see

    Horizontal. The data did not change; the line did. The grey area slid from 10 PB through 1 PB and 100 TB to about 10 TB, and 100 TB crossed from one side to the other without growing a byte. That is the insight of the widget: "how big is big" is a moving target, not a size.

  3. Stay in 2013 and slide the data size from 1 TB to 10 PB while you watch "one machine that holds it". Where does the staircase bend, and what happens to the gap between the two curves after each bend?
    What you should see

    At 3 TB it leaves commodity hardware for appliances and at 360 TB appliances for exceptional hardware (the widget's thresholds). Each segment is steeper than the last while the horizontal line keeps one slope, so beyond the crossing the gap opens faster and faster: big data on one machine is not just dearer, it runs away.

Page 184 draws four lines of horizontal scaling, one per generation of distributed platforms. "Hadoop 2.x using clusters on premises (2006)" crosses the staircase near 10 PB, "Hadoop 2.x using cloud-based services (2010)" near 1 PB, "Spark 1.6 using cloud-based service (2013)" near 100 TB, and "Spark on HDInsight (today)?" near 10 TB. Each generation made a cluster cheaper to start and cheaper per terabyte — rented in the cloud instead of bought, with better software on top — so the line sank and the crossing slid left by a factor of ten each time.

"How big is big?" has no fixed answer: big starts where many cheap machines cost less than one good one, and on p. 184 that threshold fell a thousandfold, from about 10 PB to about 10 TB.

"Not only scaling up" also points the other way: what scales out can scale back in. Elasticity — the slide names it without a definition; the meaning comes from cloud computing — is adding machines when the load grows and releasing them when it falls, so that cost follows load. It comes naturally to horizontal scaling, where a machine is a unit you can rent for a month; nobody hands back half an appliance.

Split it, copy it: partitioning and replication

Spreading data over many machines takes two moves, and a section title of the slides names both: partitioning and replication. Both start from "the traditional tabular view of a database" (p. 152), where a table can be cut by columns or by rows.

AccNum Owner Branch AccNum Balance 12202 Rossi Milano 42177 Trenti Como 30411 Bianchi Milano 51876 Neri Como 12202 100 42177 25 30411 70 51876 5 node 1 node 2 AccNum in both

Vertical: by columns

AccNum Owner Branch Balance 12202 Rossi Milano 100 30411 Bianchi Milano 70 42177 Trenti Como 25 51876 Neri Como 5 node 1 node 2 split by Branch

Horizontal: by rows

Fig. 5. The two cuts of p. 152 on a four-row account table. Vertical partitioning gives each node some columns, and the key travels with both pieces; horizontal partitioning gives each node some whole rows — here by branch — and every piece keeps all the columns.

Vertical partitioning gives each piece a group of columns, with the key AccNum repeated so that rows can be joined back. Horizontal partitioning gives each piece a group of whole rows with the same columns — here the Milano accounts on one node and the Como accounts on the other. A rule decides which row goes where; later lessons call its input the shard key (MongoDB, lesson 16) and the partition key (Cassandra, lesson 21).

Partitioning — "Aim: scalability, distribution." — "splits the data in the database and partitions pieces of it to different storage nodes" (p. 153): one database of three layers A, B, C, an arrow "SPLIT", three separate databases. The same slide adds two sentences that pull in different directions: "Databases can be sharded horizontally (by rows) or vertically (by columns)" and "See also: Sharding (as horizontal partitioning)".

"Sharding and partitioning are the same thing." Partitioning is the general move, by rows or by columns. Sharding is its horizontal form: whole rows spread over nodes, as the slide's own last line says. The sentence before it uses "sharded" loosely for "partitioned". Know both sentences as printed — the exam is matched against the slides — and in your own answers keep "sharding" for rows on different machines.

Replication — "Aim: fault-tolerance, backup" (p. 154) — copies instead of splitting: one database, an arrow "COPY", two identical databases. The sentence printed under the aim needs a correction.

"Partitioning + Replication — Possible?" asks p. 155, and its picture answers: copy the A/B/C database into two identical databases, then split each copy into A, B and C — six nodes, every piece on two of them. Splitting first and copying each piece gives the same layout, and real systems describe it that way: a number of shards, each stored a fixed number of times, its replication factor (the term of later lessons, not of these slides). Then the slides weigh the two moves (p. 156):

"Pros / Cons of Each" (p. 156), cell by cell as printed.
PartitioningReplication
ProsFast data writing / reading. Low memory overhead.Fast data reading. High data reliability.
ConsPotential data lossHigh network overhead. High memory overhead.

Every cell has a mechanism behind it. A partitioned node holds and serves only its piece, so the work spreads and each datum is stored once — but a dead node takes its piece with it. A replicated datum can be read from any copy and survives while one copy does — but every write must reach every copy, and \(N\) copies take \(N\) times the space. The sandbox shows both columns at once.

Partition and replicate: six blocks, k shards, N copies

A database of six blocks. Choose into how many shards \(k\) to split it and how many copies \(N\) of each shard to keep; every copy sits on its own node, so there are \(k \times N\) nodes, numbered copy by copy. Solid squares are first copies, dashed squares replicas. Kill a node fails the lowest-numbered running node; tap or click a node (or focus it and press Enter) to fail or restart that one. The client's arrows show where one write of block 1 must go. It starts on the layout of p. 155.

  1. Set \(k = 3\) and \(N = 1\). Predict how many blocks a single failure costs, then press Kill a node.
    What you should see

    Two: node 1 was the only home of blocks 1 and 2. Partitioning alone is fast and lean — storage × 1, one message per write — but every node is a single point of loss: the table's "potential data loss", about 3 % per period in the readout.

  2. Now \(N = 2\) (six nodes). Predict how many nodes can fail without losing a block. Press Kill a node three times, then once more.
    What you should see

    It depends on which ones. Three nodes — a whole copy — fail and nothing is lost; the fourth kill takes node 4, the second home of blocks 1 and 2, and they are gone. Now restart all and click nodes 1 and 4 directly: two failures suffice when they are the wrong two. Data is lost only when every copy of a shard is down — the insight of the sandbox — so \(N\) copies guarantee that any \(N - 1\) failures are survived: here, one.

  3. Compare \(k = 1\), \(N = 3\) with \(k = 3\), \(N = 1\). Predict which stores more and which sends more messages per write.
    What you should see

    \(k = 1\), \(N = 3\): 18 blocks stored and three messages per write, but a loss chance of about one in a million — the replication column of the table. \(k = 3\), \(N = 1\): six blocks, one message, 3 % — the partitioning column. \(k = 3\), \(N = 3\) spreads the work and keeps the safety, and pays storage × 3.

How much safer is "safer"? The slides stop at the table. A back-of-envelope model, not from the slides, gives numbers under one assumption: nodes fail independently, each with probability \(p\).

  1. A shard is lost only if all \(N\) of its copies are on failed nodes. With independent failures: \[ P(\text{shard lost}) = p^N . \]

  2. So a shard survives with probability \(1 - p^N\), and all \(k\) shards survive together — they sit on different nodes, so their fates are independent too — with \[ (1 - p^N)^k . \]

  3. Losing something is the complement: \[ P(\text{data lost}) = 1 - (1 - p^N)^k . \]

  4. Partitioning alone, \(N = 1\): \(1 - (1 - p)^k\) grows with \(k\), about \(k\) times \(p\). With \(p = 0.01\) and \(k = 3\) it is 2.97 %: more pieces, more ways to lose one — the table's "potential data loss".

  5. Replication alone, \(k = 1\): \(p^N\) collapses, 0.01, then 0.0001, then 0.000001 for \(N\) = 1, 2, 3. Both, \(k = N = 3\): about 3 in a million, for three times the storage.

Independence is the assumption behind Bernoulli trials in statistics, and it is the weak point: a fire or a power cut takes a whole rack down at once. That is why the HDFS slides of lesson 31 put the "Second replica on a remote rack" (p. 857). And one cost is missing from the table altogether: the copies must agree. A write does not reach every copy at the same instant, so for a moment two copies of the same row can differ — remember that for the last section.

Getting data in: ingestion and wrangling

The "Data Architecture Concepts" deck closes its scaling section at the other end of the pipe (pp. 157–160, "Scale and Ingestion"): before data can be split and copied, it has to arrive and become usable. Data ingestion is "The process of importing, transferring and loading data for storage and later use"; "It involves loading data from a variety of sources" and "can involve altering and modification of individual files to fit into a format that optimizes the storage" (p. 159).

The slide's example is pure engineering: "in Big Data small files are concatenated to form files of 100s of MBs and large files are broken down in files of 100s of MB." Hundreds of megabytes is what the distributed file system of lesson 31 wants — "Typically 100MB or more per file", "Millions as opposed to billions of files" (p. 847) — because one server, the NameNode, holds the record of every file: "The entire metadata is in main memory" (p. 855). Around a "bus" that collects the sources, "Integration services" do "Transportation management, message routing, message brokering, transaction management, security, and transformation" — the top band of Fig. 6.

Data ingestion (p. 159) source #1 source #2 […] source #n bus Integration services routing, brokering, transformation, … files of 100s of MB Data wrangling (p. 160) Understand Cleanse Augment Shape
Fig. 6. The two bands at the bottom of a big-data architecture. Top, ingestion as p. 159 draws it: sources pour into a bus, integration services route and transform. Bottom, the four boxes of p. 160 laid out as a pipeline.

Data wrangling turns what arrived into something worth analysing: “cleansing ‘raw’ data” so that it "can be analysed to generate valid actionable insights", by "understanding, cleansing, augmenting and shaping data", with the result "in the best format (e.g., columnar) for the analysis to perform" (p. 160). The four boxes: understand which types of data there are (qualitative, quantitative, categorical), whether there are outliers, whether data is missing; cleanse — remove outliers, add missing values, transform quantitative values into categorical ones; augment — aggregate data within one source, add data from other sources by exact or fuzzy matches; shape — give the data the best format for the analysis.

If this sounds like the preprocessing done before training a neural network, it is — done once for a whole company and kept running as a pipeline. Lesson 4 places both bands in the architecture of a big-data system; lesson 33 opens the ingestion tools and lessons 35–37 the wrangling.

Back to the missing 10

Now the hook. Who has the extra 10 when the server comes back? Nobody. The power failed before commit work, so the log holds the credit and no commit record: the restart undoes the credit, 12202 is back to 100, and the two accounts hold 125 again. Had the power failed one line after the commit, the restart would redo both writes and the transfer would stand at 110 and 15, whatever had reached the disk. \(S_1\) is never an outcome and never on show — atomicity and isolation — and a committed outcome stays — durability.

Why, then, give up a machine that keeps such promises? Not because of the promises; because of the machine. Its staircase runs out, and the size at which a cluster wins kept falling, from about 10 PB to about 10 TB on p. 184. Beyond it the data is partitioned and replicated — and the hook's question comes back in a new form.

commit copy 1 12202 110 node A copying copy 2 12202 100 node B read client 100 or 110?
Fig. 7. One account, two copies. The transfer has committed on node A; node B has not received the write yet. A client reading node B now meets the hook's question again: is the balance 100 or 110?

Which copy is right — and when 12202 and 42177 sit on different shards, who makes sure that both writes happen or neither? That is the third setting of p. 145, "Distributed systems". Lesson 5 takes up the first question: the CAP theorem, and the BASE properties that many distributed stores offer instead of ACID.

Exam-style questions

Theory questions in the form of the written exam — open answers of a few sentences, and closed questions (multiple choice, true or false) where a wrong answer may carry a penalty — plus two small exercises: one on the slides' own transaction, one on the arithmetic of partitioning and replication.

Define a transaction. Which commands delimit it, which commands decide its outcome, and when is a transaction well-formed?

Show model answer

A transaction is an elementary unit of work performed by an application. It is encapsulated between begin transaction (bot) and end transaction (eot), and within it exactly one of commit work (commit) or rollback work (abort) is executed. A transaction is well-formed when it has the structure: begin transaction; code for data manipulation (reads and writes); commit work or rollback work; no data manipulation; end transaction — that is, no read or write happens after the outcome has been decided. A system that provides the definition and execution of transactions on behalf of multiple, concurrent applications is a transactional system (OLTP), as opposed to OLAP.

A complete answer has three parts: the slide's definition, "exactly once" for commit or rollback, and the "no data manipulation" step between the outcome and end transaction. The OLTP sentence shows you read p. 146 to the end.

List the ACID properties of a transaction. For each one, give a one-sentence definition and the mechanism the DBMS uses to guarantee it.

Show model answer

Atomicity: a transaction is an atomic transformation from the initial to the final state — all of its effects or none; commit work means success, rollback work or an error before the commit means UNDO, a fault after the commit means REDO. Mechanisms: abort-rollback-restart and commit protocols. Consistency: the transaction satisfies the integrity constraints, so if the initial state is consistent the final state is consistent too (intermediate states may violate them). Mechanism: integrity checking of the DBMS. Isolation: a transaction is not affected by the behaviour of other, concurrent transactions; its intermediate states are not exposed, so the domino effect of cascading rollbacks is avoided. Mechanism: concurrency control. Durability: the effects of a committed transaction last forever, independently of any system fault. Mechanism: recovery management.

The pairing of p. 193 fits a closed question just as well: learn it as a table. An easy slip is to put "commit protocols" under durability; the slide puts them under atomicity.

True or false: when a system fault happens after a transaction has executed commit work, the DBMS undoes the transaction's writes at restart.

  • True That is the rule for a failure before the commit. After the commit the slide prescribes REDO: the committed effects must last.
  • False "Fault after commit: REDO" (p. 189): the writes are applied again, so the committed state survives — durability.
Show model answer

False. A fault after the commit requires REDO, not UNDO (p. 189): the effects of a committed transaction must survive any system fault (durability, p. 192). UNDO applies to rollback work and to errors before the commit.

With a possible penalty, answer only if you can say which side of the commit the fault is on: that single fact decides between UNDO and REDO.

Explain the difference between vertical and horizontal scalability, and say which one traditional SQL systems use and which one Big Data solutions use. What is the "grey area", and why is it time dependent?

Show model answer

In both kinds of system adding data may degrade performance; the difference is the remedy. Vertical scalability (scaling up), used by traditional SQL systems, replaces the machine with a better one, with more RAM, more cores and more disk; its cost rises in a convex staircase from commodity hardware to appliances (for example an Oracle Exadata X6-8 rack: 576 cores, 24 TB of RAM) to exceptional hardware, and then there is nothing bigger to buy. Horizontal scalability (scaling out), used by Big Data solutions, adds another machine; its cost is a straight line of "only more" commodity hardware with a fixed starting cost. So for small data one machine is cheaper, for big data the cluster is. The grey area is the band of data sizes around the crossing of the two cost curves, where neither is clearly cheaper. It is time dependent because distributed platforms keep getting cheaper and easier (Hadoop on premises, Hadoop in the cloud, Spark in the cloud, Spark on a managed service), so the horizontal line sinks and the crossing moves to smaller sizes: roughly 10 PB, 1 PB, 100 TB and 10 TB on the slide.

A complete answer names the remedy as the difference (not "SQL is slow"), the two shapes of cost and the drift to the left. Quote the trend rather than the years: the slide's years and version numbers do not match.

Compare data partitioning and replication: the aim of each, one advantage and one disadvantage of each, and whether the two can be combined.

Show model answer

Partitioning splits the data and places the pieces on different storage nodes, horizontally by rows (sharding) or vertically by columns; its aim is scalability and distribution. Pros: fast data writing and reading, because each node handles only its piece, and low memory overhead, because each datum is stored once. Con: potential data loss, because a failed node takes its piece with it. Replication keeps copies of the same data on several nodes; its aim is fault tolerance and backup. Pros: fast data reading, because any copy can answer, and high data reliability. Cons: high network overhead, because every write must reach every copy, and high memory overhead, because every copy costs storage. The two combine: split the data into partitions and store each partition on several nodes (or copy, then split), so that every piece survives the failure of a node — the usual layout of distributed databases.

Half of the answer is the four cells of the table on p. 156, the other half is the "because" behind each cell. If you use the slide's definition of replication ("the entire database across all nodes"), add that real systems copy each partition a fixed number of times.

A bank stores its accounts in the table Account(AccNum, Balance). Account 12202 holds 100 and account 42177 holds 5. The following transaction (the slides' "Example with Alternative", p. 149) runs to its end without failures. Which balances does the database hold after end transaction?

begin transaction;
update Account
  set Balance = Balance + 10 where AccNum = 12202;
update Account
  set Balance = Balance - 10 where AccNum = 42177;
select Balance into A from Account
  where AccNum = 42177;
if (A>=0) then commit work
          else rollback work;
end transaction;
  • 12202: 110, 42177: −5 That is the state after the two updates. A = −5 makes the program execute rollback work, so this state is never committed.
  • 12202: 100, 42177: 5 The check fails, rollback work undoes both updates — the credit too — and the database is back in its initial state.
  • 12202: 110, 42177: 5 Only the debit undone? A rollback undoes the whole transaction, not its last statement.
  • 12202: 100, 42177: −5 The debit is the update that broke the rule; it is the first one the UNDO removes.
Show model answer

12202 holds 100 and 42177 holds 5. After the two updates A = 5 − 10 = −5, the condition A >= 0 is false, the program executes rollback work, and the DBMS undoes both writes (atomicity): the database returns to its initial state.

The trap is the credit: it ran without error, yet the rollback cancels it. The third task of the transaction stepper rehearses exactly this run.

A hospital keeps its patient records in a database of 2 TB. The database is horizontally partitioned into 4 shards of equal size, and every shard is stored with a replication factor of 3, each copy on a different node. How much data does the cluster store in total?

  • 2 TB Partitioning alone would keep the total at 2 TB, but replication stores every shard three times.
  • 6 TB: 0.5 TB on each of 12 nodes Each shard holds 2 / 4 = 0.5 TB and is stored 3 times on its own nodes: 4 × 3 × 0.5 = 6 TB, that is 3 × 2 TB.
  • 8 TB That multiplies the database by the number of shards; the shards are pieces of the 2 TB, not copies of it.
  • 24 TB That multiplies by the shards and by the copies. Only the replication factor multiplies the data.
Show model answer

6 TB. Each shard holds 2 / 4 = 0.5 TB and is stored 3 times, so 4 × 3 = 12 nodes hold 0.5 TB each: 12 × 0.5 = 6 TB. The number of shards does not change the total; only the replication factor does: total storage = replication factor × database size = 3 × 2 TB.

Partitioning spreads the data, replication multiplies it: the "low memory overhead" and "high memory overhead" cells of p. 156 in one number. The usual slip is to multiply by the number of shards as well.

Check yourself

The power fails right after the first update of the transfer: 12202 has been credited, 42177 not yet debited. After the restart the two accounts hold…

  • 110 and 25, because the credit was written and written data stays Durability protects committed writes only. This one was not committed, so it is undone.
  • 100 and 25: the credit is undone An error prior to commit means UNDO back to \(S_0\) (p. 189): atomicity.
  • 110 and 15, because the restart finishes the transfer REDO replays committed transactions only; a restart never completes a transaction on the application's behalf.
  • whatever happened to reach the disk before the crash That is exactly what recovery prevents: the log tells the restart what to undo, whatever reached the disk.

During the transfer the database passes through \(S_1\): 12202 credited, 42177 not yet debited. Which statements are true? Select all that apply.

  • It may break a rule such as "the total of all balances is constant" without breaking ACID Consistency is required of the initial and the final state only (p. 190).
  • Concurrent transactions cannot read 110 for 12202 while the transfer runs Isolation: "Its intermediate states are not exposed" (p. 191).
  • If the server crashes now, \(S_1\) is what you find after the restart A fault before the commit leads to UNDO, back to \(S_0\).
  • A rollback from here goes back one state only, to the state before the last write A rollback undoes every write of the transaction, back to \(S_0\).

\(S_1\) exists, but only inside the transaction: nobody sees it, and no crash leaves it behind.

Two transactions add interest to account 12202 at the same moment. Which property, and which mechanism of p. 193, makes the result the same as if they had run one after the other?

  • Atomicity — commit protocols Atomicity is all-or-nothing for one transaction; it says nothing about two transactions interleaving.
  • Isolation — concurrency control A transaction "is not affected by the behavior of other, concurrent transactions" (p. 191); concurrency control enforces it.
  • Durability — recovery management Durability keeps committed effects through a fault; there is no fault here.
  • Consistency — integrity checking of the DBMS Each transaction alone can be consistent and the interleaving still wrong: a lost update is an isolation problem.

A bank splits its accounts by branch over four servers and keeps no copies. One server's disk is destroyed. In the terms of the table on p. 156, what happened?

  • The "potential data loss" of partitioning became real: one branch's accounts are gone Each account was stored once, and its only home died.
  • Nothing, since partitioning gives high data reliability High data reliability is the pro of replication, not of partitioning.
  • Reads became slower, but nothing is lost With no copies there is nowhere else to read those accounts from.
  • The other three servers rebuild the lost rows Rebuilding needs a copy, and there is none.

You raise the replication factor from 1 to 3 and keep the same shards. What gets worse? Select all that apply.

  • The storage needed Three copies take three times the space: the table's "high memory overhead".
  • The network traffic of every write Each write must reach three nodes: "high network overhead".
  • The speed of reads Reads get faster: any of the three copies can answer.
  • The chance of losing data It falls, from \(p\) to about \(p^3\) per shard.

On the 2006 line of p. 184 (Hadoop on premises), which choice was cheaper for a 300 TB database?

  • One bigger machine: vertical scaling In 2006 the grey area sat near 10 PB, so 300 TB was well on the vertical side.
  • A cluster of commodity machines: horizontal scaling That holds on the 2013 line and later; in 2006 the cluster paid off only near 10 PB.
  • Both about the same: 300 TB was in the grey area The 2006 grey area is around 10 PB, more than thirty times larger.

A web shop needs ten servers in December and three in July. Which word of p. 158 names renting ten for December and handing seven back in January?

  • Elasticity Scaling out and back in with the load, so that the cost follows it.
  • Vertical scaling Vertical scaling replaces one machine with a bigger one; it never hands machines back.
  • Replication Replication copies data for reliability; it does not follow the load.
  • Partitioning Partitioning decides where data goes, not how many machines you rent.

Key take-aways

What to watch and read