What is the byte size of common Cassandra data types - To be used when calculating partition disk usage?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
In Apache Cassandra, understanding the byte size of different data types is imperative for efficient data modeling and accurate estimation of storage requirements. This article delves into the byte size of common Cassandra data types, providing technical explanations, examples, and considerations for calculating partition disk usage.
Understanding Cassandra Data Types
Cassandra is a NoSQL database that uses a wide-row store model. Data is stored in tables (similar to tables in relational databases), and these tables can contain various data types. Each data type consumes a specific number of bytes, affecting the overall disk usage. Here's a closer look at some of the common data types.
Primitive Data Types
- Boolean:
- Description: Represents a value of true or false.
- Byte Size: 1 byte
- Example:
trueorfalse
- Tinyint:
- Description: An 8-bit signed integer.
- Byte Size: 1 byte
- Example: Supports values from -128 to 127.
- Smallint:
- Description: A 16-bit signed integer.
- Byte Size: 2 bytes
- Example: Supports values from -32,768 to 32,767.
- Int:
- Description: A 32-bit signed integer.
- Byte Size: 4 bytes
- Example: Supports values from -2,147,483,648 to 2,147,483,647.
- Bigint:
- Description: A 64-bit signed integer.
- Byte Size: 8 bytes
- Example: Useful for larger values beyond the
intrange.
- Float:
- Description: A 32-bit IEEE 754 floating point.
- Byte Size: 4 bytes
- Example: Decimal numbers with single precision.
- Double:
- Description: A 64-bit IEEE 754 floating point.
- Byte Size: 8 bytes
- Example: For decimal numbers requiring double precision.
- Decimal:
- Description: Arbitrary precision decimal.
- Byte Size: Varies based on value; uses 4 bytes for scale, additional bytes for value storage.
- Example:
Decimal('123.45')may use several bytes depending on precision.
- Varint:
- Description: Arbitrary precision integer.
- Byte Size: Varies depending on the number of digits.
- Example: Efficient for numbers that are not large.
- Timestamp:
- Description: Milliseconds since epoch.
- Byte Size: 8 bytes
- Example:
1970-01-01 00:00:00UTC onward.
- Uuid:
- Description: A universally unique identifier.
- Byte Size: 16 bytes
- Example: Globally unique 128-bit identifier.
String and Byte Data Types
- ASCII:
- Description: Strings with ASCII characters.
- Byte Size: 1 byte per character
- Text/Varchar:
- Description: UTF-8 encoded strings.
- Byte Size: 1-4 bytes per character depending on character set.
- Blob:
- Description: Arbitrary bytes.
- Byte Size: Depends on the length of the blob.
Composite and Collection Types
- List, Set:
- Description: Collections of elements.
- Byte Size: Overhead of 2 bytes per item to store the size, additional space for each element.
- Example: For a list or set of 100 integers, expect additional 200 bytes of overhead.
- Map:
- Description: Key-value pairs.
- Byte Size: Overhead of 4 bytes per entry (key and value size), plus the size of each key-value pair.
Calculating Partition Disk Usage
To accurately estimate the partition disk usage, consider the column data types and their respective byte sizes. The formula includes:
- Overhead per Partition: Accounts for additional metadata and storage format requirements in Cassandra, can be roughly estimated at around 10-15% extra.
Overview Table of Cassandra Data Type Sizes
| Data Type | Byte Size | Description |
| Boolean | 1 byte | True or false |
| Tinyint | 1 byte | 8-bit signed integer |
| Smallint | 2 bytes | 16-bit signed integer |
| Int | 4 bytes | 32-bit signed integer |
| Bigint | 8 bytes | 64-bit signed integer |
| Float | 4 bytes | Single-precision float |
| Double | 8 bytes | Double-precision float |
| Decimal | 4 bytes + variable | Arbitrary precision, 4 bytes for scale |
| Varint | Variable | Arbitrary precision integer |
| Timestamp | 8 bytes | Milliseconds since epoch |
| Uuid | 16 bytes | Universally unique identifier |
| ASCII | 1 byte per character | ASCII strings |
| Text | 1-4 bytes per character | UTF-8 strings |
| Blob | Variable | Arbitrary bytes |
| List/Set | 2 bytes/item + element size | Collections of elements |
| Map | 4 bytes/entry + key-value size | Key-value pairs |
In conclusion, having a comprehensive understanding of the byte size of Cassandra's data types is foundational to designing efficient data models and ensuring scalable performance. As data grows, so does the importance of accurate estimations and strategic planning for partition disk usage.

