What is the difference between CockroachDB & Google Cloud Spanner?

Last edited on April 24, 2023

0 minute read

    One caveat before we dive into this comparison of CockroachDB and Google Cloud Spanner: I am not a Spanner expert. I have studied their documentation, tried the product and know their use cases well enough to state that Spanner is an amazing database. In this blog I am not going to unpack all the architectural details of Spanner as that would be a much longer post and I simply would not feel comfortable doing so. I’m going to point out interesting areas in which CockroachDB is distinct from Spanner. Here’s a short video in case you’d rather consume the information that way:

    The Origin of Google Cloud SpannerCopy Icon

    Google Cloud Spanner is the pioneer database of the distributed SQL movement and the best way to familiarize yourself with Spanner’s origin is to go and read the Google Cloud Spanner whitepaper. In that paper Google describes Spanner as “Google’s scalable, multi-version, globally-distributed, and synchronously-replicated database.” It distributes data at global scale and supports externally consistent, distributed transactions. Basically, they built on their experience with Bigtable and made it relational. Which was an amazing moment for business critical workloads that needed to be modernized.

    CockroachDB & Spanner Architectural DifferencesCopy Icon

    I would be remiss to begin without mentioning that CockroachDB’s three founders (Spencer Kimball, Peter Mattis and Ben Darnell) were all in the employee #300 range at Google. Peter and Spencer helped build Colossus, which is Google’s backend file system and Ben helped design and build Reader. As part of their work, they interacted and worked with the teams that were building Spanner. And when they left, and moved on to new projects, they missed some of the Google tooling.

    While the architecture of CockroachDB is inspired by Spanner, there are a few key differences that I’d like to call out. Let’s get into them:

    1. Multi-Cloud & Intra-Cloud DeploymentCopy Icon

    The architecture of Google Spanner is dependent on hardware to synchronize time within a cluster, which in turn ties it to explicit GCP instances. So, you can’t really use it outside of GCP. By contrast, you can run CockroachDB across multiple different cloud providers on any cloud provider, or really anywhere. CockroachDB is not tied to any explicit hardware, whereas Spanner is tied to hardware that includes atomic clocks.

    2. Multi-Region Simplicity & ControlCopy Icon

    “Multi-region”, in this context, is the concept of putting data in different locations to survive the failure of an entire region or to keep data close to users for performance reasons. In CockroachDB the location of data is defined at the row level of each table. This degree of granular control over the location of data is powerful for latency and survival reasons. Plus, the granularity and simplicity of data location controls in CockroachDB is quite different than what you’ll find in Spanner.

    3. Kubernetes Freedom & Availability for AnthosCopy Icon

    Spanner is tied to explicit hardware, which can make it challenging to deploy it ad hoc in any Kubernetes cluster. By contrast, CockroachDB was built as a distributed system and is open to run on any hardware and any cluster so it works beautifully in these distributed environments like Kubernetes. Unlike Spanner, you can use CockroachDB in a multi-cloud K8s environment like Anthos or Red Hat OpenShift. If you’re going to be running Kubernetes, you’ll find that every version of CockroachDB is a great fit to run directly on it.

    Living without atomic clocks: Where CockroachDB and Spanner diverge

    4. SQL Coverage & Data TypesCopy Icon

    Spanner has done some really great work over the past couple months to become compatible with PostgreSQL. But there are areas like spatial data and other data types and syntax that are still not covered in Google Spanner. Which may not be a dealbreaker for you as it really comes down to your workload and what you want to accomplish. CockroachDB’s documentation is a great place to see the full extent of our SQL coverage.

    Getting Started with CockroachDBCopy Icon

    Both CockroachDB and Spanner are great databases. Those are just four areas where the two databases are distinct from one another, hopefully those points help you choose the right tool for the job.

    If you’re interested in taking CockroachDB for a spin you can quickly get started with CockroachDB Serverless. That’s a free serverless database offering in which you get 5 GiB and 50 million request units without ever sharing your credit card. You could download the open source version of the database and just spin up a node on your laptop. Or you can take a look at CockroachDB dedicated - the fully managed version of CockroachDB.

    global architecture
    distributed SQL