Archive for the ‘Database’ Category

More About Data Models

Friday, October 8th, 2010
news and informationbusiness,health,entertainment,technology automotive,business,crime,health,life,politics,science,technology,travel

Reading the comments on my earlier posts, as well as other posts in other blogs, shows me that there is still some confusion about the relational model. I’d like to clear some of this up.

I’m going to stop talking about the “network” or “CODASYL” model. I don’t know its details and history. I’ll just compare the relational model with the hierarchical model, as seen in, e.g. IBM’s IMS.

Object-Oriented Database Systems

It’s ironic that I’m being looked at as some kind of “relational fanboy”. The reason that I first learned about database systems was to build an object-oriented database system (for and in Common Lisp,) at Symbolics. It was called Statice and the first version was completed in 1988.

After that, Symbolics refused to let us port Statice to other hardware. Meanwhile, the object-oriented database system idea was picking up a lot of “traction”. A group of seven of us formed Object Design, where we built the best and most successful (if I may say so) object-oriented database system (this time in C++, later in Java).

I am not a relational model fanboy in the least! The point of my recent blog postings is to explain why Object Design kept getting pelted with rotten tomatoes by real the relational database fanboys. I call them “fanboys” because their devotion to the relational model was often blind. Either they did not understand what problem the relational model was intended to solve, or they didn’t understand why that wasn’t the problem we were addressing.

Despite the fact that I’m an object-oriented database guy through and through, I can still understand the purpose and benefits of the relational model Because these issues are arising in the “NoSQL” world, I want to try to lay out an explanation, especially to show what a data model is, and how it’s different from transaction and scalability issues.

What a Data Model Is

The a data model is a way to model some facts about the real world that you care about. The best book I know of about modelling data is “Data and Reality”, by William Kent, then of Hewlett-Packard. It was written in 1978 but it’s so fundamental that nothing has changed. Quite a lot of real-world facts can be modeled with normalized relational models. People can debate over whether such a representation is natural, unnatural, easy or hard to think about. If you want to make a whole new data model, read Kent’s book before you get too far.

The model you choose to use says absolutely nothing per se about indexes, how much time certain operations take, transactions, eventual consistency, or cloud computing. Implementing a database system based on a certain data model is another thing entirely, which I’ll be discussing in later posts.

Schema Evolution

Does the relational model, in and of itself, say anything about taking existing data, and changing the relational schema so that the facts in the original database are faithfully represented in the new database? I’m not 100% sure, but I don’t think so. I think the relational model does not talk about schema evolution, just about how to represent things as of now.

(Believe me, I know about schema evolution in relational database systems. I know a lot more than I want to know. My co-workers have been through a lot of pain. As my son says, “Sad face!” To be fair, it wasn’t easy in ObjectStore either: we did it but it was hard.)

Whether a schema is “sparse” can mean one of two things. First, it can mean that the model is relational but, as an implementation convenience, we don’t store certain things that we don’t need in certain places, because the columns and rows can be defaulted, or compressed out. In that sense, it’s just an implementation technique that has nothing to do with the model.

Second, they can mean that there is a flexible schema. For example, an individual document in MongoDB can have a new attribute name that was never used anywhere else. That is not relational.

C. J. Date’s Book Title

In the previous blog posts, I did not mean to imply that C. J. Date thinks that all database systems use the relational model. All I was trying to do was point out, as a sort of footnote, that his book does not have the word “Relational” in its title. He just takes it for granted. In my earlier post, Why Relational Databases, Anyway?, my point was that many people take for granted that the relational model is always right for every single data storage need, and anything that is not relational (such as object-oriented database systems) are inherently misguided. That is not the case.

Hierarchical versus Relational: Anticipating New Queries

Consider the standard example of Company-Division-Employee, where each company has many divisions and each division has many employees. In a normalized relational representation, there is a table called “Company” with one row per for each company being modeled. There is a “Division” table with one row per division being modeled, and a column that is a foreign key to the row of Company that represents this division’s company. The next level, Employee, is analogous.

The data model is not hierarchical. You could say that the particular schema, when looked at in one particular way, acts hierarchically. But the schema I’m describing, in and of itself, viewed purely from the relational model (ignoring implementation details) can model things that don’t look hierarchical whatsoever.

In the old-style hierarchical model, in order to say “add up the salaries of every employee”, your query has to start by saying “for all the companies…”. In the relational model, you don’t do that. It’s much simpler. You just go to the Employee table, and add up the values of the Salary column. You can ignore that hierarchy entirely! That’s the key benefit of the relational model.

