Distributed spatial data in free, open source CockroachDB

Distributed spatial data in free, open source CockroachDB

CockroachDB is a reliable, relational database, built to help you scale your transactional workloads in the cloud. Our focus on common relational data types has brought bulletproof resilience and effortless scalability to all sorts of customer applications, from customer service applications to global data stores for cloud-connected devices, to streaming video providers. Today, we’re excited to bring that same bulletproof resilience and effortless scale to new use cases: spatial data types in CockroachDB. 

The same open-source database you use to store and access common relational data types (e.g., INT, TEXT, UUID) can now be used with GEOMETRY and GEOGRAPHY spatial data types. And best of all, it’s free. 

All spatial data features and functions are included in the open-source license of CockroachDB 20.2. 

Spatial Data Command

CockroachDB 20.2 provides access to spatial data types, indexing for fast reads, external formats (e.g., GeoJSON,  Well Known Text), common spatial shapes (e.g., linestrings, polygon, geometry collections), builtins (e.g., ST_DWithin, ST_Contains). We aim for PostGIS compatibility to allow you to seamlessly migrate existing applications as well as use the rich third-party ecosystem. Our initial release comes with more than 220 PostGIS compatible built-ins and functions–and this is only the beginning. We will continue to add to this catalog in future releases. 

What can you build with spatial data?

With spatial data you can build applications that meet the needs of users that want information related to physical locations. Your customers increasingly expect both fast and accurate data from their applications to help them make informed decisions. They want to know how many cars are in their vicinity or how long they will wait for a ride-sharing vehicle to arrive. They want to use location data to minimize waste and reduce their carbon footprint. They want to know the exact value of a house based on recent comparable sales in the same geographic area. CockroachDB spatial data and indexing can help you store and query this data today. This spatial data tutorial from our docs is extremely thorough and includes an interactive element to help you visualize what the application development experience will be like on CockroachDB.

Here’s an example of a sample spatial data application built on CockroachDB:

Use CockroachDB to help your customers answer location data and mapping questions like: 

  • Where is the nearest gas station? Should I build a gas station in this location?
  • Is the house I want to buy located in a flood plain? What is the risk of providing insurance to this homeowner?
  • What is the congressional district for my home address? What are all the counties that my congressional district serves? 

Resiliency & Scale: What PostGIS & NoSQL can’t offer you out of the box

CockroachDB provides a horizontally scalable implementation of spatial data that allows you the ability to store and query large amounts of data with its unique indexing strategy and advanced cost-based optimizer. Each query can be distributed across multiple nodes for efficient processing through the use of our distributed SQL execution engine. CockroachDB can do all this while providing the most accurate data possible with serializable isolation. 

CockroachDB provides all of the above benefits while ensuring that you never need to worry about losing access to your spatial production data via its highly available architecture and online schema migrations. CockroachDB uses a distributed consensus algorithm to ensure that your data is highly available in the event of a node, availability zone, or region failure. This same architectural design also provides you with increased development flexibility as it ensures that schema changes never lock you out of production data. 

No longer will you need to choose between NoSQL’s eventually consistent data accuracy or PostGIS’s lack of scalability. Today, you can have both accuracy, reliability, and scale in CockroachDB.  

Familiar Postgres and PostGIS-compatible SQL

You can use familiar SQL access patterns with PostGIS-(and OGC-) compatible implementations of important spatial features like:

  • SQL data types (e.g., GEOMETRY, GEOGRAPHY) 
  • External formats (e.g., GeoJSON,  Well Known Text)
  • Popular shapes (e.g., POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION)
  • SQL built-ins (e.g., ST_Contains)

Postgres, and by extension PostGIS, is one of the most popular databases in the world. Developers often raved about PostGIS’s improved usability over Postgres’s native spatial data types as PostGIS provided revolutionary quality of life improvements including more than 300 built-ins and functions. Rather than reinventing the wheel, and creating our own syntax, we’ve chosen to provide developers with familiar PostGIS compatible SQL syntax. This means that you can use the same APIs that you use with PostGIS today while future-proofing your business with CockroachDB’s scale-out architecture. 

PostGIS helped launch Instagram and FourSquare (before each company eventually ran into sharding and scale concerns). It’s also been a key part of the stack for thousands of other applications from plucky startups to Fortune-500 behemoths. We know that regardless of the size of your company, the size of the mission-critical data needed to run your application will only continue to grow in today’s always-on, always-connected, modern world. CockroachDB helps you scale with your mission-critical data. You won’t be forced away from your initial stack when building with CockroachDB because we can accommodate massive scale. 

Here is a quick overview of the familair spatial data types and how they are supported:

Try out spatial data with CockroachDB

CockroachDB Dedicated lets you avoid the hassle of managing both a database (e.g., Postgres) and an extension (e.g., PostGIS) as we deliver one logical binary and one simple connection string. To get started today you can:

Keep Reading

SQL compatibility in CockroachDB: Spatial data, Enums, materialized views

CockroachDB empowers developers to build fast, scalable applications, and one of the ways it does this is by providing …

Read more
How we built scalable spatial data and spatial indexing in CockroachDB

Support for spatial data and spatial indexing is one of the most requested features in the history of CockroachDB. The …

Read more
What’s so special about spatial data?

How is Lyft able to tell you how far away your driver is? How does DoorDash give accurate estimates for the food you …

Read more