Local development with cloud-spanner
Asked Answered
B

4

21

Is there any way to do local development with cloud spanner? I've taken a look through the docs and the CLI tool and there doesn't seem to be anything there. Alternatively, can someone suggest a SQL database that behaves similarly for reads (not sure what to do about writes)?

EDIT: To clarify, I'm looking for a database which speaks the same flavour of SQL as Cloud Spanner so I can do development locally. The exact performance characteristics are not as important as the API and consistency behaviour. I don't think Cockroach meets these requirements?

Begrudge answered 17/2, 2017 at 5:14 Comment(0)
T
6

There is now an emulator offered from Google for local development. As of 5/2020, it's in beta.

https://cloud.google.com/spanner/docs/emulator

It only stores data in memory, but you may be able to use the gcloud command line to backup and restore your development data to and from disk as needed.

https://cloud.google.com/spanner/docs/backup/gcloud

Topper answered 15/5, 2020 at 20:14 Comment(0)
S
7

There is currently no local development option for Cloud Spanner. Your current option would be to start a single node instance on GCP.

There currently isn't another database that operates like Cloud Spanner, however CockroachDB operates on similar principles. Since they don't have access to atomic clocks and GPS units, they do make different trade-offs. In particular around reads & writes and lacking 'stale reads'. You can read more on the Jepsen blog:

Where Spanner waits after every write to ensure linearizability, CockroachDB blocks only on contested reads. As a consequence, its consistency guarantees are slightly weaker.

Susiesuslik answered 17/2, 2017 at 13:31 Comment(0)
P
7

As Dan said, the currently supported way is to have multiple instances (dev, staging, prod) or you can put multiple databases in a single instance so share resource costs across the environments.

We know that a local mock server is high on the list of productivity features that developers need.

Pintail answered 21/2, 2017 at 17:6 Comment(0)
T
6

There is now an emulator offered from Google for local development. As of 5/2020, it's in beta.

https://cloud.google.com/spanner/docs/emulator

It only stores data in memory, but you may be able to use the gcloud command line to backup and restore your development data to and from disk as needed.

https://cloud.google.com/spanner/docs/backup/gcloud

Topper answered 15/5, 2020 at 20:14 Comment(0)
L
4

CockroachDB should behave similarly to Cloud Spanner for reads and you can run it natively on Mac OS X and Linux, and on Windows using Docker. For local development, the lack of TrueTime will not make a difference as everything is running on one machine.

For writes you're out of luck right now. Spanner has a custom API for writes while CockroachDB supports standard INSERT/UPDATE/DELETE statements. The upshot of this is that CockroachDB is more likely to work with your ORM of choice and we're working hard to extend that support.

Ludovick answered 17/2, 2017 at 19:9 Comment(3)
Aren't reads reasonably different between Cloud Spanner and Cockroach? My understanding is 1) performance profile is different at minimum due to blocking on contested reads, 2) lack of stale read functionality, 3) Multi-key transactional reads may not offer linearizability if they are on different nodes. [Happy to be corrected on any!]Susiesuslik
I'm not terribly familiar with Cloud Spanner given its recent release. 1) CockroachDB doesn't block on contested reads. Or are you stating that Cloud Spanner does? 2) CockroachDB supports AS OF SYSTEM TIME to allow querying at a point in time in the past. Perhaps I'm misunderstanding your comment about stale reads functionality. 3) Yes, there is likely a difference in linearizability for multi-node deployments, yet the original question is about local development and on a single node with the client running on the same node as the server there will be no clock skew to affect linearizability.Ludovick
1) It was something I got from @Aphyr's blog: "CockroachDB blocks only on contested reads. As a consequence, its consistency guarantees are slightly weaker.", 2) Looks like I misunderstood your documentation. 3) Agreed.Susiesuslik

© 2022 - 2024 — McMap. All rights reserved.