Data Independence, Again

This is what I was saying in the previous blog post: The Problem That Relational Databases Solve. In this example, if we suddenly find that we need to get the sum of all the employee salaries, the data model makes that easy. The relational model, with normalization, is doing its best to anticipate queries that might come with a new application, and make them easy and natural. (Remember, the mind set is that applications come and go, but data stays for a long time.) That is what data independence is for.

If you or I had to make a data model with these properties, and we had never seen the relational model before, would we have come up with the model, just as E. F. Codd did? I don’t know about you, but I doubt I would have. I think it’s a novel and brilliant idea, to solve the particular problem that it was designed to solve.

Does NoSQL Mean We Don’t Like the Relational Model?

The fact that the “NoSQL” database systems are flourishing does not, in and of itself, mean that people are intentionally turning away from the relational model. After all, if someone primarily wanted a different model, they could just build a conventional centralized DBMS that that model. This would have nothing to do with scaling and transactions. ObjectStore and many other object-oriented databases did that, and those are not the only examples.

It’s one thing to say that giving up the relational model is a cost that is more than balanced by the benefits of a new type data store. It’s quite another to say that the relational model itself is undesirable in all cases. One could feel either way, but I think it’s helpful to distinguish these two issues.

Coming Soon

What about using the actual DBMS products that you can buy? What are the consequences of denormalizing, of using BLOBs/CLOBs, and so on?

The Problem That Relational Databases Solve

Monday, October 4th, 2010
news and informationbusiness,health,entertainment,technology automotive,business,crime,health,life,politics,science,technology,travel

As I said last time, “data independence” is a clean separation between applications and data. What problem does it solve, and how does it solve it?

In my previous post, I talked about the people who take the relational model for granted. Where did it first come from, and why?

(Most of this essay is taken or paraphrased from perhaps the best expositor of the relational concept, C. J. Date. I am grateful to Prof. Michael Stonebraker for his comments on an earlier draft. As always, any errors are mine alone.)

Data Independence

For a large enterprise, there is a very large body of crucial information. These are the “crown jewels” of the information technology part of the company. This information lasts for the whole lifetime of the enterprise. But applications come and go, like migrating birds. The next application to come along might want access data in a different way, for important reasons. The structure of the database structure must adapt well to these new and changing demands.

With the older styles of data organization (called “network” or “CODASYL”, roughly speaking), sometimes the new application could not be done efficiently. Many times, for all practical purposes, it was impossible to write the application with acceptable performance. You can find the details of this in many books, but to give just one analogy: suppose you have a program with nested loops. In many cases (not 2D arrays), it’s pretty obvious which loop ought to be on the outside. Well, imagine if you forced to do it the other way, even if it made the program very much slower. And that’s just one example.

To solve this, we want data organization that can do two things. First, give every application a view of the database that doesn’t change over time, so that the application keeps working. Second, have a way to change the physical organization of the data without changing any of the software that uses the database system, which may be needed to make the new applications faster without hurting the old ones, or not hurting enough that it matters much. This is called “data independence.”

The Relational Model

A novel and effective solution to data independence, the “relational”, was created by E. F. Codd, in 1970. By representing data in relations, in normalized form, you can solve both of the above problems. I won’t go over all that here; I recommend “An Introduction to Database Systems” by C. J. Date.

(By the way, notice that the name of the book isn’t “… to Relational Database Systems,” even though that’s what the book is. Why bother with a superlative adjective, when “everybody knows” that all database systems, other than ancient ones, are relational?)

The relational model, as an abstract concept, is an excellent and brilliant solution to the data independence problem. Later we’ll see that that is not the only problem for which people want to store data. But in the next post, I’ll look into how well actual relational database systems implement the concept.

Postscript: I am only talking here about the way data is modeled. I’ll talk about transaction issues later.)

Why Relational Databases, Anyway?

Wednesday, September 22nd, 2010
news and informationbusiness,health,entertainment,technology automotive,business,crime,health,life,politics,science,technology,travel

Calling a data store “NoSQL” is not quite right. Insofar as they mean “no SQL can be found here”, what they are really saying is that it’s not a relational database. (More properly, a relational database management system.) SQL, per se, isn’t the only relational query language there ever was. It’s just the one that caught on and “got traction”.

For example, one of the early relational DBMS’s was called Ingres, done by a team at U.C. Berkeley lead by Michael Stonebraker. It had a query language called QUEL, which was a competitor of SQL (then called SEQUEL). That could have been the query language used for relational database systems today.

