Building DynamoDB Streams Compatibility on Apache Phoenix
Implementing DynamoDB Streams APIs (ListStreams, DescribeStream, GetShardIterator, and GetRecords) in Apache Phoenix Adapters using Phoenix's CDC capabilities.
Modern SaaS companies often rely on managed cloud services to build and scale their applications efficiently. While many start with a single cloud provider, expanding into new markets may create a need to support additional cloud environments, whether due to customer preferences or resilience requirements. However, this expansion can be challenging when applications are tightly coupled to services offered by their original cloud provider.
DynamoDB in AWS is one example of this challenge. Applications built around its APIs may need to run against a different database backend in another cloud environment, and rewriting their data-access layer can require significant engineering effort. Applications that also rely on DynamoDB Streams to consume data changes face an additional challenge, as compatibility must extend beyond basic read and write operations.
This article explores how providing DynamoDB-compatible APIs over Apache Phoenix/HBase addresses this problem. Specifically, it examines the design and implementation of DynamoDB Streams compatibility using Phoenix's change data capture capabilities.
Apache HBase and Phoenix
Apache HBase is an open-source, distributed NoSQL database built on top of the Hadoop ecosystem. It organizes data into tables that are partitioned into regions and distributed across multiple servers. Within each region, data is stored and accessed in sorted row-key order. As tables grow or their data distribution changes, HBase regions can split or merge, allowing the database to manage data across the cluster.
Apache Phoenix provides a SQL interface over HBase, allowing applications to query and modify data using familiar SQL statements rather than working directly with the HBase APIs. It also provides capabilities such as secondary indexing and change data capture (CDC). Phoenix and HBase are widely available as part of enterprise big-data platforms, including Amazon EMR, Azure HDInsight, and Cloudera distributions.
Apache Phoenix-Adapters
Apache Phoenix Adapters is an open-source project that provides compatibility with Amazon DynamoDB APIs using Apache Phoenix and HBase as the underlying database. It is designed as a stateless HTTP service that translates DynamoDB API requests into operations supported by Phoenix. Applications can use Phoenix Adapters by simply changing their DynamoDB SDK endpoint to point to the service, without requiring changes to their application code.
Amazon DynamoDB Streams
Amazon DynamoDB is a fully managed NoSQL database service that supports key-value and document data models. DynamoDB Streams captures item-level changes to DynamoDB tables and makes them available for consumption by downstream applications.
The DynamoDB Streams API provides four operations: ListStreams for discovering streams, DescribeStream for retrieving stream and shard metadata, GetShardIterator for obtaining a position within a shard, and GetRecords for reading change records. Together, these APIs allow applications to consume database changes through existing AWS SDKs and streaming tools.
Apache Phoenix CDC and Stream Metadata
Apache Phoenix supports Change Data Capture (CDC), allowing applications to query changes made to a table using SQL (PHOENIX-7001). The CDC implementation uses a write-optimized uncovered index on row timestamps to capture row-level modifications. The index tracks changes without storing a complete copy of the data, and Phoenix retains historical row versions to reconstruct changes.
Here is a small example of what CDC usage in Phoenix looks like for a simple ORDERS table.
-- Create a table and enable CDC
CREATE TABLE orders (
order_id VARCHAR PRIMARY KEY,
status VARCHAR
);
CREATE CDC cdc_orders ON orders;
-- Insert an order
UPSERT INTO orders VALUES ('order-101', 'CREATED');
-- Update the order
UPSERT INTO orders VALUES ('order-101', 'SHIPPED');
-- Query changes, including before and after images
SELECT /*+ CDC_INCLUDE(PRE, POST) */
PARTITION_ID() AS partition_id,
PHOENIX_ROW_TIMESTAMP() AS event_time,
order_id,
"CDC JSON"
FROM cdc_orders
ORDER BY PHOENIX_ROW_TIMESTAMP();
-- Conceptual results:
-- INSERT: partition_id = R1, PRE = null, POST = {status: CREATED}
-- UPDATE: partition_id = R1, PRE = {status: CREATED}, POST = {status: SHIPPED}
-- partition_id is the hbase region identifier for the change
The CDC query returns change records along with their partition identifiers, which are HBase Region IDs, timestamps, and requested pre/post images.
CDC Streams and Partition Metadata
The initial Phoenix CDC implementation focused on querying change records within a time range. However, typical stream consumers have additional requirements. For higher throughput, they need to discover and consume multiple shards in parallel. As shards split or merge, consumers also need to track their lineage to discover new shards and ensure parent shards are fully consumed before processing their children. Finally, consumers need a way to resume from their last processed position after failures. While checkpointing is typically the consumer's responsibility, the streaming interface must provide sequence numbers and iterators to support it. To support these requirements, we extended Phoenix with stream metadata and shard-tracking capabilities (PHOENIX-7456).
Phoenix organizes CDC changes into streams containing partitions, where each partition corresponds to an HBase region of the underlying data table. The PARTITION_ID() function associates each change record with the region where it originated, allowing consumers to retrieve changes from individual partitions.
Two system tables maintain the stream metadata:
SYSTEM.CDC_STREAM_STATUStracks CDC stream objects and their lifecycle, including initialization and active states.SYSTEM.CDC_STREAMstores partition metadata, including partition identifiers, parent-partition relationships, start and end times, and row-key boundaries.
Streams and partitions have separate lifecycles. A stream can remain active while its underlying partitions change as HBase regions split or merge. The metadata therefore needs to track not just the currently active partitions, but also their relationships with previously existing partitions.
Bootstrapping and Tracking Partition Topology
It is not sufficient for a consumer to simply query HBase for its current regions since it may still be processing changes from regions that have already split or merged. Persisting partition history allows consumers to finish reading closed partitions and discover their successors without losing track of unconsumed changes.
When CDC is enabled on an existing table, Phoenix first needs to discover the HBase regions that already exist. A background initialization task populates SYSTEM.CDC_STREAM with the initial region metadata, including each region's encoded identifier, start time, and row-key boundaries.
After initialization, Phoenix needs to keep this metadata updated as the underlying HBase region topology changes. HBase provides coprocessor hooks that allow custom logic to run in response to region lifecycle events, enabling Phoenix to update its stream metadata whenever a region split or merge completes. Phoenix uses the HBase Master coprocessor hooks postCompletedSplitRegionAction and postCompletedMergeRegionsAction to track these changes. When a region splits, the parent partition is marked as closed, and entries are created for the two daughter partitions. Similarly, when regions merge, the parent partitions are closed, and a new partition is added with references to all its parents. In both cases, Phoenix preserves the parent-child relationships so consumers can reconstruct the partition topology even after the underlying HBase regions have changed.
Consider our ORDERS table that initially has two HBase regions, R1 and R2. When CDC is enabled, Phoenix bootstraps the stream metadata for both regions. Suppose R2 later splits into R3 and R4. Subsequently, R1 and R3, which are adjacent regions, merge into a new region R5. The resulting lineage looks like this, with R4 and R5 as the active regions:

