0

As far as I understand Google Cloud Spanner is globally consistent and also fast.

Let's say I have a table with a unique username field.

  • User A in USA inserts user johndoe to a US Spanner node
  • User B in China inserts user johndoe to a Chinese Spanner node

Does one of them fail? If not, how fast are the queries? Or do they both succeed but later on decide that one of them is a duplicate? Or do writes with UNIQUE fields go to 1 server?

Thanks!

0

First, there currently isn't an option to run Cloud Spanner across continents, even though Google's internal Spanner can. The answer however is still the same, just latencies on writes, etc are different in a Regional (Multi-zone) and Global (Multi-Continent) configuration.

The trick here is that Spanner does not insert into "the node", but instead tries to reach consensus across a majority of nodes. Since we always run an odd number of nodes, one of them will reach consensus first and block the other one. This transaction will be committed, then the other transaction will fail as the row already exists.

Eric Brewer gives a good overview of how consistency is achieved in this situations in this recent article: Spanner, TrueTime & The CAP Theorem

  • Will that failed transaction response be returned to the client instantly or will that client think that it went through? (in the cross-continent or high latency case). Or to put it otherwise: will consensus be reached and then the client gets a response from the database, or the other way around? Thanks a lot! – Adam Sho Feb 17 '17 at 20:39
  • PS: As I understood from the article, the client will only get a response after consensus is reached. Is that correct? – Adam Sho Feb 17 '17 at 20:47
  • The client will only get a response after the write has been affirmatively 'committed', at which time Spanner guarantees Durability (the D in ACID). – Dan McGrath Feb 17 '17 at 20:58
  • So only one of the two clients would get a confirm in the unique constraint case, and never two? Thats the last bit of understanding that I need. Thanks very much! – Adam Sho Feb 17 '17 at 21:01
  • That is correct. – Dan McGrath Feb 17 '17 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.