If memory serves, QUEL was cleaner than SQL. QUEL was more directly modeled on the relational calculus, whereas SQL is sort of a hybrid of the relational algebra and the relational calculus, which is quite different in structure. This is not exactly my area of expertise, so I’ll stop here, but the point is that the data modes of “NoSQL” systems are really no relational model database systems.

There’s a famous saying: “fish are not aware of water”. A whole generation of software engineers swam in the water of relational database systems, having seen nothing else, with no basis for comparison. To say “database system” meant “relational database system”.

They were so widely accepted that anything else was viewed with suspicion if not outright contempt. Back at Object Design, we made an object-oriented database system called ObjectStore We took a lot of criticism in news groups and such from relational model fans, but they often expressed themselves poorly, e.g. “well, everybody knows that relational is good and anything else is bad”. It’s rather hard to answer the criticism in that form. What was really going on here?

As with most things in the software world, the relational model is a particular tool to solve a particular problem. The relational model solved a problem that was very important in its time, and is still important now in some contexts. The problem is to create a clean layering between applications and database systems, which is called “Data Independence.” More about this in a future post.

NoSQL Storage Systems Never Violate ACID. Never? Well, Hardly Ever!

Tuesday, September 7th, 2010
news and informationbusiness,health,entertainment,technology automotive,business,crime,health,life,politics,science,technology,travel

Everybody agrees that the new “NoSQL” storage systems “aren’t ACID”, or “don’t have transactions”.  This is true <i>in a sense</i>, but without knowing the sense, it doesn’t tell you much.

In one sense, they <i>do</i> have transactions that are limited to having one operation per transaction.  One operation could mean reading, writing, incrementing, or doubling the value associated with a particular key.  For example, look at an “insert” operation in a key/value store.  An operations acts on only one data object.  Are these single-operation transactions ACID?  Let’s check each criterion:

A means “atomic”: either all the operations happen, or none of them happens.  Well, there’s only one operation.  The key-value store <i>does</i> guarantee that either the insert happens, or it doesn’t.  So the transaction atomic.

C means “consistent”.  In relational database systems, people use this to mean that various interesting consistency guarantees are maintained.  But here, we don’t have to worry about such things as referential integrity, since there are no references to have integrity; that is, there are no foreign keys.  So it’s consistent.

I means “isolated”: concurrency is never seen by the application.  The system behaves as if each operation happened at a particular, distinct moment in time.  The key-value stores all make this guarantee.

D means “durable”: before the application is told that the transaction has been completed successfully (i.e. committed), any side-effects it does are in stable storage so that if a node stops (such as a crash of a process or a whole node) won’t lose the results of the side-effects.  Here, a transaction is only one operation, but that doesn’t change anything: the system does provide “durability”.  (Some systems might cheat by not actually forcing data to stable storage, but we’re not talking about those.)

So it appears to be ACID!  OK, something has <i>got</i> to be wrong here, right?

Right.  Where I tried to pull the wool over your eyes is the definition of “C”.  “C” doesn’t just mean conforming to the databases integrity constraints.  It means that the system returns the correct answer! That is, response to any operation is consistent with some state that the database could be in.  There’s more than one such state when there are concurrent operations going on, which might be ordered in more than one way, depending on how the concurrency system works.  So it’s clearer to think of “C” as meaning “correct”.  (In the famous Gilbert and Lynch paper that “proves the CAP theorem”, that’s what they mean by “C”.)

The “NoSQL” storage systems are guaranteed return the correct answer <i>only</i>if there are no partitions in the network.  But if there are (or were, e.g. at write time) partitions, they can return things like “two replicas say the value is X, but another replica says that the answer is Y”, and the application has to try to make sense of and cope with that.  That is <i>not</i> “C”.  This is usually called “eventually consistency”: if the partitions were to eventually heal and the system deferred accepting new operations until all the in-progress operations finished, and something went over the whole database to fix up any inconsistencies that happened during writes, then the system would become fully consistent, and would be behave correctly until the next partition.

that there are at least two nodes that cannot send messages between each other.  It’s important to know that if a node in your your system is down, that’s considered a partition: it’s as if this node were disconnected from the network.

The “NoSQL” systems are ACID, as long as you accept that a transaction can only perform one operation, in the sense that the only thing that gets in the way of being ACID is when there are network partitions and the system is called upon to perform operations while the partition is still there.

