What is YCQL?
YCQL (YugabyteDB Cassandra Query Language) is a semi-relational SQL API that is compatible with the Apache Cassandra Query Language (CQL). YCQL provides a familiar interface for developers who have experience with Cassandra, while taking advantage of YugabyteDB’s distributed SQL capabilities.Key Features
Cassandra Compatibility
YCQL implements a large subset of the Apache Cassandra Query Language, including:- CQL Protocol: Wire-protocol compatible with Cassandra drivers (versions 3.x and 4.x)
- Data Types: Support for most Cassandra data types including primitive types, collections, and UUIDs
- DDL Operations: CREATE/ALTER/DROP for keyspaces and tables
- DML Operations: INSERT, UPDATE, DELETE, and SELECT statements
- Secondary Indexes: Support for creating indexes on non-primary key columns
- Prepared Statements: Parameterized queries with bind variables
YugabyteDB Enhancements
YCQL extends standard CQL with YugabyteDB-specific features:- Distributed Transactions: Optional ACID transactions across rows and tables
- JSONB Support: Native JSON data type with indexing capabilities
- Stronger Consistency: Configurable consistency levels with stronger defaults
- Automatic Sharding: Transparent data distribution across nodes
Architecture
Storage Engine
YCQL uses YugabyteDB’s DocDB storage engine, which provides:- Automatic Replication: Configurable replication factor (default: 3)
- Tablet Splitting: Automatic data redistribution as tables grow
- Consistency: Linearizable reads and writes by default
- High Availability: Automatic failover with Raft consensus
Query Processing
YCQL queries are processed by the YB-TServer (tablet server) layer:- Client connects using the CQL binary protocol (port 9042)
- Query is parsed and analyzed by the YCQL processor
- Execution plan is generated for distributed query execution
- Results are returned to the client in CQL format
Connection Details
Default Configuration
- Port: 9042 (CQL native protocol)
- Protocol Version: v3 and v4 supported
- Default Keyspace: None (must be created)
- Authentication: Optional (disabled by default)
Client Drivers
YCQL works with standard Cassandra drivers:Differences from Apache Cassandra
While YCQL maintains compatibility with CQL, there are some key differences:Consistency Model
- Default Consistency: YCQL uses STRONG consistency by default, while Cassandra defaults to ONE
- Consistency Levels: YCQL supports LOCAL_ONE, QUORUM, and LOCAL_QUORUM
- Transactions: YCQL supports ACID transactions when explicitly enabled
Data Types
- JSONB: YugabyteDB-specific JSON type with indexing support
- Collections: Nested collections are not supported in YCQL
- Timestamps: YCQL supports microsecond precision (flag-controlled)
Schema Design
- Primary Keys: Composite partition keys and clustering keys work similarly
- Secondary Indexes: Available on tables with transactions enabled
- Materialized Views: Not yet supported in YCQL
System Tables
YCQL provides system tables similar to Cassandra:system_schema.keyspaces- Keyspace metadatasystem_schema.tables- Table metadatasystem_schema.columns- Column definitionssystem.peers- Cluster node information
Best Practices
Schema Design
- Choose the right partition key: Distribute data evenly across tablets
- Use clustering columns for sorting: Define sort order at schema level
- Avoid hot partitions: Design keys to prevent uneven data distribution
- Enable transactions when needed: Use
WITH transactions = {'enabled': true}
Query Optimization
- Use prepared statements: Reduce parsing overhead and improve security
- Specify partition keys in WHERE clauses: Enable efficient lookups
- Limit collection sizes: Keep map, set, and list sizes reasonable
- Use indexes judiciously: Create secondary indexes only when necessary
Data Modeling
- Denormalize when appropriate: Design for query patterns
- Use counter types for incrementing values: Atomic counter updates
- Leverage TTL for time-series data: Automatic expiration of old data
- Choose appropriate data types: Match types to your data requirements
Next Steps
- Explore Data Types for detailed type information
- Learn about Statements for DDL and DML operations
- Review Functions for built-in functions and expressions
Compatibility Notes
Supported CQL Version
YCQL is compatible with Cassandra Query Language version 3.4.2 with extensions.Driver Compatibility
Tested with:- DataStax Java Driver 3.x and 4.x
- DataStax Python Driver 3.x
- DataStax Node.js Driver
- Other CQL-compatible drivers
Feature Parity
Most CQL features are supported. Notable exceptions:- Materialized views (not yet implemented)
- User-defined types (partial support)
- User-defined functions (not supported)
- Triggers (not supported)