For the above partition lineage, the metadata in the SYSTEM.CDC_STREAM table would look something like the following. For simplicity, some columns are not shown here, but each partition metadata row also carries the table and stream name.
| partition id | parent partition id | start time | end time |
|---|---|---|---|
|
R1 |
NULL |
T0 |
T2 |
|
R2 |
NULL |
T0 |
T1 |
|
R3 |
R2 |
T1 |
T2 |
|
R4 |
R2 |
T1 |
NULL |
|
R5 |
R1 |
T2 |
NULL |
|
R5 |
R3 |
T2 |
NULL |
The region identifiers and timestamps are illustrative. T0 represents the initial bootstrap, T1 the split, and T2 the merge. A null end time indicates an active HBase region receiving writes.
This example shows how Phoenix maintains partition lineage across region topology changes. R1 and R2 initially have no parents. When R2 splits, it is marked as closed, and R3 and R4 are added with R2 as their parent. Later, when R1 and R3 merge, both partitions are closed, and R5 is created with references to both parents. R4 remains active.
The merge case also influenced the metadata schema. PARENT_PARTITION_ID is included in the composite primary key of SYSTEM.CDC_STREAM, allowing multiple rows for the same child partition, one for each parent. This avoids storing multiple parent identifiers in a single field and makes it easier to query partition lineage.
Together, the background bootstrap process and the region split/merge hooks allow Phoenix to maintain a history of CDC partition topology as the underlying HBase table evolves. This metadata provides the foundation for partition-aware stream consumption.
Implementing DynamoDB Streams APIs in Phoenix Adapters
Phoenix Adapters implements four DynamoDB Streams APIs: ListStreams, DescribeStream, GetShardIterator, and GetRecords. Together, these APIs allow existing DynamoDB Streams clients to discover streams, navigate their shards, and consume change records from Apache Phoenix. The implementation uses Phoenix's CDC objects for retrieving change records and its stream metadata tables for discovering streams and their partitions.
ListStreams
Every DynamoDB Streams consumer starts with the ListStreams API. It returns the streams available for consumption for a given table name. Phoenix uses the stream information stored in SYSTEM.CDC_STREAM_STATUS and converts it into the DynamoDB Streams response format. Each stream is returned with a table name, stream ARN, and stream label. Here is an example response:
{
"Streams": [
{
"TableName": "ORDERS",
"StreamArn": "arn:aws:dynamodb:us-west-2:000000000000:table/ORDERS/cdc_orders/2026-10-14T10:00:00.000",
"StreamLabel": "2026-10-14T10:00:00.000"
}
]
}
Since Phoenix Adapters can run outside AWS, the stream ARN is constructed in the format expected by DynamoDB clients, using placeholder AWS region and account identifiers. The stream label identifies the stream's creation time. The API also supports pagination using Limit and ExclusiveStartStreamArn, allowing clients to discover streams across multiple requests.
DescribeStream
Once the consumer has the stream it wants to consume from, it calls DescribeStream to retrieve the metadata for the shards available in that stream for consumption. Phoenix Adapters constructs the DescribeStream response using metadata maintained by Apache Phoenix. Stream and partition information comes from SYSTEM.CDC_STREAM_STATUS and SYSTEM.CDC_STREAM, while StreamViewType, which determines whether change records include old images, new images, or both, is retrieved from Phoenix table metadata. The partition identifiers, parent-child relationships, and start/end timestamps are then used to construct the shard metadata.
Consider the example from Section 2, where the ORDERS table initially has two regions, R1 and R2, and R2 subsequently splits into R3 and R4. An abbreviated DescribeStream response after the split would look like this:
{
"StreamDescription": {
"StreamArn": "...",
"StreamLabel": "2026-10-14T10:00:00.000",
"StreamStatus": "ENABLED",
"StreamViewType": "NEW_AND_OLD_IMAGES",
"TableName": "ORDERS",
"Shards": [
{
"ShardId": "shard-R2",
"SequenceNumberRange": {
"StartingSequenceNumber": "T0||00000",
"EndingSequenceNumber": "T1||99999"
}
},
{
"ShardId": "shard-R3",
"ParentShardId": "shard-R2",
"SequenceNumberRange": {
"StartingSequenceNumber": "T1||00000"
}
},
{
"ShardId": "shard-R4",
"ParentShardId": "shard-R2",
"SequenceNumberRange": {
"StartingSequenceNumber": "T1||00000"
}
}
]
}
}
Shard identifiers are simplified for illustration, and || in Sequence Numbers denotes concatenation.
Although Apache Phoenix CDC supports region merges and tracks multiple parent partitions, Phoenix Adapters disables HBase region merges (MERGE_ENABLED=false) for tables with DynamoDB Streams enabled. This is because DynamoDB Streams supports shard splits but does not expose merging shards. Disabling merges keeps the underlying HBase partition topology compatible with the DynamoDB Streams shard model.
The example shows how closed shards have an EndingSequenceNumber, while active shards do not. The sequence numbers are constructed using partition timestamps with additional padding to identify individual records. The sequence-number format and the purpose of this padding are explained in a separate section below.
GetShardIterator
GetShardIterator allows a client to obtain an iterator representing the position from which it wants to start consuming records within a shard. The API supports four starting positions, which Phoenix Adapters handles as follows:
TRIM_HORIZON: Uses the shard's starting sequence number to begin reading from the earliest available position.LATEST: Uses the current clock time as the starting position to consume new changes.AT_SEQUENCE_NUMBER: Starts reading at the specified sequence number.AFTER_SEQUENCE_NUMBER: Starts reading immediately after the specified sequence number.
Phoenix Adapters returns an opaque shard iterator that contains all the information needed to construct a Phoenix CDC SQL query. This includes the table name, CDC object, stream view type, partition identifier, and starting sequence number. Conceptually, the iterator looks like this:
shardIterator/<tableName>/<cdcObject>/<streamType>/<partitionId>/<startSeqNum>
tableName: The underlying Phoenix table.cdcObject: The Phoenix CDC object used to query changes.streamType: The configured stream view type, to determine which row images to return.partitionId: The CDC partition from which records will be retrieved.startSeqNum: The sequence position from which consumption should begin.
Since the iterator contains all the information required to construct the SQL query, Phoenix Adapters does not need to maintain server-side cursors for individual consumers. Any instance of the stateless HTTP service can process a subsequent GetRecords request using the iterator supplied by the client.
GetRecords
To start consuming records from a shard starting from a given position, the client would provide the ShardIterator it received from the GetShardIterator response to the GetRecords API. Phoenix Adapters decodes the iterator to identify the CDC object, partition, and starting sequence position. It then constructs a SQL query against the CDC object to retrieve changes from that position.
A simplified version of the query is:
SELECT /*+ CDC_INCLUDE(PRE, POST) */ *
FROM <cdcObject>
WHERE PARTITION_ID() = <partitionId>
AND PHOENIX_ROW_TIMESTAMP() >= <timestamp>
ORDER BY PHOENIX_ROW_TIMESTAMP() ASC
LIMIT <limit> OFFSET <offset>
The partition identifier restricts the query to a particular shard, while the timestamp and offset identify where consumption should resume. The CDC_INCLUDE hint retrieves the previous and updated row images needed for the DynamoDB Streams response.
Handling Sequence Numbers
DynamoDB Streams assigns a sequence number to each change record, identifying its position within a shard. These sequence numbers allow consumers to read records in order and resume consumption from a particular position. DynamoDB Streams also guarantees that changes to the same item appear in the order they occurred, although it does not guarantee a global ordering across different items.
Phoenix CDC provides a timestamp for each change through a row timestamp. However, multiple changes to different HBase row keys can occur within the same millisecond and therefore share the same timestamp. Using the timestamp directly as a sequence number would not uniquely identify these records.
To address this, Phoenix Adapters constructs sequence numbers by combining the millisecond timestamp with an N-digit offset. Records sharing the same timestamp are returned in HBase row-key scan order and assigned incrementing offsets. N is configurable, with a default value of 5, allowing up to 100,000 distinct sequence positions for records sharing the same timestamp within a partition. For updates to the same row key, Phoenix's mutation and timestamp-handling logic is important for preserving the order of successive changes. For example,
| rowkey | timestamp | sequence number |
|---|---|---|
|
order-101 |
100 |
10000000 |
|
order-102 |
121 |
12100000 |
|
order-103 |
121 |
12100001 |
|
order-104 |
121 |
12100002 |
|
order-105 |
156 |
15600000 |
Sequence numbers/timestamps are shortened for readability. The actual implementation uses fixed-width numeric strings.
The offset resets when the timestamp changes. This gives records within a shard a distinct position without maintaining a global sequence number counter which writes to different rowkeys would need to synchronize on. When processing a GetRecords request, Phoenix Adapters splits sequence number from the shard iterator back into its timestamp and offset components. The timestamp is used in the PHOENIX_ROW_TIMESTAMP() predicate, while the offset is applied through the SQL OFFSET clause to skip records already consumed.
Returning Records and NextShardIterator
Phoenix Adapters converts the CDC query results into DynamoDB Streams records. Each record includes an event type (INSERT, MODIFY, or REMOVE), the item's primary key, a sequence number, and the appropriate old or new item images based on the configured StreamViewType. Event type is inferred from the PRE/POST images in the CDC results, which also contain the row key, and the sequence number is generated based on the steps described in the previous section.
Along with the records, GetRecords returns a NextShardIterator (NSI), which the client uses to continue reading from where the previous request stopped. As records are processed, the adapter tracks the timestamp and offset of the last record. The offset increments for records sharing the same timestamp and resets to zero when the timestamp changes. After processing the batch, the next iterator is constructed using the last record's timestamp and its offset incremented by one.
Consider the example above, with a client requesting two records per call:
| records returned | sequence number for nsi |
|---|---|
|
Records Returned |
Sequence Number for NSI |
|
order-101, order-102 |
12100001 |
|
order-103, order-104 |
12100003 |
|
order-105 |
15600001 |
After the first call, the NSI contains sequence number 12100001, representing timestamp 121 and offset 1. The client passes this iterator unchanged in its next GetRecords request. Phoenix Adapters splits the sequence number into its timestamp and offset components and constructs a query equivalent to:
SELECT /*+ CDC_INCLUDE(PRE, POST) */ *
FROM <cdcObject>
WHERE PARTITION_ID() = <partitionId>
AND PHOENIX_ROW_TIMESTAMP() >= 121
ORDER BY PHOENIX_ROW_TIMESTAMP() ASC
LIMIT 2 OFFSET 1;
This query skips order-102, which was already returned at timestamp 121, and retrieves order-103 and order-104. The following NSI advances to 12100003, allowing the next request to skip all three records at timestamp 121 and continue with order-105. This process allows clients to resume consumption across batches using the returned iterator, without Phoenix Adapters maintaining server-side cursors. It relies on HBase's deterministic row-key scan order to consistently return records sharing the same timestamp in the same order across requests.
Phoenix Adapters also checks whether the underlying partition has closed and whether any unread records remain. Once a closed partition has been fully consumed, GetRecords returns a null NextShardIterator, signaling that the consumer has reached the end of that shard.
Compatibility Validation
Implementing the published interface of a technically complex API is certainly challenging, but it is the behavior across different inputs and edge cases which makes compatibility hard to achieve. DynamoDB provides extensive API documentation, but not every detail of its behavior is explicitly specified, so a great deal of what applications depend on is undocumented. One good way to establish that is to observe what DynamoDB does and record it.
Phoenix Adapters includes comprehensive integration tests that compare the results of API operations against AWS DynamoDB Local. These tests help verify that the implementation produces compatible results and catch regressions as the project evolves. One good example is BinaryStreamsIT, which validates change records and old/new item images across inserts, updates, and deletes for tables with primary keys in the binary data format.
Community-developed conformance suites provide another way to test compatibility. One such project is Parity Suite, which tests DynamoDB-compatible implementations against behavior observed from the actual AWS DynamoDB service. We ran Parity Suite (v3.6.1) against Phoenix Adapters (as of commit 04d5cbd9d5), and all DynamoDB Streams tests passed, covering INSERT, MODIFY, and REMOVE events, shard and iterator behavior, primary keys, old and new item images, and different stream view types. These results provide additional validation of the Streams implementation for the scenarios covered by the suite
Conclusion
Together, these four APIs allow existing DynamoDB Streams clients to discover streams, navigate shards, and consume changes from Apache Phoenix. Phoenix Adapters achieves this by exposing Phoenix's SQL-based CDC capabilities and stream metadata through a DynamoDB-compatible interface. The implementation is validated through integration tests against DynamoDB Local and third-party conformance testing.
Applications can also use the Kinesis Client Library (KCL) through the DynamoDB Streams Kinesis Adapter, which uses these four APIs to discover shards and consume records. This allows existing KCL-based consumers to work with Phoenix Adapters without implementing their own stream-consumption logic.
More broadly, this approach demonstrates how an existing database's CDC capabilities can be exposed through a familiar streaming API. By maintaining compatibility at the API level, applications can continue using their existing client libraries and streaming integrations while working with a different database backend.
Opinions expressed by DZone contributors are their own.