“Partition” is a somewhat slippery concept that I will examine in an upcoming separate essay.  But the basic ides is that a it means that there are at least two nodes that cannot send messages between them.  It’s important to know that if a node in your your system is down, that’s considered a partition: it’s as if this node were disconnected from the network.

This also shows that the name “NoSQL” doesn’t explain everything that’s important about these systems.  But you can’t pack a whole lot into a short, punchy name, so I’m not really complaining.  ( do the same thing with the names of my blog essays; <i>mea culpa<i>.  You just have to keep in mind that the lack of SQL is not the only important thing.

What Does the Proof of the “CAP theorem” Mean?

Monday, July 12th, 2010
news and informationbusiness,health,entertainment,technology automotive,business,crime,health,life,politics,science,technology,travel

Several years back, Eric Brewer of U.C. Berkeley presented the “CAP conjecture”, which he explained in these slides from his keynote speech at the PODC conference in 2004. The conjecture says that a system cannot be consistent, available, and partition-tolerant; that is, it can have two of these properties, but not all three. This idea has been very influential.

Seth Gilbert and Nancy Lynch, of MIT, in 2002, wrote a now-famous paper called “Brewer’s Conjecture and the Feasibility of Consistent Available Partition-Tolerant Web Services”. It is widely said that this paper proves the conjecture, which is now considered a theorem. Gilbert and Lynch clearly proved something, but what does the proof mean by “consistency”, “availability”, and “partition-tolerance”?

Many people refer to the proof, but not all of them have actually read the paper, thinking that it’s all obvious. I wasn’t so sure, and wanted to get to the bottom of it. There’s something about my personality that drives me to look at things all the way down to the details before I feel I understand. (This is not always a good thing: I sometimes lose track of what I originally intended to do, as I “dive down a rat-hole”, wasting time.) For at least a year, I have wanted to really figure this out.

A week ago, I came across a blog entry called “Availability and Partition Tolerance” by Jeff Darcy. You can’t imagine how happy I was to find someone who agreed that there is confusion about the terms, and that they need to be clarified. Reading Jeff’s post inspired me to finally read Gilbert and Lynch’s paper carefully and write these comments.

I had an extensive email conversation with Jeff, without whose help I could not have written this. I am very grateful for his generous assistance. I also thank Seth Gilbert for helping to clarify his paper for me. I am solely responsible for all mistakes.

I will now explain it all for you. First I’ll lay out the basic concepts and terminology. Then I’ll discuss what “C”, “A”, and “P” mean, and the “CAP theorem”. Next I’ll discuss “weak consistency”, and summarize the meaning of the proof for practical purposes.

Basic Concepts

The paper has terminology and axioms that must be laid out before the proof can be presented.

A distributed system is built of “nodes” (computers), which can (attempt to) send messages to each other over a network. But the network is not entirely reliable. There is no bound on how long a message might take to arrive. This implies that a message might “get lost”, which is effectively the same as taking an extremely long time to arrive. If a node sends a message (and does not see an acknowledgment), it has no way to know whether the message was received and processed or not, because either the request or the response might have been lost.

There are “objects”, which are abstract resources that reside on nodes. Objects can perform “operations” on other objects. Operations are synchronous: some thread issues a request and expects a response. Operations do not request other operations, so they do not do any messaging themselves.

There can be replicas of an object on more than one node, but for the most part that doesn’t affect the following discussion. An operation could “read X and return the value”, “write X”, “add X to the beginning of a queue”, etc. I’ll just say “read” for an operation that has no side-effects and returns some part of the state of the object, and “write” to mean an operation that performs side-effects.

A “client” is a thread running on some node, which can “request” an object (on any node) to perform an operation. The request is sent in a message, and the sender expects a response message, which might returns a value, and which confirms that the operation was performed. In general, more than one thread could be performing operations on one object. That is, there can be concurrent requests.

The paper says: “In this note we will not consider stopping failures, though in some cases a stopping failure can be modeled as a node existing in its own unique component of a partition.” Of course in any real distributed system, nodes can crash. But for purposes of this paper, a crash is considered to be a network failure, because from the point of view of another node, there’s no way to distinguish between the two. A crashed node behaves exactly like a node that’s off the network.

You might say that if a node goes off the network and comes back, that’s not the same as a crash because the node loses its volatile state. However, this paper does not concern itself with a distinction between volatile and durable memory.  There’s no problem with that; issues of what is “in RAM” versus “on disk” are orthogonal to what this paper is about.

Consistent

The paper says that consistency “is equivalent to requiring requests of the distributed shared memory to act as if they were executing on a single node, responding to operations one at a time.” They explain this more explicitly by saying that consistency is equivalent to requiring all operations (in the whole distributed system) to be “linearizable”.

“Linearizability” is a formal criterion presented in the paper “Linearizability: A Correctness Condition for Concurrent Objects”, by Maurice Herlihy and Jeannette Wing. It means (basically) that operations behave as if there were no concurrency.

The linearizability concept is based a model in which there is a set of threads, each of which can send an operation to an object, and later receive a response. Despite the fact that the operations from the different threads can overlap in time in various ways, the responses are as if each operation took place instantaneously, in some order. The order must be consistent with each thread’s own order, so that a read operation in a thread always sees the results of that thread’s own writes.

Linearizability per se does not include failure atomicity, which is the “A” (“atomic”) in “ACID”. But Gilbert and Lynch assume no node failures. So operations are atomic: they always run to completion, even if their response messages get lost.

So by “consistent” (“C”), the paper means that every object is linearizable. (That’s not what the “C” in “ACID” means, by the way, but that’s not important.) Very loosely, “consistent” means that if you get a response, it has the right answer, despite concurrency.

This is not what the “C” in “ACID transaction” means. It’s what the “I” means, namely “isolation” from concurrent operations. This is probably a source of confusion sometimes.

Furthermore, the paper says nothing about transactions, which have would have a beginning, a sequence of operations, and an end, which may commit or abort. “ACID” is talking about the entire transaction. The “linearizability” criterion only talks about individual operations on objects. (So the whole “ACID versus BASE” business, while cute, can be misleading.)

Available

“Available” is defined as “every request received by a non-failing node in the system must result in a response.” The phrase “non-failing node” seemed to imply that some nodes might be failing and others not. But since the paper postulates that nodes never fail, I believe the phrase is redundant, and can be ignored. After the definition, the paper says “That is, any algorithm used by the service must eventually terminate.”

The problem here is that “eventually” could mean a trillion years. This definition of “available” is only useful if it includes some kind of real-time limit: the response must arrive within a period of time, which I’ll call the maximum latency.

Next, it’s very important to notice that “A” says nothing about the content of the response. It could be anything, as far as “A” is concerned; it need not be “successful” or “correct”. (If think otherwise, see section 3.2.3.)

So “available” (“A”) means: If a client sends a request to a node, it always gets back some response within L time, but there is no guarantee about contents of the response.

Partition Tolerant

There is no definition, per se, of the term “partition-tolerant”, not even in section 2.3, “Partition Tolerance”.

First, what is a “partition”? They first define it to mean that there is a way to assort all the nodes into separate sets, which they call “components”, and all messages sent from a node in one component to another nodes in a separate component are lost. But then they go on to say “And any pattern of message loss can be modeled as a temporary partition separating the communicating nodes at the exact instance the message is lost.” or their formal purposes, “partition” simply means that a message can be lost. (The whole “component” business can be disregarded.)  That’s probably not what you had in mind!

In real life, some messages are lost and some aren’t, and it’s not exactly clear when a “partition” situation starts, is happening, or ends. I realize that for practical purposes, we usually know what a partition means, but if we’re going to do formal proofs and understand what was proved, one must be completely clear about these terms.

Even in a local-area network, packets can be dropped. Protocols like TCP re-transmit packets until the destination acknowledges that they have arrived. If that happens, it’s clearly not a network failure from the point of view of the application. “Losing messages” must have something to do with nodes entirely unable to communicate for a “long” time compared to the latency requirements of the system.

Furthermore, remember that node failure is treated as a network failure.

So “partition-tolerant” (“P”) means that any guarantee of consistency or availability is still guaranteed even if there is a partition. In other words, if a system is not partition-tolerant, that means that if the network can lose messages or any nodes can fail, then any guarantee of atomicity or consistency is voided.

CAP

The CAP theorem says that a distributed system as described above cannot have properties C, A, and P all at the same time. You can only have two of them. There are three cases:

AP: You are guaranteed get back responses promptly (even with network partitions), but you aren’t guaranteed anything about the value/contents of the response. (See section 3.2.3.) A system like this is entirely useless, since any answer can be wrong.

CP: You are guaranteed that any response you get (even with network partitions) has a consistent (linearizable) result. But you might not get any responses whatsoever. (See section 3.2.1.) This guarantee is also completely useless, since the entire system might always behave as if it were totally down.

CA: If the network never fails (and nodes never crash, as they postulated earlier), then, unsurprisingly, life is good. But if messages could be dropped, all guarantees are off. So a CA guarantee is only useful in a totally reliable system.

At first, this seems to mean that practical, large distributed systems (which aren’t entirely reliable) can’t make any useful guarantees! What’s going on here?

Weak Consistency

Large-scale distributed systems that must be highly available can provide some kind of “weaker” consistency guarantee than linearizability. Most such systems provide what they call “eventual consistency” and may return “stale data”.

For some applications, that’s OK. Google search is an obvious case: the search is already specified/known to be using “stale” data (data since the last time Google looked at the web page), so as long as partitions are fixed quickly relative to the speed of Google’s updating everything, (and even if sometimes not, for that matter), nobody is going to complain.

Just saying that results “might be stale” and will be “eventually consistent” is unfortunately vague. How stale can it be, and how long is “eventually”? If there’s no limit, then there’s no useful guarantee.

For a staleness-type weak consistency guarantee, you’d like to be able to say something like: “operations (that read) will always return a result that was consistent with all the other operations (that write) no longer ago than time X”. And this implies that “write” operations are never lost, i.e. always happen within a fixed time bound.

t-Connected Consistency

Gilbert and Lynch discuss “weakened consistency” in section 4. It’s also about stale data, but with “formal requirements on the quality of stale data returned”. They call it “t-Connected Consistency”.

It makes two assumptions. (a) Every node has a clock that can be used to do timeouts. The clocks don’t have to be synchronous with each other. (b) There’s some time period after which you can assume that an unanswered message must be lost. (c) Every node processes a received message within a given, known time.

The real definition of “t-Connected Consistency” is too formal for me to explain here (see section 4.4). It (basically) guarantees (1) when there is no partition, the system is fully consistent; (2) if a partition happens, requests can see stale data; and (3) and after the partition is fixed, there’s a time limit on how long it takes for consistency to return.

Are the assumptions OK in practice? Every real computer can do timeouts, so (a) is no problem. You can always ignore any responses to messages after the time period, so (b) is OK. It’s not obvious that every system will obey (c), but some will.

I have two reservations. First, if the network is so big that it’s never entirely working at any one time, what would guarantee (3) mean? Second, in the algorithm in section 4.4, in the second step (“write at node A”), it retries as long as necessary to get a response. But that could exceed L, violating the availability guarantee.

So it’s not clear how attractive t-Connected Consistency really is. It can be hard it is to come up with formal proofs of more complicated, weakened consistency guarantees. Most working software engineers don’t think much about formal proofs, but don’t underrate them. Sometimes they can help you identifying bugs that would otherwise be hard to track down, before they happen.

Jeff Darcy wrote a blog posting about “eventual consistency” about a half year ago, which I recommend. And there are other kinds of weak consistency guarantees, such as the one provided by Amazon’s Dynamo key-store, which worth examining.

Reliable Networks

Can’t you just make the network reliable, so that messages are never lost? (“Never” meaning that the probability of losing a message is as low as other failure mode that you’re not protecting against.)

Lots and lots of experience has shown that in a network with lots of routers and such, no matter how much redundancy you add, you will experience lost messages, and you will see partitions that last for a significant amount of time. I don’t have a citation to prove this, but, ask around and that’s what experienced operators of distributed systems will always tell you.

How many routers is “lots”? How reliable is it if you have no routers (layer 3 switches), only hubs (layer 2 switches)? What if you don’t even have hubs? I don’t have answers to all this. But if you’re going to build a distributed system that depends on a reliable network, you had better ask experienced people about these questions. If it involves thousands of nodes and/or is geographically distributed, you can be sure that the network will have failures.

And again, as far as the proof of the CAP theorem is concerned, node failure is treated as a network failure. Having a perfect network does you no good if machines can crash, so you’d also need each node to be highly-available in and of itself. That would cost a lot more than using “commercial off-the-shelf” computers.

The Bottom Line

My conclusion is that the proof of the CAP theorem means, in practice: if you want to build a distributed system that is (1) large enough that nodes can fail and the network can’t be guaranteed to never lose messages, and (2) you want to get a useful response to every request within a specified maximum latency, then the best you can guarantee about the meaning of the response is that it is guaranteed to have some kind of “weak consistency”, which you had better carefully define in such a way that it’s useful.

P.S.

After writing this but just before posting it, Alex Feinberg added a comment to my previous blog post with a link to this excellent post by Henry Robinson, which discusses many of the same issues and links to even more posts. If you want to read more about all this, take a look.