docs/features/cdc/cdc-intro.rst
:abbr:CDC (Change Data Capture) is a feature that allows you to not only query the current state of a database's table, but also query the history of all changes made to the table.
As an example, suppose you made a sequence of changes to some table in the given order:
.. code-block:: cql
UPDATE ks.t SET v = 0 WHERE pk = 0 AND ck = 0;
UPDATE ks.t SET v = 1 WHERE pk = 0 AND ck = 0;
UPDATE ks.t SET v = 2 WHERE pk = 0 AND ck = 0;
UPDATE ks.t SET v = 2 WHERE pk = 0 AND ck = 1;
UPDATE ks.t SET v = 1 WHERE pk = 0 AND ck = 1;
UPDATE ks.t SET v = 0 WHERE pk = 0 AND ck = 1;
Normally, querying the table would return
.. code-block:: cql
pk | ck | v
----+----+---
0 | 0 | 2
0 | 1 | 0
(2 rows)
but with CDC, you can also learn the history of all changes:
.. code-block:: none
change at 2020-01-29 14:37:32: UPDATE ks.t SET v = 0 WHERE pk = 0 AND ck = 0; change at 2020-01-29 14:37:33: UPDATE ks.t SET v = 1 WHERE pk = 0 AND ck = 0; change at 2020-01-29 14:37:35: UPDATE ks.t SET v = 2 WHERE pk = 0 AND ck = 0; <- latest change change at 2020-01-29 14:37:38: UPDATE ks.t SET v = 2 WHERE pk = 0 AND ck = 1; change at 2020-01-29 14:37:39: UPDATE ks.t SET v = 1 WHERE pk = 0 AND ck = 1; change at 2020-01-29 14:37:40: UPDATE ks.t SET v = 0 WHERE pk = 0 AND ck = 1; <- latest change
(not an actual syntax, the above example just presents the general concept).
Some examples where CDC may be beneficial:
In ScyllaDB CDC is optional and enabled on a per-table basis. The history of changes made to a CDC-enabled table is stored in a separate associated table.
log table document <./cdc-log-table>.You can enable CDC when creating or altering a table using the cdc option, for example:
.. code-block:: none
CREATE TABLE ks.t (pk int, ck int, v int, PRIMARY KEY (pk, ck, v)) WITH cdc = {'enabled':true};
.. include:: /features/cdc/_common/cdc-params.rst
When writing applications, you can now use our language specific libraries to simplify writing applications which will read from ScyllaDB CDC. The following libraries are available:
Go <https://github.com/scylladb/scylla-cdc-go>_Java <https://github.com/scylladb/scylla-cdc-java>_Rust <https://github.com/scylladb/scylla-cdc-rust>_ScyllaDB University: Change Data Capture (CDC) lesson <https://university.scylladb.com/courses/data-modeling/lessons/change-data-capture-cdc/>_ - Learn how to use CDC. Some of the topics covered are: