
This post is maintained by Bytebase, an open-source database DevSecOps tool that can manage both CockroachDB and PostgreSQL. We update the post every year.
Update History | Comment |
---|---|
2025/04/15 | Initial version. |
CockroachDB Overview
CockroachDB is a distributed SQL database designed to create a scalable, consistent, and survivable database. Developed by Cockroach Labs, it aims to combine the familiarity of SQL with the horizontal scalability of NoSQL databases.
License Model
CockroachDB has recently moved to a fully proprietary licensing model under the CockroachDB Software License. The licensing options include:
- Enterprise: A paid license that provides access to all features, requiring annual renewal
- Enterprise Free: Available for businesses with less than $10M in annual revenue
- Enterprise Trial: A 30-day self-service trial license
All CockroachDB Cloud deployments automatically include an Enterprise license. For developers, there's a 7-day grace period for clusters without a license key, and single-node clusters don't require a license key at all.
Architecture and Design Philosophy
CockroachDB's architecture is built around a layered approach:
- SQL Layer: Translates client SQL queries to key-value operations
- Transactional Layer: Enables atomic changes to multiple key-value entries
- Distribution Layer: Presents replicated key-value ranges as a single entity
- Replication Layer: Consistently replicates key-value ranges across nodes
- Storage Layer: Reads and writes key-value data on disk
This design allows CockroachDB to distribute data automatically across nodes in chunks called "ranges," with each range replicated to at least three nodes by default for survivability.
Performance Characteristics
CockroachDB delivers predictable throughput and latency at scale on commodity hardware. It can process single-row reads in 1ms and single-row writes in 2ms within a single availability zone. In benchmark tests using TPC-C, CockroachDB v21.1 processed 1.68M tpmC with 140,000 warehouses at 95% efficiency.
A key feature of CockroachDB is that it achieves this performance while maintaining SERIALIZABLE isolation, the strongest isolation level in the SQL standard.
Scalability Features
CockroachDB excels in scalability with:
- Native, automatic horizontal scaling
- No theoretical scaling limit (demonstrated linear scaling up to 256+ nodes)
- Multi-active availability where all nodes can accept reads and writes
- Automatic data distribution and rebalancing
- Built-in support for multi-region deployments
- Consensus-based replication using the Raft protocol
SQL Compatibility
CockroachDB is wire-compatible with PostgreSQL and supports most PostgreSQL data types and SQL features. However, it has some limitations compared to vanilla PostgreSQL:
- PostgreSQL compatibility maintained by CockroachDB
- Third-party PostgreSQL Compatibility Index, CockroachDB only has achieved a score of 40.21%.
Deployment Options
CockroachDB offers several deployment options:
- CockroachDB Cloud:
- Standard: A fully managed, multi-tenant deployment in a single region (AWS or GCP)
- Advanced: A fully managed, single-tenant deployment with enhanced features
- Self-Hosted: Requires an Enterprise license for production use
CockroachDB vs. PostgreSQL
License and Cost
The most significant difference is in licensing: PostgreSQL is truly open-source and free forever, while CockroachDB has moved to a proprietary license model with various paid tiers. This has major implications for production deployments and total cost of ownership.
Architecture and Scalability
CockroachDB was built from the ground up as a distributed SQL database, offering native horizontal scaling and global distribution capabilities. PostgreSQL, as a traditional RDBMS, excels in single-node performance but requires additional configuration and tools to achieve similar distributed capabilities.
Performance Characteristics
Both databases offer strong consistency and ACID compliance. CockroachDB achieves this in a distributed environment using the Raft consensus protocol, while PostgreSQL uses MVCC within a single-node architecture. CockroachDB's performance is optimized for distributed scenarios, while PostgreSQL often has better performance for complex queries on a single node.
SQL Compatibility and Ecosystem
PostgreSQL has a more mature and feature-rich SQL implementation with a wider range of extensions and procedural languages. CockroachDB, while PostgreSQL-compatible, has a more limited set of extensions and features, focusing instead on distributed capabilities.
Comparison Table
Aspect | CockroachDB | PostgreSQL |
---|---|---|
License | Proprietary (CockroachDB Software License) | Open Source (PostgreSQL License) |
Architecture | Distributed SQL database | Traditional monolithic RDBMS |
Horizontal Scaling | Native, automatic | Manual (partitioning, read replicas) |
Multi-Region Support | Built-in | Possible but requires additional tools |
High Availability | Multi-active (all nodes accept reads/writes) | Primary-replica architecture |
SQL Compatibility | PostgreSQL-compatible | Native PostgreSQL |
Extensions | Limited | Rich ecosystem |
Cost | Paid license for production use | Free for all uses |
Cloud Options | CockroachDB Cloud | Multiple providers |
Use Cases | Distributed, global applications | Wide range of applications |
If you're considering a distributed database solution like CockroachDB, it's certainly a good problem to have—it indicates your business has achieved meaningful scale. However, a few considerations are worth noting: CockroachDB isn't fully compatible with vanilla PostgreSQL, as discussed in this HN thread. Moreover, the benefits of horizontal scalability come with trade-offs in complexity and cost.