Schema design

Updated at:

ApsaraDB for HBase stores data differently from relational databases. Schema decisions — table structure, column family layout, rowkey format, and versioning — directly affect read and write performance. This page covers the core schema design rules and configuration options.

Rules of thumb

Use these guidelines as a starting point. Each section below provides more detail.

  • Keep region sizes between 8 GB and 50 GB.

  • Keep cell sizes at 10 MB or smaller. For cells exceeding 10 MB, use Medium-sized Objects (MOBs) — currently not supported by ApsaraDB for HBase, but planned for version 2.0. If MOBs are not applicable, store the data in Object Storage Service (OSS) and keep a reference in HBase.

  • Use one to three column families per table. Don't model HBase tables like relational database management system (RDBMS) tables.

  • Aim for 50 to 100 regions per table when using one or two column families.

  • Use short column family names — the name is stored with every value.

  • Design rowkeys to distribute writes evenly across regions. Sequential or time-ordered rowkeys cause hotspotting.

Modify a schema

Use HBase Shell or the Admin Java API to create and update schemas.

(Recommended) Disable the table before you modify column families:

Configuration config = HBaseConfiguration.create();
HBaseAdmin admin = new HBaseAdmin(config);
String table = "Test";

admin.disableTable(table);        // Disable the table

HColumnDescriptor f1 = ...;
admin.addColumn(table, f1);      // Add a column family
HColumnDescriptor f2 = ...;
admin.modifyColumn(table, f2);   // Modify a column family
HColumnDescriptor f3 = ...;
admin.modifyColumn(table, f3);   // Modify a column family

admin.enableTable(table);

Changes to a table or column family — including the encoding algorithm, compaction format, and block size — take effect at the next major compaction or when StoreFiles are rewritten.

Number of column families

Keep the number of column families as small as possible. ApsaraDB for HBase is not optimized for multiple column families.

Flush and compaction operations run per region, not per column family. If one column family accumulates enough data to trigger a flush, adjacent column families are also flushed — even if they contain very little data. This creates unnecessary I/O.

Compaction is triggered based on the number of files in a column family, not on file size. With multiple column families, this can cause redundant compaction activity across families that don't need it.

To minimize this overhead, group columns with similar access rates into a single column family.

Column family cardinality

If a table has multiple column families, keep their row counts in a similar range. A large imbalance causes problems during scans.

For example, if column family A has 1 million rows and column family B has 1 billion rows, HBase distributes column family A's data across many regions based on the shared rowkey space. Scanning column family A then requires touching many region servers, making it very inefficient.

Rowkey design

Rowkey design is the most important schema decision in HBase. All reads and writes are ordered by rowkey, so a poor design causes hotspotting — where all traffic hits a single region server.

Avoid sequential or time-ordered rowkeys. If rowkeys are timestamps or auto-incrementing IDs, all new writes go to the same region. This overloads one region server while others sit idle.

Distribute writes evenly. Common strategies include:

  • Salting: Add a random or hash-derived prefix to each rowkey. This spreads writes across regions.

  • Hashing: Replace sequential IDs with a hash of the original key. Use a consistent hash function so reads can reconstruct the rowkey.

  • Key reversal: Reverse the bytes of a timestamp or numeric ID. For example, 1678901234 becomes 4321098761. This breaks sequential ordering without changing the key content.

For time-series and log data, combine a device or host identifier with the timestamp: <device-id>_<timestamp>. This keeps data for each device contiguous while distributing writes across devices. Old regions that no longer receive writes are acceptable — only active regions consume significant resources.

Number of versions

HBase doesn't overwrite cell values. Each write appends a new version with a timestamp. Old versions are removed during major compaction.

The version count is configured per column family using HColumnDescriptor. The default is 3.

Don't set the maximum version count to a high number (for example, hundreds or more) unless retaining historical data is a core requirement. A high version count leads to large StoreFiles and slower compaction.

Minimum number of versions

The minimum version count, also configured via HColumnDescriptor, defaults to 0 (disabled).

This setting works together with Time To Live (TTL). When both are set, HBase retains at least M versions of data for the last T seconds, up to a maximum of N versions:

  • T seconds = TTL duration

  • N = maximum versions

  • M = minimum versions (M < N)

The minimum versions setting is only active while TTL is enabled for the column family.

Supported data types

HBase uses a bytes-in/bytes-out interface via Put and Result. Any value that can be serialized to a byte array — strings, numbers, complex objects, binary data — can be stored.

Storing objects between 10 MB and 50 MB degrades query performance. For values above 10 MB, use Medium-sized Objects (MOBs) if available, or store the data in OSS and keep a reference in HBase.

Column family block size also affects read performance — factor it in alongside versioning when designing the schema.

TTL

TTL is configured per column family in seconds. ApsaraDB for HBase uses UTC for TTL calculations and automatically deletes data after the TTL expires.

Expired rows in stored files are removed during minor compaction. To disable TTL expiry, set hbase.store.delete.expired.storefile to false, or set the minimum version count to a non-zero value.

Cell TTL

The latest version of ApsaraDB for HBase supports setting a TTL per cell. Cell TTL can be set per-operation (Appends, Increments, and Puts) using Mutation#setTTL. When set, it applies to all cells updated by that operation.

Cell TTL differs from ColumnFamily TTL in two ways:

  1. Cell TTL is measured in milliseconds, not seconds.

  2. Cell TTL cannot exceed the ColumnFamily TTL. If the cell TTL is longer than the column family TTL, the column family TTL applies.